Skip to content

Instantly share code, notes, and snippets.

@ibtisamtauhidi
Created June 2, 2016 20:59
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 ibtisamtauhidi/21ef780db4cf2160eb191c17341aa36e to your computer and use it in GitHub Desktop.
Save ibtisamtauhidi/21ef780db4cf2160eb191c17341aa36e to your computer and use it in GitHub Desktop.
import sys
import serial
import time
if (len(sys.argv) < 1):
print "Usage: readGPIO.py <PORT>"
sys.exit(0)
else:
portName = sys.argv[1];
serPort = serial.Serial(portName, 19200, timeout=1)
while True:
serPort.write("gpio readall\r")
response = serPort.read(25)
hex_string = response.replace("\n","").replace("\r","").replace("gpio readall","").replace(">","")
bin_string = str(bin(int(hex_string, 16))[2:].zfill(32))
bin_string = bin_string[::-1]
print bin_string[:18]
time.sleep(.1)
serPort.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment