Skip to content

Instantly share code, notes, and snippets.

@fnishio
Last active December 5, 2016 06:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnishio/b2063941b82f2cf1b935 to your computer and use it in GitHub Desktop.
Save fnishio/b2063941b82f2cf1b935 to your computer and use it in GitHub Desktop.
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