Here is my code:
Code: Select all
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
clock = 17
mosi = 18
GPIO.setup(clock,GPIO.OUT)
GPIO.setup(mosi,GPIO.OUT)
GPIO.output(clock,True)
GPIO.output(mosi,False)
counter = 0
def writeByte(value):
# do something to write the byte
mask = 0x80
for i in range(8):
GPIO.output(clock,False)
if (value & mask):
GPIO.output(mosi,True)
else:
GPIO.output(mosi,False)
GPIO.output(clock,True)
mask >>= 1
while True:
try:
GPIO.output(clock,False)
sleep(0.0005)
for i in range(3):
writeByte(counter)
for i in range(15):
writeByte(0)
counter = counter + 1
if (counter > 255):
counter = 0
except KeyboardInterrupt:
GPIO.cleanup()
Code: Select all
~/spi $ sudo python test.py
^CTraceback (most recent call last):
File "test.py", line 32, in <module>
GPIO.output(clock,False)
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)
Code: Select all
test.py:8: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(clock,GPIO.OUT)
test.py:9: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(mosi,GPIO.OUT)