1 Reply Latest reply on Sep 29, 2015 8:34 AM by DiegoV_Intel

    Edison Mini breakout board I2C init problem using Python

    cjnaz

      Hi,

      On a Edison Mini Breakout board, I have hard-wired an HTU21D to the I2C6 pins (J17 pins 7 & 9).  If I run a Sparkfun basic demo Arduino sketch (https://learn.sparkfun.com/tutorials/htu21d-humidity-sensor-hookup-guide/htu21d-library-and-functions) it works just fine - produces temp and humidity readings without errors. 

       

      If I run an Adafruit HTU21D Python demo script on the same setup I get I2C errors 100% of the time.  Then, if I run this "wirehack" Arduino sketch then the Python code starts working:  https://richardstechnotes.wordpress.com/2014/11/05/using-i2cdetect-on-the-intel-edison-and-getting-i2c6-to-work-on-the-mini-breakout-board/.  To eliminate the Adafruit code layers, I poked directly at the smbus with this Python script, with the same results… doesn't work until the wirehack Arduino sketch is run.  I've started to look at the Arduino wire.cpp. 

       

      It seems that something is missing in the initialization of the I2C port 6 in the Python code.  Is this a well-known problem with a not-so-well-known Python init code fix for I2C usage?

       

      Smbus poke script:

      #!/usr/bin/python

      from smbus import SMBus

      bus = SMBus(6)

      # read temperature register 3 bytes

      val = bus.read_i2c_block_data(0x40, 0xE3, 3)

      print val

       

       

      Smbus poke scrip error before running wirehack:

      root@Edison1:~# python SMBus_direct_HTU21D.py

      Traceback (most recent call last):

        File "SMBus_direct_HTU21D.py", line 8, in <module>

          val = bus.read_i2c_block_data(0x40, 0xE3, 3)

        File "/usr/lib/python2.7/site-packages/smbus/util.py", line 59, in validator

          return fn(*args, **kwdefaults)

        File "/usr/lib/python2.7/site-packages/smbus/smbus.py", line 258, in read_i2c_block_data

          raise IOError(ffi.errno)

      IOError: 110

       

      Smbus poke script success after running the wirehack:

      root@Edison1:~# python SMBus_direct_HTU21D.py

      [106, 144, 130]

        • 1. Re: Edison Mini breakout board I2C init problem using Python
          DiegoV_Intel

          Hello cjnaz,

           

          In order to use an Edison's interfaces (I2C, SPI, UART, etc), the muxes should be configured first. According to your description, the Python script is not configuring the muxes properly. If that Python script is generic (I mean, not written for Edison) then it isn't configuring the muxes and the I2C interface is not set up.

           

          On the other hand, the Arduino sketch works because the I2C is configured through the Arduino IDE. For Python scripts I recommend you to use the MRAA library which was made to use the Edison's interfaces and the mux configuration is made transparently for the user, like the Arduino IDE does: intel-iot-devkit/mraa · GitHub

           

          Regards,

          Diego.