Hello community, I have the following issue:
I'm trying to sampling and store a voltage signal using the ADC and also the SD card module.
The thing is, firstly I store all the data that comes from the voltage signal in an array of ints (15000 positions) and then I write it in the SD card but when I executed the code, the arduino simply does nothing.
I tried with no array ints, and It worked perfect, but with the array no. I read that with file.write() it is possible to do but just with chars, strings and bytes but no with ints.
here's my code
#include <SD.h>
const int chipSelect=4;
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
void setup() {
Serial.begin(9600);
sbi(ADCSRA, ADPS2);
cbi(ADCSRA, ADPS1);
cbi(ADCSRA, ADPS0);
analogReference(DEFAULT);
pinMode(A0,INPUT);
if(!SD.begin(chipSelect)){
Serial.println("Error al leer la tarjeta.");
return;
}
}
void loop() {
long t0,t;
File dataFile=SD.open("pruebas.txt" ,FILE_WRITE);
int a[14999];
long int pot=0;
if(dataFile){
Serial.println("Sampling begins in 3seg");
delay(3000);
for(int i=0; i<15000; i++) {
a[i]=analogRead(A0);
}
Serial.println("Writing");
for(int j=0; j<15000; j++) {
pot=a[j];
dataFile.println(a[j]);
}
Serial.println("End of writing.");
dataFile.close();
delay(15000);
}
else{
Serial.println("Error ");
}
delay(2000);
}