I'm working on a system of acquisition and ECG datalogging with the Arduino, and I'm having the following problem: I'm losing data every 103 points (just 103). No matter the sampling frequency to use, every 103 points, some points are lost, damaging the signal sampling. It could be the recording time on the SD card, but even when the SD.close () command is run only once, the data is lost. Here is a simple test algorithm with a 100 Hz sine wave at the entrance.
#include <SD.h>
#include <SPI.h>
int CS = 4;
int ECG_PIN = 1;
int voltage;
int index = 0;
const int bufferSize = 5;
int vetor[bufferSize];
int RECORD_TIME = 20000;
File logFile;
void setup(){
pinMode(CS, OUTPUT);
pinMode(ECG_PIN,INPUT);
if(!SD.begin(CS)){
return;
}
logFile = SD.open("ECG_log.txt", O_CREAT | O_WRITE);
}
void loop(){
while(millis() <= RECORD_TIME){
voltage = analogRead(ECG_PIN);
if(logFile){
logFile.println(voltage);
delay(0.5);
}
}
logFile.close();
}
What could it be? Speed analogRead ()? Problem on the SD card?
Sorry if the question is very basic, I am beginner, in a way, the Arduino platform. Any help will be very welcome.
Thanks!...