Windows I2C

In order to run I2C on a Windows PC there needs to be some device that can read and write I2C as a standard PC does not come with that interface. The BV4221_V2 is such a device. In that link under the Python heading are some instructions for using with Python and will be repeated here.

There is a pre-built windows exe (notsmb) file that will install the required libraries and the serial library, all that is needed is to download and double click the exe and that is the install complete. See also here for alternatives.

BV4221_V2 Preparation

Out of the box the BV4221_V2 is user friendly when using a terminal, this needs switching off and the Baud rate fixing, to do this open a terminal and type the following commands.

P0    // 'P zero'tuns off the prompt
D     // sets decimal
F     // fixes this behaviour
B115200 // fixes baud rate

The BV4221_V2 will no longer have a prompt just a * which is much more convenient in a programming situation and the class (installed with notsmb) takes advantage of that.

When installing notsmb the class can be found in 'C:\Python27\Lib\site-packages' if you are interested in how it works, if not simply import it as shown below.

#read 4 bytes form an I2C device with address 0x90
l = bus.i2c(0x90,[],4)

#write 4 bytes form an I2C device with address 0x90
l = bus.i2c(0x90,[1,2,3,4],0)

#send a command byte 0x22 followed by another byte 6 then read 2 bytes
l = bus.i2c(0x90,[0x22,6],2)

Using Example

Open a command window and run Python. The example assumes that the files is in the working directory and a 24C32 EEPROM or similar is connected to the BV4221_V2.

>>> from notsmb import notSMB
>>> bus = notSMB("COM21",115200) # put in the com port to match your system

>>> bus.detect() # will return a list of all i2c devices
>>> bus.i2c(0x28,[0,0],10) #Read the first 10 values:
>>> bus.i2c(0x28,[0,30],10) #Read bytes at address 30:
>>> bus.i2c(0x28,[0,45,7],0) #Write 7 & 8 to address 45,46: