On 3/4/07, Dave Hylands <dhylands@...> wrote:
> HI Arnar,
> > If Dave sees this, I wanted to create a python binding for the
> > i2c-io-api.h functions - has that been done before?
> > I started with "I2C_IO_GetInfo" but I just got this:
> > ERROR: I2cTransfer: ioctl failed: Bad file descriptor (9)
> > ERROR: I2cReadBlock failed
> Did you do the open (of /dev/i2c-0) and call I2cSetSlaveAddress? You
> need to pass the file descriptor returned from open into
> I2cSetSlaveAddress. After calling SetSlaveAddress, then you can call
No, that was exactly what I was missing. I figured that out late last
night, but thanks. I first thought that the i2cDev parameter to the
functions was the address.
I have a complete Python binding for all the functions in i2c-io-api.h
and they seem to be working. I also have functions to control gDebug
from python and to get the values of I2C_IO_VERSION and
I2C_IO_MIN_VERSION. All the functions take an address and open
/dev/i2c-0 for each operation, which is mainly b/c of my initial
misunderstanding - I should probably change that to allow opening of
an i2c device from python and pass that instead.
I'm working on a simple Python-only abstraction layer on top of that
right now. The only problem is that I can't test things properly since
I don't have the hardware for it, such as servos and analog devices
(i.e. a POT). All I have are some leds. I tested the ADC by wiring a
pin to F_AGND and then to F_AVDD - and I got the correct results :o)
I'd be very happy if you were willing to test this. I just need to
finish the abstraction layer (that basically mimics the i2c-io command
line program) and I wanted to write a simple controller for the PWMs,
like the "servo" shell script you have.
If this code is of any use to anyone other than myself I'd be happy to
give it away.