Skip to content

Instantly share code, notes, and snippets.

@BertLindeman
Forked from dlech/ev3dev-i2c-probe.py
Last active August 29, 2015 14:05
Show Gist options
  • Save BertLindeman/ed936ce822cd550a1c08 to your computer and use it in GitHub Desktop.
Save BertLindeman/ed936ce822cd550a1c08 to your computer and use it in GitHub Desktop.
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
@BertLindeman
Copy link
Author

Added a check before the unicode starnslate. Byte needs to be less than128.

@BertLindeman
Copy link
Author

  • 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