Having trouble reading value from I2C device with Python libs (OmegaExpansion / OnionI2C)
-
Hello, I'm working on writing a driver for the Adafruit MPR121 capacitive touch sensor using the Onion python i2c libraries (OmegaExpansion onionI2C). For some reason that I haven't been able to figure out yet, reading from a register address always returns 0x00. There's a sequence of register writes to reset the device, which results in a specific value
0x24
stored in one of the registers. I stripped all my code down to the bare minimum, but no luck calling this from python. The command line toolsi2cdetect i2cget i2cset
work correctly, so I know the breakout itself is working.- Using the command line tools
> i2cdetect -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- > i2cset -y 0 0x5a 0x5e 0x00 > i2cset -y 0 0x5a 0x80 0x63 > i2cset -y 0 0x5a 0x5e 0x8f > i2cset -y 0 0x5a 0x5e 0x00 > i2cget -y 0 0x5a 0x5d 0x24
- My code using the python onionI2C library
from OmegaExpansion import onionI2C i2c = onionI2C.OnionI2C() i2c.setVerbosity(2) i2c.writeByte(0x5a, 0x5e, 0x00) i2c.writeByte(0x5a, 0x80, 0x63) i2c.writeByte(0x5a, 0x5e, 0x8f) i2c.writeByte(0x5a, 0x5e, 0x00) i2c.readBytes(0x5a, 0x5d, 1)
...and the output
> python touchTest.py onion-i2c:: writing buffer: buffer[0]: 0x5e buffer[1]: 0x00 onion-i2c:: writing buffer: buffer[0]: 0x80 buffer[1]: 0x63 onion-i2c:: writing buffer: buffer[0]: 0x5e buffer[1]: 0x8f onion-i2c:: writing buffer: buffer[0]: 0x5e buffer[1]: 0x00 onion-i2c:: Reading 1 byte from device 0x5a: addr = 0x5d read 1 byte, value: 0x00
I'm pretty stumped and not sure what else to troubleshoot. Any ideas from the community on other directions I can take? Thanks in advance for any help
-
@cmelnick It's possible the
onion-i2c::
debug readings aren't 100% correct.Can you try changing your code when you read to this:
val = i2c.readBytes(0x5a, 0x5d, 1) print(val)