Hello guys!!
It's been a while sence I solved my arduino isues tacking advantage of this comunity.
I'm posting on the forum for the first time, mostly because I haven't found any similar posts.
I'm correnctly building my own DAQ using arduino uno (for now, later I'll use a pro micro), and ADC ADS1220, and logging the data to an SD card.
I also have an 0.92" Oled I2C display, wich shows the analog read in mV between AIN0 and AIN1 on the DAS1220, with a high enough precision.
The trubleshooting started when I added the SD card, using the SD.h library truth SPI comunication, bougth the SD card and the ADS1220 use SPI comunication, been connected to different CS_pins.
Everything works well until the SD card is initialized by the SD.begin() command, when the ADC readings go to negative lavues independently of the analog input.
The first aplication will be to measure the output in mV of an geophysical measuring device.
There will be two buttons for to different data measurments.
I'll post the arduino code bellow
//--------------------------------Constants-----------------------
const int butVert=2;
const int butHori=3;
int nSamples=100; //Define the number of samples do colect in each line
//--------------------------------Variables------------------------
float Volts;
//------------------------------Screen-----------------------------
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
Adafruit_SSD1306 dsp(-1);
//------------------------------ADS1220----------------------------
#include "Protocentral_ADS1220.h"
#include <SPI.h>
#define ADS1220_CS_PIN 7
#define ADS1220_DRDY_PIN 6
Protocentral_ADS1220 pc_ads1220;
int32_t adc_data;
//-----------------------------SD---------------------------------
#include "SdFat.h"
SdFat sd;
const int chipSelect = 8;
void setup() {
Serial.begin(115200);
//-----------------------------buttons-------------------------
pinMode(butVert,INPUT);
pinMode(butHori,INPUT);
//-----------------------------screen--------------------------
dsp.begin(SSD1306_SWITCHCAPVCC, 0x3C);
dsp.clearDisplay();
dsp.setTextColor(WHITE);
//------------------------------ADS1220-----------------
pc_ads1220.begin(ADS1220_CS_PIN,ADS1220_DRDY_PIN);
//Uncoment the line to select the sample rate
pc_ads1220.set_data_rate(DR_20SPS); //20 samples/second
// pc_ads1220.set_data_rate(DR_45SPS); //45 samples/second
// pc_ads1220.set_data_rate(DR_90SPS); //90 samples/second
// pc_ads1220.set_data_rate(DR_175SPS); //175 samples/second
// pc_ads1220.set_data_rate(DR_330SPS); //330 samples/second
// pc_ads1220.set_data_rate(DR_600SPS); //600 samples/second
// pc_ads1220.set_data_rate(DR_1000SPS); //1000 samples/second
pc_ads1220.set_pga_gain(PGA_GAIN_1);
//Uncoment the line to be configure the differencial analog input
pc_ads1220.select_mux_channels(MUX_AIN0_AIN1); //Configure for differential measurement between A0 and A1
// pc_ads1220.select_mux_channels(MUX_AIN0_AIN2); //Configure for differential measurement between A0 and A2
// pc_ads1220.select_mux_channels(MUX_AIN0_AIN3); //Configure for differential measurement between A0 and A3
// pc_ads1220.select_mux_channels(MUX_AIN1_AIN2); //Configure for differential measurement between A1 and A2
// pc_ads1220.select_mux_channels(MUX_AIN1_AIN3); //Configure for differential measurement between A1 and A3
// pc_ads1220.select_mux_channels(MUX_AIN3_AIN2); //Configure for differential measurement between A3 and A2
// pc_ads1220.select_mux_channels(MUX_AIN1_AIN0); //Configure for differential measurement between A1 and A0
// pc_ads1220.select_mux_channels(MUX_AIN3_AIN2); //Configure for differential measurement between A3 and A1
pc_ads1220.Start_Conv(); //Start continuous conversion mode
//----------------------SD-------------------------------------------
/*Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
}
Serial.println("card initialized.");
SD.end();*/
}
void loop() {
//----------------------ADS1220-------------------------------
//----------------------Screen---------------------------------
dsp.setTextSize(2);
dsp.setCursor(1,15);
adc_data=pc_ads1220.Read_WaitForData();
float Vout = (float)((adc_data*2.048*1000)/(16777216/2));
dsp.print(Vout);
dsp.setCursor(100,15);
dsp.print("mV");
dsp.setTextSize(1);
dsp.setCursor(1,1);
dsp.print("ponto:");
dsp.setTextSize(1);
dsp.setCursor(40,1);
dsp.print("xxx"); //lugar para adicionar o numero do ponto
dsp.display();
dsp.clearDisplay();
//-----------------------Buttons----------------------------------
if (digitalRead(butVert)==LOW){
Serial.print("P1V\t");
ads1220_Data();
}
if (digitalRead(butHori)==LOW){
Serial.print("P1H\t");
ads1220_Data();
}
//---------------------------SD-------------------------------
/*File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print("xxx/t");
dataFile.close();
}*/
}
//--------------------------Functions-----------------------
float ads1220_Data(){ //reads de values converted by DAS1220
//will be chaged later to log to the SD_card
dsp.clearDisplay();
dsp.setTextSize(4);
dsp.setCursor(15,3);
dsp.print("Wait");
dsp.display();
dsp.clearDisplay();
int i;
for(i=0; i<=nSamples; i++){
while(digitalRead(ADS1220_DRDY_PIN) == HIGH);
adc_data=pc_ads1220.Read_WaitForData();
Volts = (float)((adc_data*2.048*1000)/(16777216/2));
Serial.print((float)Volts);
Serial.print("\t");
}
Serial.println();
return Volts;
}
I'm not a good programer so most of my code was parasitized from te examples that come with the libraries.
I think my problem issues with the SPI communication, but I don't know how to solve it, thus I'm asking for you help.
Many thanks