I am making an data logger project. In my data logger, I have 5 sensors like: temperature, humidity, accelerometer, light and barometer. Here, I am storing the data in to SD card in binary format. I'm storing accelerometer @3200HZ and all other sensors at 1HZ.
While writing, I'm adding a special character like $,& to each sensor measurements to identify the data while reading. I am not adding any spl character for accelerometer data. Accelerometer data is huge data with 3200HZ so I'm not adding spl character as it consumes some memory also it making delay while writing leading to miss out some samples and able to achive only 2600HZ for 3200HZ.
My reading data code looks like below:
while((nr = fgetc(logFile)) != EOF)
{
if (nr == '$')
{ // read temp data if nr = $
fread(&temp_read,sizeof(float),1,logFile);
pc.printf("\r\n %f",temp_read);
}
if (nr == '&')
{ // read humidity data if nr = &
fread(&Humidity_read,sizeof(float),1,logFile);
pc.printf("\r\n %f",Humidity_read);
}
else
{ // if nr is not a spl character
data1 = nr;// send nr to a variable.
nr = fgetc(logFile);// read next byte and save it in nr
data2 = nr;// send nr to another variable
int16_t temp = (data1 | (data2 << 8));// club both bytes to form int16_t data
pc.printf("\r\n %i",temp);// print the one axis
}
}
Unfortunately this program giving wrong data. There is huge difference. Is there any another way to solve this problem. Where I'm making errors. Thank you in advance.