I2C

As an alternative to notSMB that is written in C and now has problems with the Raspberry Pi 'jessie' update there is an alternative, thanks to Raju for the contribution.

  • linuxi2c.py Simple way to access the I2C bus on a Rpi
  • windowsi2c For accessing I2C using the BV4221/2 hardware via the USB

This works in a similar way to notSMB but there are some differences and so software written for niotSMB will require changing

Linux_i2c

As an example of use assume that a BV4243 is connected to the RPi bus, this has an address of 0x78 (0x3c 7 bit address)

After importing the command is <device>.i2c(<output list>,<bytes to input or 0>), the command returns a list or a list of length 0.

The BV4243

In Python:

>>> import linuxi2c

>>> dev = linuxi2c.IIC(0x3c,1) # bus number 1, 0 for very old RPi's

>>> dev.i2c([31,1],0) # clears screen

The command consists of output to the i2c bus as a LIST, in this case 31 and 1 and the number of bytes expected for the return, in this case none.

To get data from the display, after a key press the command is 3. To get a single key:

>>> dev.i2c([3],1) # or

>>> l = dev.i2c([3],1)

>>> dev.close() # releases bus

Windows_i2c

This will in fact work with either Windows or Linux but does require the USB to I2C converter. For Windows the com port is something like 'com4' and for Linux it will be something like '/dev/tty/AMA0' depending of course on the version of Linux and hardware. The syntax is slightly different, requiring the address of the device so multiple devices can exist on the same bus.

After importing the command is <bus>.i2c(<device address>,<output list>,<bytes to input or 0>), the command returns a list or a list of length 0.

Taking the example above:

>>> import windowsi2c

>>> bus = windowsi2c.IIC('com4',115200) # com port as a string and Baud rate

>>> bus.i2c(60,[31,1],0) # clears screen. NOTE same address just decimal

>>> i = bus.i2c(60,[3],1) # gets key

>>> bus.close() # frees up bus