Hi,
I'm trying to log IMU data onto an SD card using the LowLatencyLogger example in the SdFat library. I wanted to shorten the number of lines of code by using a for loop. However, when I try to do this the first line of data that is recorded onto the Excel sheet is repeated over and over again.
Originally, this is how I had my code. When I ran the code, the data is shown properly on the Excel spreadsheet (shown in the first attached image):
struct data_t {
float ax1, ay1, az1;
};
void acquireData(data_t* data) {
//Acquire IMU 1 data
imu::Vector<3> accel1 = bno1.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
data->ax1 = accel1.x();
data->ay1 = accel1.y();
data->az1 = accel1.z();
}
void printData(Print* pr, data_t* data) {
//Print IMU 1 data
pr->write(',');
pr->print(data->ax1);
pr->write(',');
pr->print(data->ay1);
pr->write(',');
pr->print(data->az1);
}
void printHeader(Print* pr) {
//Print IMU 1 headers
pr->write(',');
pr->print(F("ax1"));
pr->write(',');
pr->print(F("ay1"));
pr->write(',');
pr->print(F("az1"));
pr->println();
}
However, when I tried to change the code in the printData function to a for loop, the first line that is outputted keeps repeating over and over again (shown in the second attached image).
const uint8_t IMU1_DIM = 3; //number of values in IMU 1 array
struct data_t {
float imu1_data[IMU1_DIM] = {ax1, ay1, az1}; //array of IMU 1 values
float ax1, ay1, az1;
};
void acquireData(data_t* data) {
//Acquire IMU 1 data
imu::Vector<3> accel1 = bno1.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
data->ax1 = accel1.x();
data->ay1 = accel1.y();
data->az1 = accel1.z();
}
void printData(Print* pr, data_t* data) {
//Print IMU 1 data
for (int i = 0; i < IMU1_DIM; i++) {
pr->write(',');
pr->print(data->imu1_data[i]);
}
}
void printHeader(Print* pr) {
//Print IMU 1 headers
pr->write(',');
pr->print(F("ax1"));
pr->write(',');
pr->print(F("ay1"));
pr->write(',');
pr->print(F("az1"));
pr->println();
}
I'm relatively new to programming and not really sure what I'm doing wrong so any help would be greatly appreciated! Thanks!

