Hello!
In a project I'm designing, I need to make aquisition of three sensors with a frequency of 333.3333... Hz (delays of 3 ms in 1 second), display it in the serial monitor and save it to and SD card.
My question is if saving data to SD card(it would be one println per each aquisition of the three sensors) makes the aquisition rate being changed? It is really important to me to have a minimum of 300Hz!
Thanks ![]()
The code I wrote is the following:
//aquisition variables
const int EMG_pin = A0; // Analog input pin that the EMG signal is attached to
long aq_delay = 3; // Signal aquisition rate;
unsigned long last_aq_time = 0;
int EMG_value;//SD Card libraries & variables
#include <SPI.h>
#include <SD.h>
File myFile;void setup() {
// put your setup code here, to run once:
Serial.begin(9600);while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("aquisition.txt", FILE_WRITE);}
void loop() {
// put your main code here, to run repeatedly:
if(millis() - last_aq_time >= aq_delay){ //establishes the aquisition rate
last_aq_time = millis();
//signal aquisition
EMG_value = analogRead(EMG_pin);//data display
Serial.println(EMG_value);
//data saving
if (myFile) {
myFile.println(EMG_value);
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}}
}