Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raspberry Pi SPI loopback test code
#!/usr/bin/env python
# loopback test script
# connect MOSI and MISO
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
def BytesToHex(Bytes):
return ''.join(["0x%02X " % x for x in Bytes]).strip()
try:
while True:
resp = spi.xfer2([0x01, 0x02])
print BytesToHex(resp)
time.sleep(1)
except KeyboardInterrupt:
spi.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.