Tuesday, 12 February 2013

Connecting with I2C

This is the newly configured breadboard, a bamboo
cutting board for $3 from the dollar store with holes and
zip ties to hold the processors in place and self adhesive
mounting tape for the solderless plug-in breadboards
and the USB hub. All the power (except to the processors
through USB) is coming from the Arduino DUE
in the top corner, as it is good for up to 800 mA of 3V3.
I already installed a bunch of stuff for software support so it should be plug and go on the breadboard... and it was as simple as hoped for. The breakout boards are wired to power and connected to the I2C pins of the Pi through the green (SCL) and yellow (SDA) leads.

sudo i2cdetect -y 1

Shows an ADS1115 16 Bit ADC at 0x48 and a MPL115A2 Barometric Temperature / Pressure sensor at 0x60. The DAC Note seems to be out of date on the library as the version I've got already had the links to Adafruit_I2C.py created and there was code to check the revision number automatically. Still, the link is a tidy way to get the libraries in without setting the path variable.

Switching to the ADS1x15 directory got me an example already set up for the 1115, but you would need to edit for the 12 bit version, the ADS1015, that behaves almost identically. With pins floating I get:

sudo python ads1015_example.py 
Channel 0 = 0.598 V
Channel 1 = 0.591 V

A close up of the breakout boards with the I2C boards
lower and the analog accelerometer board in the top left.
There's no library code for the MPL115A2 so I will ignore it for now. A little modification to the example program allows ads1115.py to read all 4 channels once a second and put the output on a single line. Attaching the analog outputs from the +/-16 G Accelerometer breakout board gives the kind of results you would expect. Pin 0 is connected to the supply voltage.

With this sort of addition to the Pi you get a high resolution reading of analog voltages so you can respond to an analog world. It adds a little price and complexity over a microcontroller with built in ADC capabilities and it won't read the data as fast over I2C as you can get it from the integrated ADC ports.









sudo python ads1115.py

Channel 0 = 3.275 V Channel 1 = 1.637 V Channel 2 = 1.625 V Channel 3 = 1.711 V
Channel 0 = 3.275 V Channel 1 = 1.637 V Channel 2 = 1.625 V Channel 3 = 1.710 V

1 comment: