vsergeev / python-periphery

A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
529 stars 139 forks source link

i2c read API - add ability to specify starting address? #16

Closed rcordeau closed 6 years ago

rcordeau commented 6 years ago

It seems that when reading from an i2c device, if you keep issuing the same "read", you get different data. What I have noticed is this:

  1. Start fresh, and open up the i2c device (i2c = I2C("/dev/i2c-0")
  2. Setup a new i2c.Message of 16 bytes, read=True
  3. issue the i2c.transfer
  4. read back the data
    • Excellent - I get the first 16 bytes from the i2c device specified at the device address I wanted Now, I want to read the first 16 bytes from the i2c device again. If I setup up a new i2c.Message of 16 bytes, read=True and issue the i2c.transfer again, I will actually get the NEXT 16 bytes of the i2c device, instead of the first 16 bytes. Even if I close the i2c (i2c.close()), and reopen it and start all over, I will get the next 16 bytes, and then the next, etc. Is there any way you can specify an offset at the i2c device address from which to read/write?
rcordeau commented 6 years ago

Never mind