Small scale datalogging

I know there are various ways to log data to SD cards etc. However ...
From my very basic test it looks as though it would be possible to write upto a few thousand unsigned long integers to an array. That's significant;y more than I would expect to need (a few hundred would be more than enough), but I was wondering a) whether it's just a really bad idea, b) if not, what the limiting factors are and c) whether there's a better way to do small scale data logging without external data storage?

What Arduino board are you using? The, primary, limiting factor is how much SRAM the board has if the data is stored in RAM. Uno has 2K bytes SRAM, Mega has 8K bytes. Each unsigned int long takes 2 4 bytes

edit: misread the size of the data.

And 16K on Atmega1284P.

The OP is storing unsigned long ints so 4 bytes per entry. You can also jump to a Teensy and up your memory capacity to 1024K

Storing data in ram has the major disadvantage that you will lose the data if the power goes out, or the arduino resets (not always true, but your sketch will need to save information that will persist across a reset in order to take up where it left off).

blh64:
The OP is storing unsigned long ints so 4 bytes per entry. You can also jump to a Teensy and up your memory capacity to 1024K

640K ought to be enough for anybody.

a7

Thanks all.

I'm currently using a Nano, so 2K of SRAM. I'm not bothered about memory being volatile.

On my current sketch, the IDE reports:

Global variables use 1392 bytes (67%) of dynamic memory, leaving 656 bytes for local variables. Maximum is 2048 bytes.

If an unsigned long is 4 bytes, that's room for 164 unsigned long values ... right?

I'm surrprised there's as much as 1392 bytes used. I've currently got the wire.h and an I2C LCD library. Is it likely they will be using much SRAM?

That 1392 bytes used is just how much memory that the compiler can know about. Any memory used by local variables is not reported. There are utilities that can tell you how much memory is free at any time during runtime.

fenghuang:
c) whether there's a better way to do small scale data logging without external data storage?

I guess that depends entirely on how seriously you need the logged data. A Mega or NodeMCU may hold more data than you need in memory - right up to the point when the lights go out, but that may be quite OK for some quick short term thing.

fenghuang:
I'm surrprised there's as much as 1392 bytes used. I've currently got the wire.h and an I2C LCD library. Is it likely they will be using much SRAM?

The libraries themselves will not use that much SRAM. If you are printing a lot of text to the LCD or Serial, that can use a considerable amount of RAM, in which case the F() macro can help considerably by storing text literals in program memory.

lcd.print("this text is stored in SRAM");
lcd.print(F("this text is stored in program memory"));

Thanks.
David_2018 I've used Serial.Print for debugging, so that makes a lot of sense. Looks like it's time to do some rationalising. :slight_smile:

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