Help needed with writing data to a CSV on an SD card

Hi everyone,

I am trying to read and store some data that I am receiving over radio communication. (HC-12).

The data comes in 2 batches: First, the timestamps of all measurements, and in the second, the actual data from these measurements.

What I am trying to do is first reading and then storing the timestamps of the measurements in the csv file, which I have managed to do like below:

However, after that, I am confused as to how I can store the corresponding sensor data to the corrosponding time. For example, how can I store the first reading in cells C2, D2, etc. Is there a nice and simple way to do this?

Also, I would highly prefer not to read all the data first and then store it, as I can be receiving almost thousands of bytes of data, and I am very sure arduino wont be able to handle storing all of that data all at once, so I prefer to read and immediately store the data. Thank you!

I don't understand the problem

At say 10:57:03 on 13/11/24 save the date and time then save each of the sensor readings taken at that date/time, separated by a comma. After the last reading add a newline character ready for the next date/time and readings

If the timestamps and data are received in the same order, the simplest way is to read a timestamp from the file, then write the timestamp with its data to a new file.

1 Like

That sounds rather strange. What would happen if the number of timestamps is different to the number of measurements as it would imply a piece of data has got lost?

How would you handle a timestamp and an unrelated measurement going missing as your measurement may no be stored against the correct timestamp?

Do you have any control over how the data is sent to you?

You don't. You organise things so something as stupid as that doesn't happen. That is what loops are for.

There is a data logging example in the SD library, which is probably all you need.

Can you post some examples, because your description is not very detailed and ambiguous.

Do you have control over the way that data is sent? Sending it 2 batches like this doesn't seem very sensible.

When the actual data arrives, how do you know which timestamp it belongs with?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.