This seems like a useful info source
http://quick2wire.com/2012/06/i2c-python/As my understanding gradually emerges (a bit like a very slow moving brute force driven steam roller with as much subtlety as a .. as a pneumatic sledgehammer)
I2C is not really anything like "plug and play". Even when using I2Cdetect. I assumed I2C detect sent a whole bunch of common signals to every known I2C address and then listened out for some response, and that it would be a bit like lsusb (only for things that were connected to the I2C bus as opposed to USB).
It looks like there is lots of support out there for the MCP23008 chip so that you can use an API and as long as you are using this particular chip set then it is kind of plug n play.
In some respect you do need to do a kind of "bit banging" (not exactly the case, but sort of true) in order to ensure that you can tailor the right reads or writes are sent to match whatever your device actually needs.
So, with that in mind y, you could use C and
ioctl or you could use something like this quick2wire.i2c API but you still need to manually configure it.
So, the address for the pcf8591p 8bit I2C A-D converter with the three user address bits set to "0" is 10010001 = 145 = 0x91
The next control byte would be 00000000 (to use channel 0, auto increment off, single ended, analogue out off) = 0 = 0x0
The third bit which is sent to the pcf8591p is stored and then converted to a voltage by the digital to analogue converter. I dont want to do this at the moment so I assume this value would also be 0x0.
So, to read from the pcf8591p analogue input 1 I would use something like this (in quick2wire pseudo code)
- Code: Select all
import quick2wire.i2c as i2c
import time
with i2c.I2CBus() as bus:
bus.transaction(
i2c.write_bytes(0x91, 0x0, 0x0))
while True:
results = bus.transaction(
i2c.read(0x91, 1))
gpio_state = results[0]
print(gpio_state)
time.sleep(1)
Am I anywhere like in the right forest before I even ask if I am near barking up the right tree?
NB. Quick2Wire references
using the PCF8591, the very AD converter I am trying to use in this web page.