I have the ADS1113 ADC connected to the Arduino using the I2C protocol. I'm just trying to read the analog data from the ADC. I have 5 volts connected to the AIN0 and AIN1 inputs. When I check the Wire.endTransmission() value I keep getting a zero back, meaning the data was successfully transmitted. Yet, when requesting 4 bytes I keep getting this, even if I change the voltage at the AIN0 and AIN1 inputs.
I pretty new to using I2C and learning how to setup particular ICs from reading the data sheet: http://www.ti.com/lit/ds/sbas444c/sbas444c.pdf
The QuickStart Guide is on page 33 (Sorry I tried posting a pic of what it says, but I don't have high enough reputation to post more than two links…).
So I guess my question is, how do I obtain the second and third byte values? Or am I completely off and not even supposed to be reading the data from the conversion register?
#include <Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
int sensorValue = analogRead(A0); //compare to ADC data
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
Serial.println();
Wire.beginTransmission(B1001000); //Address of ADC
Wire.write(1);
int ack = Wire.endTransmission();
Serial.print("I2C = ");
Serial.print(ack);
Serial.println();
delay(15);
Wire.requestFrom(B1001000,4,1); //Requesting 4 bytes
while(Wire.available()){
float RAW = Wire.read();
float RAW_voltage = (RAW*4.096/32768.0);
Serial.print("Raw ADC value = ");
Serial.print(RAW);
Serial.print("\tVoltage = ");
Serial.print(RAW_voltage);
Serial.println();
}
delay(1000);
}
Best Answer
What do you mean about 4bytes. Your code is correct and received all requested 4 bytes 1 by 1
this loop run four times and received all data from the I2c Slave.
But if your ADC values are not changed that means your sensor ADS1113 not configure/working correctly first of all check your sensor output.