Tutorial.Memory History

Hide minor edits - Show changes to output

November 23, 2013, at 08:58 AM by Scott Fitzgerald -
Changed line 5 from:
There are three pools of memory in the microcontroller used on current Arduino boards :
to:
There are three pools of memory in the microcontroller used on avr-based Arduino boards :
November 23, 2013, at 08:58 AM by Scott Fitzgerald -
Added lines 3-4:
''The notes on this page are for all boards except the Due, which has a different architecture''
October 21, 2013, at 01:17 PM by Roberto Guido - corrected typo on bytes occupied by string. Thanks Mike Stupak for report
Changed lines 29-30 from:
puts 32 bytes into SRAM (each character takes a byte). This might not seem like a lot, but it doesn't take long to get to 2048, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
to:
puts 33 bytes into SRAM (each character takes a byte, plus the '\0' terminator). This might not seem like a lot, but it doesn't take long to get to 2048, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
February 12, 2013, at 05:41 AM by Scott Fitzgerald -
Changed line 3 from:
There are three pools of memory in the microcontroller used on Arduino boards (ATmega168):
to:
There are three pools of memory in the microcontroller used on current Arduino boards :
Changed lines 10-11 from:
The ATmega168 chip has the following amounts of memory:
to:
The ATmega328 chip found on the Uno has the following amounts of memory:
Changed lines 13-15 from:
Flash 16k bytes (of which 2k is used for the bootloader)
SRAM 1024 bytes
EEPROM 512 bytes
to:
Flash 32k bytes (of which .5k is used for the bootloader)
SRAM 2k bytes
EEPROM 1k byte
Changed lines 18-19 from:
Notice that there's not much SRAM available. It's easy to use it all up by having lots of strings in your program. For example, a declaration like:
to:
The ATmega2560 in the Mega2560 has larger memory space :
[@
Flash 256k bytes (of which 8k is used for the bootloader)
SRAM 8k bytes
EEPROM 4k byte
@]

Notice that there's not much SRAM available in the Uno. It's easy to use it all up by having lots of strings in your program. For example, a declaration like:
Changed lines 29-30 from:
puts 32 bytes into SRAM (each character takes a byte). This might not seem like a lot, but it doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
to:
puts 32 bytes into SRAM (each character takes a byte). This might not seem like a lot, but it doesn't take long to get to 2048, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
March 08, 2008, at 04:37 AM by Paul Badger -
Changed lines 32-34 from:
To use the EEPROM, see the [[http://www.arduino.cc/en/Reference/EEPROM | EEPROM library]].
to:
To use the EEPROM, see the [[http://www.arduino.cc/en/Reference/EEPROM | EEPROM library]].

[[Foundations]]
March 08, 2008, at 04:36 AM by Paul Badger -
Changed lines 26-31 from:
* if your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.

* if you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an [[Reference/Int | int]] takes up two bytes, while a [[Reference/Byte | byte]] uses only one (but can store a smaller range of values)

* if you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the [[http://www.arduino.cc/en/Reference/PROGMEM | PROGMEM]] keyword
to:
* If your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.

* If you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an [[Reference/Int | int]] takes up two bytes, while a [[Reference/Byte | byte]] uses only one (but can store a smaller range of values).

* If you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the [[http://www.arduino.cc/en/Reference/PROGMEM | PROGMEM]] keyword.
March 08, 2008, at 04:35 AM by Paul Badger -
Changed lines 26-27 from:
* if your sketch talks to a program running on the computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino
to:
* if your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.
February 18, 2008, at 05:29 PM by David A. Mellis -
Changed lines 22-23 from:
puts 32 bytes into SRAM (each character takes a byte). It doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
to:
puts 32 bytes into SRAM (each character takes a byte). This might not seem like a lot, but it doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
February 18, 2008, at 05:28 PM by David A. Mellis -
Changed lines 18-19 from:
One thing you will notice in the chart above is that there is a lot more Flash (program) memory than SRAM available. When you create variables with the Arduino language such as:
to:
Notice that there's not much SRAM available. It's easy to use it all up by having lots of strings in your program. For example, a declaration like:
Changed lines 22-23 from:
You are putting 32 bytes (1 char = 1 byte) into SRAM. 32 bytes isn't a lot of memory in a pool of 1024 bytes, but if the sketch requires some large data structures - such as a large amount of text to send to a display, or a large lookup table, for example - using flash memory (program memory) for storage may be the only option. To do this, use the [[http://www.arduino.cc/en/Reference/PROGMEM | PROGMEM]] keyword.
to:
puts 32 bytes into SRAM (each character takes a byte). It doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.

If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely. To check if this is happening, you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). If it then runs successfully, you're probably running out of SRAM. There are a few things you can do to address this problem:

* if your sketch talks to a program running on the computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino

* if you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an [[Reference/Int | int]] takes up two bytes, while a [[Reference/Byte | byte]] uses only one (but can store a smaller range of values)

* if you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the [[http://www.arduino.cc/en/Reference/PROGMEM | PROGMEM]] keyword
February 14, 2008, at 05:35 AM by Paul Badger -
Changed line 3 from:
There are three pools of memory in the microcontrollers used on Arduino boards (e.g. the ATmega168):
to:
There are three pools of memory in the microcontroller used on Arduino boards (ATmega168):
February 14, 2008, at 04:13 AM by David A. Mellis -
Added lines 1-24:
!! Memory

There are three pools of memory in the microcontrollers used on Arduino boards (e.g. the ATmega168):
* Flash memory (program space), is where the Arduino sketch is stored.
* SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs.
* EEPROM is memory space that programmers can use to store long-term information.

Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). SRAM is volatile and will be lost when the power is cycled.

The ATmega168 chip has the following amounts of memory:

[@
Flash 16k bytes (of which 2k is used for the bootloader)
SRAM 1024 bytes
EEPROM 512 bytes
@]

One thing you will notice in the chart above is that there is a lot more Flash (program) memory than SRAM available. When you create variables with the Arduino language such as:

char message[] = "I support the Cape Wind project.";

You are putting 32 bytes (1 char = 1 byte) into SRAM. 32 bytes isn't a lot of memory in a pool of 1024 bytes, but if the sketch requires some large data structures - such as a large amount of text to send to a display, or a large lookup table, for example - using flash memory (program memory) for storage may be the only option. To do this, use the [[http://www.arduino.cc/en/Reference/PROGMEM | PROGMEM]] keyword.

To use the EEPROM, see the [[http://www.arduino.cc/en/Reference/EEPROM | EEPROM library]].

Share