Last active
December 5, 2016 06:43
-
-
Save fnishio/b2063941b82f2cf1b935 to your computer and use it in GitHub Desktop.
Raspberry Pi SPI loopback test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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