Heres my new get voltage function
double Adc::getVoltage()
{
while(digitalRead(RDY)); //once RDY pin is pulled low
digitalWrite(_pin, LOW);//pull CS low
selectADC();
delay(100); // a dealy here could help
SPI.transfer(0x5C); // Channel 1 Data Register
//(0101 1100)
byte inputBytes[4];
inputBytes[3] = 0x00; //MSB all 0's
inputBytes[2] = SPI.transfer(0x00);
inputBytes[1] = SPI.transfer(0x00);
inputBytes[0] = SPI.transfer(0x00);
digitalWrite(_pin, HIGH);
convertToVoltage(inputBytes);
const char dummy = 'D';
writeToSD(dummy);
return 0;
}
and the convert to voltage function i'm using:
void Adc::convertToVoltage(byte inputBytes[4]) {
double MSB = inputBytes[2];
double SB = inputBytes[1];
double LSB = inputBytes[0];
double result = (MSB * 256 * 256);
result = result + (SB * 256);
result = result + LSB ;
result = (result * 6.6 / 256 / 256 / 256) - 3.3;
Serial.println("result is");
Serial.print(result);
Serial.print(" volts");
}