Okay... Taken awhile to really search through these alternatives.
The oversampling just adds way to much noise. I can't use it. But thank you for the suggestion.
I looked into using SPI and I still get screwy readings. bunch of zeros. Sometimes a really low negative value.
This is my revised code:
// MCP3202 2 channel ADC
// 3202 is different software-wise from 3204/3208 (which are identical)
#include <SPI.h>
#define SELPIN 10
#define DATAOUT 11
#define DATAIN 12
#define SPICLOCK 13
/////////////////////////////////////////////////////////////////////////////
void setup(){
pinMode(SELPIN, OUTPUT);
SPI.begin();
SPI.setClockDivider(16);
Serial.begin(9600);
}
void loop(){
byte i;
int ain[2];
ain[0] = read_adc(SELPIN, 2);
ain[1] = read_adc(SELPIN, 1);
Serial.println(ain[0]);
Serial.println(ain[1]);
Serial.print('\n');
delay(500);
}
int read_adc(byte cs, byte channel)
{
int upperDAC = 0;
int lowerDAC = 0;
int dataDAC = 0;
// byte commandbits = B11000000; //command bits - start, mode, chn (3), dont care (3)
byte goof = B11000000; //command bits - start, mode, chn, MSBF
digitalWrite(cs, LOW); //Select adc
SPI.transfer(0x01); //1 is the start bit
upperDAC = SPI.transfer(goof);
lowerDAC = SPI.transfer(0x00);
digitalWrite(cs, HIGH);
dataDAC = (upperDAC<<8) + lowerDAC;
return dataDAC;
}
Is it something wrong in my code? Is the board wired wrong?
I tried switching Arduino pin 11 and 12 around in an act of desperation.