Tables vs Arrays

Hi,

I’ve got a project I’m working on to measure room conditions:

  • temperature
  • humidity
  • pressure

I’d like to sample sensor used to collect these this once every 10 minutes.

I’m using a clock (RTC) and when it is an interval of 10 mins, it will run a for loop and grab the data.

I’d then like to store this data. I’m thinking either table or an array. But the lines (rows) will reach into the thousands as I need to store and retrieve the data only 1x / month

Questions:

  1. Is it better to store as an array or a table?

  2. Is there a difference between which is faster, or able to store decimals better?

I’ll but using an UNO board, and writing the data as it’s recorded to a microSD card on a shield.

What, exactly, do you think a "table" is, if not some kind of array....

Regards,
Ray L.

Well I wasn't sure, I'm slightly new to programming them.

Do you use an array to make a table?

If you want to store your data on an SD card I recommend you look into XML or JSON. Both are fairly easy to read as a human when you store simple data in it and have nice support to be read by all kinds of programming environments.

Have a look at GPX files which are created by GPS programs. They are based on XML

JSON can be used by JavaScripts

project_science:
I’ve got a project I’m working on to measure room conditions:

  • temperature
  • humidity
  • pressure

I’d like to sample sensor used to collect these this once every 10 minutes.

Are all data types the same? Will the timestamp also be saved?

If you want to store on a SD card, just read the values and save to card; no need for arrays.

For easy importing into a spreadsheet program, store in csv format.

If you want to store your data on an SD card I recommend you look into XML or JSON.

Why complicate things when a simple comma separated file is an easy format to write to and read from ?

project_science:
I’m thinking either table or an array.

by table i assume you mean to capture a single measurement as a bundle of information.

the following shows how to define a new type, representing a measurement. it also shows how an array of such types can be defined, but you would most likely just write one instance of Data_t to the SD card, appending a record to the file on the card

typedef struct {
    byte    month;
    byte    day;
    byte    hour;
    byte    min;
    byte    sec;
} Time_t;

typedef struct {
    Time_t  timestamp;
    byte    tempF;
    byte    humidity;
    byte    pressure;
} Data_t;


Data_t  data [10];

You can use CSV, it has been used for more than 40 years and is still used in many applications.

UKHeliBob:
Why complicate things when a simple comma separated file is an easy format to write to and read from ?

I do not believe printing a couple of extra characters really complicates things. And the XML file format is more flexible and supports hierarchical data.

For instance you can change the way you store parameters and just continue using the same file. e.g.

21.5

70.7

You can easily store data at different intervals. In a table you would need to store empty values.

Additionally there are tools for XML validation and repair.

the XML file format is more flexible and supports hierarchical data.

True, but according to the OP all he wants to do is to store 3 items of data at intervals and he/she would be wise to also store the date/time of the reading. So, no hierarchy needed and a simple flat format that can be read and analysed by any spreadsheet program as well as host of database programs and is, of course, readable by humans too