I2C MCP3221 12 bit ADC reading 0 at any voltage

1.5k Views Asked by At

I've hooked up an MCP3221 to a Teensy 3.1 on the I2C bus and connect it to Vref(3.3V), just to check if it's working. However it's reading 0, even when I hook it up to a different voltage. Is my code faulty or should I just get a new device?

#include <MCP3221.h>
#include <Wire.h>
#include "SoftwareSerial.h"

#define ADDRESS 0x4D // 7 bits address is 0x4D, 8 bits is 0x9B

MCP3221 adc(155,0x3);

void setup() {
  Serial.begin(9600);
  Serial.println("First");
  Wire.begin(); //connects I2C

}


void loop() {

  Serial.println(adc.readI2CADC());

  delay(10);

}
2

There are 2 best solutions below

0
On

There is a list of device addresses in the Microchip data sheet DS21732C on the page 20. Depends on the marking code on your chip.

1
On

You are not using the right address. You declare the constant but never use it. The adc declaration should be like this

MCP3221 adc(ADDRESS, 0x3);

Why? Doing a little search, I found out that instead of 8 bits address (155 in decimal or 0x9B in hexadecimal), you have to use 7 bits address, 0x4D in this case. You can see that in this example, too. I think you should have this example in the Arduino IDE, in File > Examples > MCP3221.

Looking at the example, seems like the second argument you passed to the adc can be wrong, too, but I'm not sure about this. Try a greater value if you see you always measure the same.