Hi,
I’ve made myself a data logger. It records barometric pressure, and converts to altitude, applies a filter to get rid of the noise and writes it to an SD card. It will hopefully go into a model rocket to be able to plot altitude-time data.
However-I can only get it to sample at 10Hz currently, which seems a bit slow to me? I’m a bit of a noob so there may be many ways to make the code more efficient, but I don’t really know how.
I tried to comment out all the ‘Serial.print’ lines at the bottom, and it had no effect on speed.
Any ideas or info would be greatly appreciated thanks.
void loop()
{
int buttonstate = digitalRead(buttonpin);
if (buttonstate == 1)
{
active = 1;
delay(1000);
}
if (id==1 && active==1)
{
starttime = millis();
}
if(id<20 && active==1)
{
File logFile = SD.open("TEST7.csv", FILE_WRITE);
if(logFile)
{
float clock = millis() - starttime;
float time = clock/1000;
String dataString = String(id) + ", ";
a = bmp.readAltitude(bmp.readPressure());
p=p+q;
k=p/(p+r);
x=x+k*(a-x);
p=(1-k)*p;
logFile.print(dataString);
logFile.print(time);
logFile.print(", ");
logFile.print(a);
logFile.print(", ");
logFile.println(x);
logFile.close();
Serial.print(dataString);
Serial.print(time);
Serial.print(", ");
Serial.print(a);
Serial.print(", ");
Serial.println(x);
buttonstate = digitalRead(buttonpin);
if (buttonstate == 1)
{
active = 0;
delay(1000);
}
}
else
{
Serial.println("Couldn't access SD Card file");
}
id++;
}
}