1

I was wondering what is the best way to store files on Arduino, I've seen that is possible using the SD Card module but I only want like 2/3 file texts so having a whole SD Card for that sounds a bit overkill, is there any other way to store files like that?

Cheers!

  • How much data are we talking about? How is the sketch using the data? Read every startup, read on processing input, write on..., etc. – Mikael Patel Aug 19 '17 at 15:53
2

If you want files, then you need a filesystem. The only simple to use and reliable things on an Arduino that have a filesystem are SD cards or USB memory sticks through the USB Host Shield.

However, most of what people think they want to store in "text files" is actually data that can better be stored in other ways. Using text to store numeric values that only the Arduino will ever see is pointless - store it as numeric values.

The most convenient place to store such values (if you don't have lots of them) is in the internal EEPROM.

If you have more than a few values you can use an external EEPROM or serial Flash chip to store larger amounts of data.

Anything more than that, though, and SD card rapidly becomes the most cost effective method.

  • Thanks for the answer! Is it a read only memory or can it be changed multiple times? For example I just want to store things like settings and variables like time, but I need it to be able to be edited after, like changing the time when ever needed. – Matthew Aug 19 '17 at 11:39
  • @Matthew it is possible to read and write multiple times on the eeprom, but as far as I know there is a relatively low physical write cycles limit, i.e. you can change the value of a given bit only say 10.000 times. This is not a problem if you store settings, but you must avoid things like writing the eeprom in a frequently repeated loop. That said, it is quite simple to use it, I think there is even a dedicated library which comes with the Arduino IDE. – noearchimede Aug 19 '17 at 12:08
  • Microchip have invented what they call "EERAM" - an SRAM with EEPROM backup that saves its settings using energy stored in a capacitor when the power is lost. Infinite write cycles to the SRAM portion and EEPROM rated at 100,000 backups. Look for the 47C16. – Majenko Aug 19 '17 at 12:14
  • There's nothing that says you can't have a filesystem on a serial flash chip - or for that matter, there is no requirement that you use a filesystem with an SD card or a USB stick. If doing a lot of operations, the typical fact that one tends to be a fixed mapping of blocks and the other has a wear leveling algorithm does need to be considered, but at a simple level the same storage schemes can work. – Chris Stratton Aug 20 '17 at 2:35
  • @ChrisStratton Yes, I know. I have written block device drivers for flash chips, internal flash, SRAM chips, etc for chipKIT's implementation of sdfat. The biggest negative point to using an FS on a flash chip is that of wear levelling. You tend to get a disproportionate number of writes to a small number of blocks prematurely ageing the flash chip. An SD card is easy to swap when it dies, a flash chip isn't. – Majenko Aug 20 '17 at 8:45
1

Best way to store files on Arduino

what's best (or not) depends on your criteria, which you didn't articulate.

The simplest (and dumbest) way is to use a sd card. generally a waste of space and pins for small files.

the 2nd best is to use flash or eeprom: limited space and potentially risky. this can be partially addressed via out-board storage devices.

the best is to not store files on arduino: transmit the content away and let more capable devices to handle that.

  • Yes, using an ordinary PC as an aid to Arduino is an overlooked option. We always have some old laptop that can be used for a lot of things: 1) As a clock (via NTP); 2) As a logger or database (no SD needed); 3) As User Interface (no keypad, no screen needed); 4) as an email interface (send/receive emails to the world). All you need is a WiFi connection. – user31481 Aug 20 '17 at 10:22
1

The Arduino Uno uses the ATmega328P microcontroller. That microcontroller is able to write the EEPROM 100,000 times. As far as I know, that is 100,000 times per EEPROM location.

Suppose you want to run it for 10 years, then 10 years / 100k is about 1 hour. That means you can write to EEPROM every hour. Storing settings is no problem. There is even a EEPROM.update function that only writes the data when the data has changed.

If you want to store the latest settings every second, then you need to look for something else.

Important note: When storing settings (in EEPROM or SD memory card) the Arduino could be powered off while it is busy writing. Those settings will not be valid. Therefor you might have to add a checksum, store a copy of the settings, and keep default settings in the code in case both the settings and its copy are not valid.

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.