-
-
Save BertLindeman/ed936ce822cd550a1c08 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 smbus | |
import time | |
for bus in range(3, 7): | |
curport = (bus - 2) | |
print "bus: %2d port: %2d " % (bus, curport) | |
try: | |
i2c = smbus.SMBus(bus) | |
print " Input port %d:" % (bus - 2) | |
for addr in range(0x01, 0x80, 2): | |
try: | |
for offset in range(0, 24, 8): | |
data = i2c.read_i2c_block_data(addr, offset, 8) | |
data.append(0) | |
i = 0 | |
s = '' | |
while data[i]: | |
#if data[i] >= 128: | |
# print " char >127: 0x%02x = %d" % (data[i], data[i]) | |
#else: | |
s += str(chr(data[i])) | |
i += 1 | |
if offset == 0: | |
print " Address 0x%02X:" % addr | |
print " '%s'" % s | |
time.sleep(0.02) | |
except IOError, err: | |
if err.errno != 6: | |
print " Address 0x%02X: %s" % (addr, err) | |
#else: | |
# print " Error 6 at Address 0x%02X:" % addr | |
except IOError, err: | |
if err.errno != 2: | |
print " Input port %d: %s" % (bus - 2), err | |
Author
BertLindeman
commented
Aug 30, 2014
- remove check for <128
- change unichr -> chr
- add quotes around printed strings
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment