Reading analog input with ADS7830 ADC (I2C)

I have a ADS7830: http://www.ti.com/lit/ds/symlink/ads7830.pdf

For testing i made a simple circuit:
ADS7830_test.jpg

But all i get is 0 or 255.

Code:

#include <Wire.h>

#define Addr 0x4B // ADS7830 I2C address 

void setup()
{
  // Initialise I2C communication as Master
  Wire.begin();
  // Initialise serial communication, set baud rate = 9600
  Serial.begin(9600);
  delay(300);
}

void loop()
{
  unsigned int data;

  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Channel Selection
  Wire.write(0x08);
  // Stop I2C transmission
  Wire.endTransmission();
  
  // Request 1 byte of data
  Wire.requestFrom(Addr, 1);
  
  // Read 1 byte of data
  if (Wire.available() == 1)
  {
    data = Wire.read();
  }

  // Output data to serial monitor
  Serial.print("Digital value of analog input  : ");
  Serial.println(data);
  delay(300);
}

I suggest to run the I2C Scanner program to make sure that the device is recognized on the bus, and that you have the correct address.

According to the comment in the code, you have selected differential inputs on CH0 and CH1, so why is CH1 left open? For the circuit shown, single-ended input on CH0 would be more appropriate.

Just found the error.
It was set to differential input.
I changed it in the code above.
To read channel 0 it needs to be:

// Channel Selection
Wire.write(0x08);

Need to play now a bit because its the first time I'm doing this i2c and binary/hex stuff.

But i have another question: Can i get false readings on i2c if it works or does i2c work or not?
I ask because i have some temp sensors (MCP9808) on 50ft cable (used P82B715P).

Edit
You gave the answer when i was writing :slight_smile:

I2C doesn't work over long distances (it was intended for chip-to-chip communications on circuit boards).

Thats the reason for the P82B715P: www.nxp.com/documents/data_sheet/P82B715.pdf
Page 10 up to 30 meters (100ft).

I did read from people they have a whole house bus running since years without problems.

There is also the P82B96 who can do 200 meters.

for more than 8 bit we need 2 register for msb and lsb ry these will work by changeing i2c address

#include<Wire.h>

#define Addr 0x68
int count;
float vtg;

void setup()
{
//Wire.setClock(400000);
// Start serial communication and set baud rate = 9600
Serial.begin(9600);
// Initialise I2C communication as MASTER
Wire.begin();
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Send configuration command
// Continuous conversion mode, 16-bit resolution
Wire.write(0x12);
// Stop I2C Transmission
Wire.endTransmission();
delay(100);

}

void loop()
{
unsigned int data[2];

// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// raw_adc msb, raw_adc lsb
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
Serial.print("DATA[0] : ");
Serial.println(data[0]);
Serial.print("DATA[1] : ");
Serial.println(data[1]);
count=data[0];
count=(count<<8)+data[1];
Serial.print("COUNT : ");
Serial.println(count);

}