Using I2C with Arduino Due and AD7150

Dear all,

I am kind of noob in this field, I'll try to be as clear as possible.

I am trying to read values from the CDC AD7150 (datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/AD7150.pdf) using the Arduino Due. The circuit uses two different capacitance plates. I believe one of them should be excited and the other one is the one that we should check (am I right?).

Obviously, on my first attempts I got errors and errors and when I solved them I got always the value of zero as output.

Someone told me to check the I2C (SDA and SCL). After doing some research I understood what was that.

I read some codes on this forum but I did not understand them. Arduino Due has SDA on pin 20 and SCL on pin 21. I thought when reading from the slave we should use pin 20 and that is what I have in my code (I'll attach it below), I am getting wired values for SCL and SDA (definitely not correct). I am using pull-ups resistors (the ones Arduino Due has got inherently (1K each, enough for a 3.3V supply)).

I would be grateful if you would help me out reading what I am sending through the I2C and I would also appreciate some help reading values from the CDC output.

Thanks a lot for taking some of your time to read this.

If I have forgotten any other information please let me know.

Code:
#include <Wire.h>

void setup() {
Wire.begin();
Serial.begin(9600);
}

void loop(){
Wire.requestFrom(20,3); //address 20 ask for 3 bytes

while (Wire.available()){
char c = Wire.read();
Serial.print ("The value for SDA is: ");
Serial.println(c);
}

char val = digitalRead(52); // this is where I connected the output of the CDC
Serial.print("The output value is: ");
Serial.println(val);
delay(500);
}

// I know it is too short, but I do not know what else I should add.

Pullup resistors of 1k is too low. Start with 10k from SDA to 3.3V and from SCL to 3.3V.

Start with the I2C Scanner: Arduino Playground - I2cScanner.
It returns a hexadecimal number, use that number as the I2C address in the sketch.

If the I2C Scanner does not find the chip, then perhaps it is wrong connected.

If the I2C Scanner does find the chip, then you can try to read data, for example the chip ID.

void loop()
{
  Wire.beginTransmission( 0x??);   // use the address found with the I2C Scanner
  Wire.write( 23);    // set register pointer to Chip ID
  Wire.endTransmission();

  Wire.requestFrom( 0x??, 1);   // use the address found with the I2C Scanner
  int data = Wire.read();

  Serial.print( "The Chip ID is: 0x");
  Serial.println( data, HEX);

  delay( 1000);
}

The I2C bus is a bus with two wires plus GND. The wires are called SDA (serial data) and SCL (serial clock). You need to connect both for a working I2C bus (connect SDA to SDA and SCL to SCL and GND to GND). Both the Arduino and the sensor can do things with the SDA and SCL signals, the signals go in both directions.
In the sketch, you can read a register from the sensor.

Thanks a lot for your answer,

I do not understand one bit, if I connect the wires to the SDA pin (20) and SCL pin (21), should not be the address 20 for the exchange of data?
Or are you suggesting that I connect the wires into other pins for the Arduino Due?

If I understood correctly, I should do:

  • Scan the IC2 pins (for Arduino Due)
  • Connect the SDA to one of the pins and the SCL to another pin and then use the code.

Or the scan is for the AD1750??

Thanks again.

You could see this thread to understand how works I2C:

https://forum.arduino.cc/index.php?topic=503482.0

@Fraannn101, you are still stuck with the wrong ideas and you can not get further this way.
The pins are not scanned, the SDA is not read.
You should learn about I2C. The SDA and SCL make together the I2C bus (also GND is needed). It is not possible read SDA or SCL, those are the names of the two wires of the I2C bus.