Created
June 2, 2016 20:59
-
-
Save ibtisamtauhidi/21ef780db4cf2160eb191c17341aa36e to your computer and use it in GitHub Desktop.
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
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