Gravitech's 12bit ADC + Arduino UNO

I want to expand the # of analog pins on my Arduino Uno by using the Gravtech 12bit ADC: http://www.gravitech.us/i2c128anco.html.

But Im not sure how to code it. I have some sample code from the Gravitech website here:

/******************************************************************************
Example program I2C-ADC interface with Arduino.

SETUP: I2C-ADC => Arduino
PIN7 => ground, PIN11 => A5(SCL), PIN12 => A4(SDA), PIN14 => +5V
Note: The program is written for address 0x90 (Arduino address 0x48).
This program was tested using Arduino Nano
Document: AD7828 datasheet
Updated: September 4, 2008
E-mail: support@gravitech.us
Gravitech
(C) Copyright 2008 All Rights Reserved
*******************************************************************************/

#include <Wire.h>

/*******************************************************************************
Setup
*******************************************************************************/
void setup()
{
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
delay(1000);
}

/*******************************************************************************
Main Loop
*******************************************************************************/
void loop()
{
const int I2C_address = 0x48; // I2C write address
const byte DAT[8] = {0x8C,0xCC,0x9C,0xDC,0xAC,0xEC,0xBC,0xFC};
// Constant configuration data

byte Adval_High, Adval_Low; // Store A/D value (high byte, low byte)
byte i; // Counter

delay(1000);

for (i=0; i<=7; i++)
{
Wire.beginTransmission(I2C_address);
Wire.write(DAT*); // Configure the device to read each CH *

  • Wire.endTransmission();*

  • delay(1);*

  • // Read A/D value*

  • Wire.requestFrom(I2C_address, 2);*

  • while(Wire.available()) // Check for data from slave*

  • {*

  • Adval_High = Wire.read(); // Receive A/D high byte*

  • Adval_Low = Wire.read(); // Receive A/D low byte*

  • }*

  • Serial.print("A/D value CH");*

  • Serial.print(i, DEC);*

  • Serial.print(" is ");*

  • Serial.print(Adval_High,HEX);*

  • if (Adval_Low <= 0x0F)*

  • Serial.print("0");*

  • Serial.println(Adval_Low,HEX);*

  • } *

  • Serial.println();*
    }
    But nothing appears on the serial monitor! Help!!

Well for one problem I see you trying to send an array via a Wire.send command which can only handle single byte transfers. Looking at the site link for the same code you seemed to have dropped the array pointer info as it shows using:

for (i=0; i<=7; i++)
  {
    Wire.beginTransmission(I2C_address);
    Wire.send(DAT[i]);        // Configure the device to read each CH  
    Wire.endTransmission(); 
    delay(1);

Your posting is missing the [i] array pointer:

 Wire.write(DAT);        // Configure the device to read each CH

So mistype? Bad cut and paste? I didn't look for other possible errors, but give that a shot and see if you move further along.

Lefty

So mistype? Bad cut and paste?

No. The forum software interpreted the sequence of characters '[', 'i', and ']' in the "code" as the flag to start italicizing the text. Using code tags (by pressing the # icon) would have prevented that.

But nothing appears on the serial monitor! Help!!

It would appear, then, that you do not have the ADC connected correctly, or that you are using the wrong address to talk to it.

The two lines I'm confused about are here in the sample code:

#void loop()
{
const int I2C_address = 0x90; //0x48; // I2C write address
const byte DAT[8] = {0x8C,0xCC,0x9C,0xDC,0xAC,0xEC,0xBC,0xFC};
// Constant configuration data

How are the addresses known? I'm not sure where the coder is pulling these addresses from; the datasheet is confusing to me. Are these the correct addresses to use?

The ADS7828 has two address pins and can therefore be set to occupy one of 4 I2C addresses. Gravitech have presumably decided on one such address.

If you look at the data sheet on page 12 Fig 3 the address format is

10010 A1 A0 R

0x90 is

10010000

so they have set A0 and A0 (the yellow bits) to LOW on the PCB. (The LSB is a R/W flag.)


Rob