0

Flow goes something like:

Read sensors Send data If send fails store the data in eeprom/flash/sd If sent check if any previous ones have failed and send those

So my question is what's the best storage option to save the data? Is there an easy way to save strings or am I going to have to write it byte by byte?

  • Depends on how many data you want to save. And do you have something like a backup battery? In my current project, I save some RFIDkeys to EEPROM when it has no internet connection and low battery, otherwise it just waits for internet connection. Writing byte-by-byte isn't actually that difficult, you can use a struct to pack your bytes and then write the bytes of the struct to your memory. Put it in a for loop, and it'll save them all. – Paul May 4 '15 at 7:28
1

In my opinion SD would be the best way because it is cheap, small, relatively fast and easily portable on a PC, using FAT (but it uses a lot of resources) or even raw; but then you have to use some more trick to get to the raw data from a OS, its not just "plug n read".

The SD library uses FAT under the hood, and it gives you a nice and easy interface. Just remember that SD works at 3.3V, and connecting them directly to arduino will break them fast, even if often not immediately.

  • SD would mean a bigger footprint though, right? a 1Mbit SO chip is pretty small but supporting an SD slot takes up a lot of space. I only use 3.3v arduinos now. :-) – Ryan Detzel Mar 4 '15 at 21:30
  • well, you can use a microSD, they have the same interface. beat that :P I normally buy microSD with adapter, and i use to solder directly on the adapter, so i can easily swap the card when needed (please pay attention to remove them when the micro is NOT writing. i use a "unmount button" or a temporized write every seconds, with a led that light up when writing) – Lesto Mar 4 '15 at 21:36
0

Other than SD (see @lesto's answer), you can also store the data locally on your Arduino's EEPROM. You can store a byte at a time. The amount of storage varies from chip to chip, the AtMega328p that powers Arduino UNOs has 1kb. The eeprom is persistent over resets, I suspect not if you're reprogramming it, so think how you're going to get the data off before you start storing valuable info.

At 1kb, size is at a premium, so you probably don't want to use text strings, just the raw data. Remember that, if your chip resets, you will lose any memory variables with info about e.g. where you're up to. I would probably include some sort of checksum of each record, to test if the data is yours or not. I would include a counter or timestamp, so when you are starting up, you can read all memory to find the newest (valid) record; the next record is one greater, and at the next memory address. When you get to the end of the memory, restart at 0. If you store a one-byte counter, a one byte checksum, and 2 bytes of data, you can store 256 records. You could mark records off as you send them, or keep a counter in memory of which ones you have already sent - if your chip is reset, it may resend old records (very rarely), which your server would need then need to handle.

If using eeprom, try to spread your writes - you get a certain number of writes PER MEMORY LOCATION, so if you always write to address 15, then 15 will wear out before the others. I think I saw a reference to "100,000 writes", but am unable to find that now to confirm. 100,000 writes at 1 write per second to the same address will have your eeprom fail after about 27 hours; 4 writes per second spread over 1K will cause a fail after about 10 months.

Test what happens when you write past the end of memory - some possible scenarios include failed write, write to a different location (e.g. trying to write to address 1024+1 will write to address 1024), not writing at all and reading it back will return 0, 255, or another number (consistent or otherwise)

See http://arduino.cc/en/Reference/EEPROM on how to write to eeprom.

To find out how many bytes of memory your EEPROM has, use E2END. Addresses run from 0 to E2END, so E2END might be 1023 (0 to 1023=1024 bytes).

  • The reference to "100,000 writes" can be found in the ATmega datasheet: “The EEPROM has an endurance of at least 100,000 write/erase cycles.” – Edgar Bonet Mar 5 '15 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.