Programming ADC1231

To anyone familiar with these chips, what is some simple code I can use to read the data from the chip, and print it to the serial monitor on an Arduino Uno.

I have this so far.
int data = 9;
int sclk = 10;
int pdwn = 11;
int clkin = 12;
int SPEED = 13;
void setup() {
pinMode(SPEED, LOW);
pinMode(clkin, LOW);
pinMode(data, HIGH);
Serial.begin(9600);
}
void loop() {
if (digitalRead(data == LOW)){
const int packetLength = 25;
int SG[packetLength];
for(int x = 0; x <= 25; x++){
digitalWrite(sclk, HIGH);
SG[x] = analogRead(data);
Serial.println(SG[x]);
digitalWrite(sclk, LOW);
}
}
}
I'm only storing it in an array now, because I might be storing the whole array on an SD card at the end of every loop. I am mostly concerned with getting a correct reading.

Here's a link to the data sheet.

Thanks.

pinMode(SPEED, LOW);
pinMode(clkin, LOW);
pinMode(data, HIGH);

pinMode is either INPUT, OUTPUT or INPUT_PULLUP. You need separate statements to set them low if they are outputs.

for(int x = 0; x <= 25; x++){
digitalWrite(sclk, HIGH);
SG = analogRead(data);
Serial.println(SG );

digitalWrite(sclk, LOW);

analogRead on a digital input is not right. Use digitalRead. Your data is not going to an array. SG will hold only the value of the last read bit. The data is coming in serially. Investigate shiftIn(). With 3 calls to shifIn() you can input all 3 bytes from the AD.

Digital read only reads whether the pin is high or low. The data pin goes low when it is ready for data to be read, and shifting sclk to high pushes out one of the 24 bits. How and where do I store and read this bit? I can't use digital read on the data pin, as it will only read 1 or 0.

If you use shiftIn(data,sclk,MSB_FIRST) The clocking and bit shifting is done for you.
You would do like:
once the data line goes LOW,

byte highBYTE = shiftIn(data,sclk,MSB_FIRST);
byte middleBYTE = shiftIn(data,sclk,MSB_FIRST);
byte lowBYTE = shiftIn(data,sclk,MSB_FIRST);

I found this discussion from the forum that may be of help. It is for a similar chip.
http://forum.arduino.cc/index.php/topic,128823.0.html

Thanks, that post was very helpful.

My new code looks like this,

int data = 9;
int sclk = 10;
int pdwn = 11;
int clkin = 12;
int SPEED = 13;
void setup() {
  // put your setup code here, to run once:
  pinMode(SPEED, OUTPUT);
  pinMode(clkin, OUTPUT);
  pinMode(data, INPUT);
  pinMode(sclk, OUTPUT);
  pinMode(pdwn, OUTPUT);
  digitalWrite(SPEED, LOW);
  digitalWrite(clkin, LOW);
  digitalWrite(data, HIGH);
  Serial.begin(9600);

}                         

void loop() {
    int32_t value = 0;
    digitalWrite(sclk, HIGH); //enter standby
    delay(1000);
    digitalWrite(sclk, LOW); //wake up
    //wait for data ready
    if (digitalRead(data) == LOW);
    value = shiftIn(data, sclk, MSBFIRST);
    value <<= 8;
    value |= shiftIn(data, sclk, MSBFIRST);
    value <<= 8;
    value |= shiftIn(data, sclk, MSBFIRST);
    
    digitalWrite(sclk, HIGH); // polling pulse
    digitalWrite(sclk, LOW);
    value = ((signed long) (value << 8)) >> 8; 
    
    Serial.println(value,DEC);
    
}

All thats printed to the serial monitor is -1 every iteration. It prints -1 even if No pins are connected to the arduino. Would my breadboard circuit, or code be wrong? Thanks again.

Also when I use

while (digitalRead(data) == LOW);
    byte highBYTE = shiftIn(data, sclk, MSBFIRST);
    byte midBYTE  = shiftIn(data, sclk, MSBFIRST);
    byte lowBYTE  = shiftIn(data, sclk, MSBFIRST);
    
    digitalWrite(sclk, HIGH); // polling pulse
    digitalWrite(sclk, LOW);
    
    
    Serial.println(highBYTE);
    Serial.println(midBYTE);
    Serial.println(lowBYTE);

I get a constant value of 255 which would be 1.

digitalWrite(SPEED, LOW);
  digitalWrite(clkin, LOW);
  digitalWrite(data, HIGH);  // did you mean pdwn vs data.  This turns on the internal pullup on pin 9 as it is

For troubleshooting tie pins 11, 12, 13 (pdwn, clkin, SPEED) to +5 for pdwn, gnd to clkin and gnd to SPEED on the breadboard to remove them from the equation.

Tying the pins helped. The code is shifting data and printing it, but now with a balanced bridge the first byte is always 128, the second 0, and the third 0 as well. With the fourth resistor of the bridge swapped for another of different resistance, the first byte is always around some constant number, and the second and third bytes seem to be random.

Try the code from your reply #4. That should yield a decimal number. What do you mean first byte , second bye...? In terms of high, middle low would be less ambiguous.

Im pretty sure I've got it working. When balanced it reads 8388608, which is half of 2^24. This makes sense meaning that zero is in the middle of the chips range. When I change a resistor the value always changes to something else, that is rather constant. I haven't figured out quite the right conversion to get it to volts yet, but I'm close. Thanks for all your help.

See page 12 on the data sheet for output range.

Hmm so when balanced, the reading is the negative full scale input? Well, that's not right.

My unhelpful advice would be to throw away that chip and get one that works by standard I2C or SPI. There are so many different things that could be causing your problem, it is hard to know where to start.