fat16lib and PaulS thanks for replying !
Since I have very basic knowledge in programming, I´m having a hard time understanding the suggested codes, specially LowLatencyLogger.
What I pretend to do is receive the heart signal through 3 analog pins (A0-A2), then use the ADC and save them to the SD card as text file to plot the signal after it.
I wonder if you can help me with my code... It´s pretty basic, this is what I have so far:
uint32_t lastTime;
void setup()
{
Serial.begin(115200);
lastTime = millis();
Serial.println("Miliseg,Valor1,Valor2,Valor3");
}
void loop()
{
while ((millis() - lastTime) < 2); // wait for 2 ms passed
lastTime = millis();
int x = analogRead(A0);
int y = analogRead(A1);
int z = analogRead(A2); // make a read
Serial.print(millis());
Serial.print(",");
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
Serial.println(z);// send it
}
This is a code I found to sample 500 samples for sec.
Then I modified it to trying log it into the SD card with this:
#include <SD.h>
uint32_t lastTime;
const int chipSelect = 10;
void setup()
{
Serial.begin(9600);
lastTime = millis();
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
pinMode(4, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.println("Miliseg,Valor1,Valor2,Valor3");
}
void loop()
{
while ((millis() - lastTime) < 2); // wait for 2 ms passed
lastTime = millis();
int x = analogRead(A0);
int y = analogRead(A1);
int z = analogRead(A2);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(millis());
dataFile.print(",");
dataFile.print(x);
dataFile.print(",");
dataFile.print(y);
dataFile.print(",");
dataFile.println(z);
dataFile.close();
Serial.print(millis());
Serial.print(",");
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
Serial.println(z);// send it
}
else {
Serial.println("error opening datalog.txt");
}
}
This code only log around 50 samples for second.
I appreciate if you guys could help me to understand what can be modified to get what I need.