• Email: info@sparkyswidgets.com

I2C ADC Breakout

Project description

A simple way to add a 12 bit ADC to any project using the I2C protocol. Built on the proven MCP3221 and MCP1541 pair this unit makes it very easy to take readings in 1mV steps (for even 500uV steps when paired with the MCP1521!) and is capable of up to 28.8Ksps in I2C fast mode.

I2CADCBreakout_header

Wide Range VCC

So wait, I can put 5v on the AIN, but only 3.3 on the I2C?

While working on a RasPi project I needed to easily interface some analog voltage signals, since I was using the MCP3221 in another project I figured it would make for a really handy breakout board for Pi projects and also when those pesky Arduino projects suck up all the available analog pins!

One of the cool things I picked up from the datasheet is the ability to power from the MCP15XX series of reference voltages, I thought it would make this a fairly robust project that many others might be able to take advantage of. By combining the MCP3221 and the MCP1541 you get a matched pair geared towards 12bit readings at 1mV resolution, which turned out to be perfect for the project I was working on. All in all for a couple of ICs and a few passives it sure makes a handy little breakout when in a pinch and it cheap enough to leave in projects too!

You can also bypass the Vref and remove the pullups for some really crazy interfacing (At your own risk of course!!)

Easy to Use

This is a very use module to ask for data!

The device is extremely easy to interface, in the Arduino environment its a matter of implementing the standard wire library and asking for the 2 registers, then combining them back into a 12bit int raw reading as shown in the code below! Simply hook up VCC, GND, SDA, SCL and input which ever signal you want to read  (common ground of course) and take some readings!

Happy Analog to Digital conversions!

Arduino Example

Some simple Arduino code to read and assemble the ADC reading

 #include
 #define ADDRESS 0x4D // MCP3221-A5 address (There are other addresses available)

 float vRef = 4107; //vRef reading in mV - Check This WIth DMM
 float stepSize = vRef/4096; //Each step = our vRef/ number of steps in 12bit

 void setup(){
   Wire.begin(); //Initialize I2C comms
   Serial.begin(9600); //Initialize Serial comms
 }

 void loop(){
   byte adc_MSB;
   byte adc_LSB;
   int adcRaw;
   float miliVolts;

    Wire.requestFrom(ADDRESS, 2);        //requests 2 bytes
    while(Wire.available() < 2);         //while two bytes to receive

    adc_MSB = Wire.read();
    adc_LSB= Wire.read();
    adcRaw = (adc_MSB * 256) + adc_LSB;
    miliVolts = adcRaw * stepSize;
    Serial.print("ADC RAW: ");
    Serial.println(adcRaw);
    Serial.print("Voltage: ");
    Serial.println(miliVolts/1000);
    Serial.print("mV/Step      : ");
    Serial.println(stepSize,4);
    delay(1000);
 }

Easy to Use

This is a very use module to ask for data!

#include

#define ADDRESS 0x4D // MCP3221-A5 address in 7bit format (There are other addresses available)

float vRef = 4107; //vRef reading in mV - Check This WIth DMM
float stepSize = vRef/4096; //Each step = our vRef/ number of steps in 12bit

void setup(){
Wire.begin(); //Initialize I2C comms
Serial.begin(9600); //Initialize Serial comms
}

void loop(){
byte adc_MSB;
byte adc_LSB;
int adcRaw;
float miliVolts;

Wire.requestFrom(ADDRESS, 2); //requests 2 bytes
while(Wire.available() < 2); //while two bytes to receive adc_MSB = Wire.read(); adc_LSB= Wire.read(); adcRaw = (adc_MSB * 256) + adc_LSB; miliVolts = adcRaw * stepSize; Serial.print("ADC RAW: "); Serial.println(adcRaw); Serial.print("Voltage: "); Serial.println(miliVolts/1000); Serial.print("mV/Step : "); Serial.println(stepSize,4); delay(1000); } [/sourcecode]

I2CADCBreakout.inoview rawview file on GitHub

Creative Commons License

I2C ADC Breakout by Sparky's Widgets is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.Based on a work at http://www.sparkyswidgets.com/portfolio-item/i2c-adc-breakout/.

Overview

Details