Skip to content

Instantly share code, notes, and snippets.

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(), 0)
def BytesToHex(Bytes):
return ''.join(["0x%02X " % x for x in Bytes]).strip()
while True:
resp = spi.xfer2([0x01, 0x02])
print BytesToHex(resp)
except KeyboardInterrupt:
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.