So my data collection system seems to be working great for a couple of seconds and then these delays get massive. Does anyone know whats going on?
Ill attach my code in the next post, for now here's my output:
Time: 2653.00 | Alt: -1.65 | Ax: -0.72 | Ay: -0.28 | Az: 9.16 | Gx: -0.05 | Gy: -0.01 | Gz: -0.01 | Temp: 20.33 *C
Time: 2665.00 | Alt: -1.65 | Ax: -0.74 | Ay: -0.27 | Az: 9.12 | Gx: -0.05 | Gy: -0.01 | Gz: -0.01 | Temp: 20.33 *C
Time: 2677.00 | Alt: -1.65 | Ax: -0.73 | Ay: -0.27 | Az: 9.12 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.33 *C
Time: 2690.00 | Alt: -1.65 | Ax: -0.73 | Ay: -0.26 | Az: 9.12 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.33 *C
Time: 2702.00 | Alt: -1.65 | Ax: -0.75 | Ay: -0.28 | Az: 9.09 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.32 *C
Time: 2714.00 | Alt: -1.65 | Ax: -0.78 | Ay: -0.27 | Az: 9.12 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.31 *C
Time: 2726.00 | Alt: -1.65 | Ax: -0.77 | Ay: -0.27 | Az: 9.09 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.32 *C
Time: 2740.00 | Alt: -1.65 | Ax: -0.74 | Ay: -0.28 | Az: 9.11 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.31 *C
Time: 2753.00 | Alt: -1.65 | Ax: -0.74 | Ay: -0.28 | Az: 9.13 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.31 *C
Time: 2765.00 | Alt: -1.65 | Ax: -0.74 | Ay: -0.25 | Az: 9.11 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.30 *C
Time: 2778.00 | Alt: -1.65 | Ax: -0.74 | Ay: -0.27 | Az: 9.09 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.32 *C
Time: 2790.00 | Alt: -1.65 | Ax: -0.74 | Ay: -0.25 | Az: 9.11 | Gx: -0.05 | Gy: -0.02 | Gz: -0.01 | Temp: 20.32 *C
Time: 5056.00 | Alt: -1.64 | Ax: -0.28 | Ay: -0.30 | Az: 9.15 | Gx: -0.13 | Gy: 0.13 | Gz: -0.02 | Temp: 20.34 *C
Time: 5361.00 | Alt: -1.64 | Ax: -0.34 | Ay: -0.34 | Az: 9.12 | Gx: -0.09 | Gy: 0.04 | Gz: -0.02 | Temp: 20.35 *C
Time: 5666.00 | Alt: -1.64 | Ax: -0.36 | Ay: -0.41 | Az: 9.18 | Gx: -0.05 | Gy: -0.03 | Gz: -0.01 | Temp: 20.38 *C
Time: 5971.00 | Alt: -1.63 | Ax: -0.35 | Ay: -0.46 | Az: 9.16 | Gx: -0.06 | Gy: -0.04 | Gz: -0.02 | Temp: 20.36 *C
Time: 6276.00 | Alt: -1.63 | Ax: -0.22 | Ay: -0.47 | Az: 9.10 | Gx: -0.06 | Gy: -0.04 | Gz: -0.01 | Temp: 20.37 *C
Time: 6581.00 | Alt: -1.63 | Ax: -0.09 | Ay: -0.45 | Az: 9.12 | Gx: -0.06 | Gy: -0.04 | Gz: -0.01 | Temp: 20.37 *C
Time: 6887.00 | Alt: -1.63 | Ax: -0.10 | Ay: -0.49 | Az: 9.16 | Gx: -0.06 | Gy: -0.02 | Gz: -0.01 | Temp: 20.39 *C
Time: 7192.00 | Alt: -1.64 | Ax: -0.11 | Ay: -0.50 | Az: 9.17 | Gx: -0.05 | Gy: -0.03 | Gz: -0.01 | Temp: 20.39 *C
Time: 7498.00 | Alt: -1.65 | Ax: -0.05 | Ay: -0.55 | Az: 9.05 | Gx: -0.06 | Gy: -0.04 | Gz: -0.02 | Temp: 20.40 *C
void run() {
collectData();
curData[0] = millis() - startTime;
printData();
SDWrite();
//transmitRunData();
}
void collectData () {
getAccelerometerData();
getAltitude();
}
void getAltitude() {
curData[1] = baro.readAltitude(startPressure);
return;
}
void getAccelerometerData() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
curData[2] = a.acceleration.x;
curData[3] = a.acceleration.y;
curData[4] = a.acceleration.z;
curData[5] = g.gyro.x;
curData[6] = g.gyro.y;
curData[7] = g.gyro.z;
curData[8] = temp.temperature;
}
void printData () {
Serial.print("Time: ");
Serial.print(curData[0]);
Serial.print(" | ");
Serial.print("Alt: ");
Serial.print(curData[1]);
Serial.print(" | ");
Serial.print("Ax: ");
Serial.print(curData[2]);
Serial.print(" | ");
Serial.print("Ay: ");
Serial.print(curData[3]);
Serial.print(" | ");
Serial.print("Az: ");
Serial.print(curData[4]);
Serial.print(" | ");
Serial.print("Gx: ");
Serial.print(curData[5]);
Serial.print(" | ");
Serial.print("Gy: ");
Serial.print(curData[6]);
Serial.print(" | ");
Serial.print("Gz: ");
Serial.print(curData[7]);
Serial.print(" | ");
Serial.print("Temp: ");
Serial.print(curData[8]);
Serial.println(" *C");
}
void SDWrite() {
myFile = SD.open(fileName, FILE_WRITE);
if(myFile) {
myFile.print(curData[0]); myFile.print(",");
myFile.print(curData[1]); myFile.print(",");
myFile.print(curData[2]); myFile.print(",");
myFile.print(curData[3]); myFile.print(",");
myFile.print(curData[4]); myFile.print(",");
myFile.print(curData[5]); myFile.print(",");
myFile.print(curData[6]); myFile.print(",");
myFile.print(curData[7]); myFile.print(",");
myFile.println(curData[7]);
myFile.close();
}
}
add printing to the serial monitor to narrow down where the delay is happening
Opening a file, writing a few lines of data, then closing it again vastly increases the error rate and the current draw, and as the file gets longer, the entire process gets slower and slower.
myFile = SD.open(fileName, FILE_WRITE);
...
myFile.println(curData[7]);
myFile.close();
}
To write data quickly and reliably, open the file once in setup() and close it only when you are all done collecting data.
To avoid losing data during power failures, issue a myFile.flush()
command every so often: every 15 minutes, every hour, etc.
as recommended by @jremington don't open/close the file on each write of data
rather then writing text to the file write the raw binary data it should be much faster
Im pretty bad at going in between data types and trying to decipher what they all mean (I know this is important to learn but one thing at a time). How would I process the binary data once its in the excel file
You seem to create a CSV file, which is a human-readable representation of some data table.
Excel happens to be able to import such a file, but that does not make it an Excel file.
You could write a small program, that converts from the binary format to CSV,
and runs on the device that runs Excel.
system
Closed
November 26, 2023, 5:11pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.