import spidev import time import Adafruit_BBIO.GPIO as GPIO CS_PIN = 'P9_17' CLK_PIN = 'P9_22' MOSI_PIN = 'P9_18' MISO_PIN = 'P9_21' GPIO.setup(CS_PIN, GPIO.OUT) GPIO.setup(CLK_PIN, GPIO.OUT) GPIO.setup(MOSI_PIN, GPIO.OUT) GPIO.setup(MISO_PIN, GPIO.IN) spi = spidev.SpiDev() spi.open(0, 0) spi.mode = 0b00 spi.max_speed_hz = 500000 def transfer(send, length): receive = spi.xfer2(send) return receive GPIO.output(CLK_PIN, GPIO.LOW) while True: send_data = [0x0A19] print(send_data) GPIO.output(CS_PIN, GPIO.LOW) # Set CS low to initiate data transfer for byte in send_data: for i in range(16): GPIO.output(CLK_PIN, GPIO.HIGH) if byte & 0x8000: GPIO.output(MOSI_PIN, GPIO.HIGH) else: GPIO.output(MOSI_PIN, GPIO.LOW) GPIO.output(CLK_PIN, GPIO.LOW) byte <<= 1 GPIO.output(CS_PIN, GPIO.HIGH) # Set CS high after data transfer spi.close() GPIO.cleanup()