Skip to content

Instantly share code, notes, and snippets.

@ardangelo
Created May 18, 2016 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardangelo/22b14e8c76a02f5c129b288ffc8c91af to your computer and use it in GitHub Desktop.
Save ardangelo/22b14e8c76a02f5c129b288ffc8c91af to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# arduino rpi
# 8 -> 13 (gpio 3)
# 9 (pwm) -> 33 (pwm1)
# 10 (pwm ss) -> 23 (gpio 14)
# 11 (pwm mosi) -> 19 (gpio 12)
# view from front of CABLE
# annotated with colors of crappy $1 ebay link cable
# T
# 1 3 5 1 3v, xxx 3 SI, wht 5 SC, red
# 2 4 6 2 SO, blk 4 SD, grn 6 GN, xxx
import wiringpi
import time
SI = 0
SO = 1
SC = 2
SD = 3
wiringpi.wiringPiSetup()
wiringpi.pinMode(SI, 1)
wiringpi.pinMode(SO, 0)
wiringpi.pinMode(SC, 1)
wiringpi.pinMode(SD, 1)
def sendbytes(u16list):
wiringpi.digitalWrite(SC, 1) # mode 3 clock idle
res = ''
for u16 in u16list:
wiringpi.digitalWrite(SD, 0) # slave select
bstr = bin(u16)[2:].zfill(16)
# print "send " + bstr
for i in reversed(xrange(16)):
wiringpi.digitalWrite(SC, 1) # mode 3 clock hi
if bstr[i] == '0':
wiringpi.digitalWrite(SI, 0) # send 0
else:
wiringpi.digitalWrite(SI, 1) # send 1
wiringpi.digitalWrite(SC, 0) # mode 3 clock lo (toggle)
time.sleep(.001)
res = str(wiringpi.digitalRead(SO)) + res
wiringpi.digitalWrite(SC, 1) # mode 3 clock hi (sample)
time.sleep(.001)
wiringpi.digitalWrite(SD, 1) # slave idle
# print "read " + res
return int(res, 2)
recd = 0
while recd != 0x72026202:
recd = sendbytes([0x6202, 0x0000])
print "got 0x{0:08x}".format(recd)
time.sleep(.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment