Skip to content

Instantly share code, notes, and snippets.

@dlech
Forked from BertLindeman/ev3dev-i2c-probe.py
Last active August 29, 2015 14:05
Show Gist options
  • Save dlech/d86161aea84db05f8ffb to your computer and use it in GitHub Desktop.
Save dlech/d86161aea84db05f8ffb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
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):
try:
label = { 0: "Version", 8: " Vendor", 16: "Product" }
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(chr(data[i]))
i += 1
if offset == 0:
print " Address: 0x%02X" % addr
print " %s: '%s'" % (label[offset], s)
time.sleep(0.02)
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