Storing Data on the Arduino

From Learning

Jump to: navigation, search

Microcontrollers like the Arduino have three different kinds of memory space:

  • Flash - where the program is stored (doesn't erase even when the power is off)
  • SRAM - where the program's variables are stored and accessed (erases when the power is off)
  • EEPROM - where programmers can store long-term information (doesn't erase even when the power is off)

If the SRAM becomes full, your program won't work properly, so you can store information in the EEPROM to free up space in the SRAM. To do so, you need to import the correct header file.

#include <avr/pgmspace.h>

To store data in the EEPROM, use the PROGMEM keyword and the EEPROM data types (found here).

dataType variableName[] PROGMEM = {};

To store an 8 sample wavetable:

prog_uchar PROGMEM wavetable[8] = {128,131,134,137,140,143,146,149};

See Also

Arduino Memory Tutorial

Arduino Playground Types of Memory

Arduino PROGMEM Reference

  • This page was last modified on 10 December 2011, at 09:19.
  • This page has been accessed 7,106 times.