- Flash memory
- RAM (SRAM)
In this article we will discuss all of them giving some basic code sources too.
The flash memory is where arduino sketch is stored. It is non volatile memory. That means that the information persists after the power is turned off. The flash memory usually is bigger in size than the other two types. It can be written 10.000 times. The arduino bootloader is written there so you loose 2KB if you use the arduino bootloader.
The SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs. (The runtime memory)
This is a volatile memory and can be written unlimited times. When you declare a new run time variable this will be stored in SRAM.
The SRAM is relatively small memory (1024 bytes) and you have to use it with caution.
For example when you declare : char message = "Hello";
You are putting 5+1=6 bytes into SRAM on runtime (the one byte is the terminating null byte).
As you can see if you want to use constant long strings you can pretty easily reach the 1KB limit of your SRAM .
Using the PROGMEM command you can avoid this problem since you can store the constant string into flash memory instead of the SRAM. Unfortunately this trick cannot be done with variables since PROGMEM cannot modify the variables at run time. PROGMEM can not store non constant data.
EEPROM is a non volatile memory. This memory space can be used to store long-term information. It can be written 100.000 times
The eeprom is the smallest amount of ram offered by ATMega microcontrollers but it is extremelly useful when you need to store data. Consider the EEPROM as your hard disk. In order to use this kind of memory you have to use the EEPROM library.
Here are the amount of memories used by Arduino.
|FLASH (2 Kbyte used for bootloader)
More informations about arduino memories can be found at the official site.
In the next pages we will see three memory examples