0
\$\begingroup\$

I have an ADS1113 ADC connected to an 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 0 back, meaning the data was successfully transmitted.

Yet, when requesting 4 bytes I keep getting this, even when I change the voltage at the AIN0 and AIN1 inputs:

enter image description here

I am pretty new to using I2C and learning how to setup particular ICs from reading the data sheet. The QuickStart Guide is on page 35 (I tried posting a pic of what it says, but I don't have high enough reputation to post more than two links).

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); 
}
\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

According to the datasheet for single-ended measurement you should connect AIN1 pin to ground. enter image description here

\$\endgroup\$
0
\$\begingroup\$

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.

 while(Wire.available()){    



    float RAW = Wire.read();  <<--------------- at this line 
    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();
  }

But if your ADC values are not changed that means your sensor ADS1113 not configure/working correctly first of all check your sensor output.

\$\endgroup\$
2
  • \$\begingroup\$ I thought maybe I was requesting 4 bytes of information from the ADC. Ahhh ok, thanks. What do you mean by checking the sensor output though? \$\endgroup\$
    – Zach Stow
    Commented Oct 23, 2017 at 7:22
  • \$\begingroup\$ Ohh, i think you are using an external sensor or somthing like voltage source \$\endgroup\$
    – Bhura
    Commented Oct 23, 2017 at 12:19
0
\$\begingroup\$

I think the ADC tells you the difference between AIN0 and AIN1. Since both are 5V, the difference is 0V.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.