I've got a particular part hooked up over I2C to my Edison (through some level-shifters). Python is generally my weapon of choice, and after reading some things, I initially decided that it suited my needs just fine. However, I'm having a little bit of trouble understanding how the mraa library works, especially if the hardware on the bus uses 16 bit addresses. I'm attaching an example of what I mean. Here's some snippets from some code that I've put together:
def __init__( self,
self.mraa_i2c = mraa.I2c(i2c_bus)
for addr in [self.ctrl, self.status, self.int_enable, self.int_flags, self.version_reg,self.id_reg]:
print addr+" = "+str(self.mraa_i2c.readByte())
...and then the main code establishes an instance of the class and calls the smallRegisterDump function. Of course, I now realize, after looking at more code examples on the web and looking at the I2C lines on the oscilloscope that this code doesn't do what I was intending. Instead, the first line (self.mraa_i2c.write) actually requests a write (not what I intended), and the address to which it's trying to write is not what I was expecting either. Any ideas as to how I can read from a 16-bit address with the mraa library, or is it, as I suspect, just not possible with that library? If it's not possible with the mraa library, is there another library that I can use, or am I really going to have my 'roll my own' here? I can code everything in C, but if there's a 'pythonic' alternative, I generally prefer that.
I also have experience taking C code and turning it into a Python library if need be, but most C code that I've seen for the Edison that utilizes I2C makes use of the mraa library, which from what I can tell is what is ultimately limiting me.
Thanks in advance!
20150301_I2C.png 63.2 K