Quick2Wire I2C Analog and Raspberry Pi

The picture above shows the main interface board complete with ribbon cable for attaching it to a Raspberry Pi's GPIO header. On the right is the Analog board. The port expander board (included in the 'conbo' kit with the huge interface board, is a similar size and all the boards have 6 pin headers for I2C designed to be daisy-chained together using the cables supplied.

All three boards come as through-hole kits that are easy to assemble. Even easier if you rearrange the assembly instructions and solder the components in the order of those that lie lower to the boards first, rather than the apparently random order specified in the instructions.

The analog board is a nice size and has the pair of I2C connectors, a DIP switch to select the I2C address and various other quite useful headers.

Mini Project

Its always good to see how these things work, so I decided to try out an analog input, using just a pot (variable resistor).

As you can see, a fair amount of desk space is required for this! The ribbon cables and sockets all have notches, so the only place that you beed to make sure you have the cable the right way around is on the Raspberry Pi.

The pot is wired to the analog board with one wiper to VREF, the other wiper to AGND and the slider (middle connection) to AIN0.

The AGND and VREF jumpers are both bridged and the DIP switches are in their original position.

This shows that the PCF8591 is on I2C address 48. If you have a revision 1 board use "-y 0" rather than "-y 1".

The following code is lifted unaltered from GrumpyMike (Mike Cook) here.

Just paste it into a file called "pot.py".

#Read a value from analogue input 0

#in A/D in the PCF8591P @ address 0x48

from smbus import SMBus

bus = SMBus(1)

print("Read the A/D")

print("Ctrl C to stop")

bus.write_byte(0x48, 0) # set control register to read channel 0

last_reading =-1

while(0 == 0): # do forever

reading = bus.read_byte(0x48) # read A/D

if(abs(last_reading - reading) > 2):

print(reading)

last_reading = reading

Again, if you have an older revision 1 Pi, change bus = SMBus(1) to be bus = SMBus(0).

Run the program and you should see a new reading every time you move the pot knob.

$ sudo python pot.py

Read the A/D

Ctrl C to stop

150

147

144

141

138

135

132

129

126

Likes

DIP switches to select I2C address.

The daisy chain I2C idea, lets see some nice displays etc. in this format please.

I haven't mentioned that the expansion board also breaks out SPI and Serial connections from the Pi.

Dislikes

Their own library for all the I2C things. The 'standard' code works fine.

The interface is huge and largely devoid of any active components, it could easily be half the size.

Conclusion

This has the potential to grow into a really nice system, a bit like .Net Gadgeteer for Pi. But if you just want to have analog inputs on your Raspberry Pi then just stick a PCF8591 chip onto some breadboard and use jumper wires!

About the AuthorThese are my books. Click on the image below to find out more about them.