Skip to content

Instantly share code, notes, and snippets.

@dlech
Created July 11, 2014 17:56
Show Gist options
  • Save dlech/0589dbed922f020fcd83 to your computer and use it in GitHub Desktop.
Save dlech/0589dbed922f020fcd83 to your computer and use it in GitHub Desktop.
import smbus
import time
for bus in range(3, 7):
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]:
s += str(unichr(data[i]))
i += 1
if offset == 0:
print " Address 0x%02X:" % addr
print " %s" % s
time.sleep(0.01)
except IOError, err:
if err.errno != 6:
print "Address 0x%02X: %s" % addr, err
except IOError, err:
if err.errno != 2:
print "Input port %d: %s" % (bus - 2), err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment