FREE USA SHIPPING ON ORDERS OVER $100 On Dr.Duino.com

Is memory really that simple?

 

You've probably seen, when comparing different Arduino boards, a list similar to this:

What is all of that? It's certainly overwhelming for anyone new to the scene. 

So let's take it real slow. 

Memory. 

There's really just two types of memory to consider. 

Volatile and Non-Volatile.

 No, no, not like whether it's explosive or not, but whether or not it sticks around after losing power. 

You see, Non-Volatile memory sticks around after power is removed.  It's any type of memory that, well, remembers what it had.

Volatile memory is only good for as long as power is supplied to it.  Once that power is gone...WHOOPS...so is what it had, sort of like remembering if you turned off the coffee pot this morning...wait, did I?

Under these two types of memory there are quite a few different names. 

We'll start with RAM, and first off you cannot download more RAM despite what that teenager or person on the other line is trying to tell you. 


RAM, or Random Access Memory, and of course there are then two types of RAM:

SRAM and DRAM

Regardless of which we are talking about, static RAM or dynamic RAM, they all have the same basic anatomy. 

You see each one of those chips is a memory module.  A row of these chips becomes a "page" and a group of pages becomes a "bank". 

The cool thing is that within these "banks" are thousands and thousands of tiny momentary switches.  These switches can be either on or off, that is, their state is either on or off, a 1 or a 0. 

Hopefully, it makes sense how RAM memory is Volatile.  If there's no power to "maintain" the switch as it is in its current state then it defaults to being off, thus erasing whatever was stored there.

In an Arduino, SRAM, or static RAM, is where three main data interactions occur.  I don't want to dive too far into them because that's for another post, but we have:

  • Static data - all of the global and static variables that you create get copied to here when the program first starts, think about your Setup() routine and all of the declarations before it.
  • The Heap - I know a funny name, but it's for holding all of the dynamically changing values and allocated data
  • The Stack - this holds all of the local variables, it keeps a record of any interrupts and function calls.

Normally, whenever you have memory problems it's because the heap and stack "collide", or data from one gets written over the other.  Again, I'll save those details for another post because it can get pretty tricky.

Now let's move on to the other type, non-volatile, or persistent memory - memory that stays even after losing power.

In the case of the Arduino, this type of memory is called flash, or PROGMEM, and it's essentially your program memory.  This is where your actual compiled program gets stored and the only way to change it is by re-uploading new compiled code to your board.

Another term for this type of memory is ROM, or read-only memory

I think that's a bit of a misnomer because whenever you upload to the board you are actually writing to it so it's technically not read-only. 

Perhaps than, a better name would be read-only (under most situations) memory, because after the initial write your programs aren't going to, and shouldn't, be changing it.

 Flash memory is really cool because their switches don't need to have external power to hold them in one state or the other.  The science is actually quite in depth and beyond the scope for a blog post, but just know that once you've set the "switch" it stays in that state until you decide to change it.

 

Lastly, we come to EEPROM, or electrically erasable programmable read only memory. 

Whew! That's a mouthful. 

This memory is really slow and it can only be read byte to byte, but it's super useful because you can use the Arduino to make changes to it while your program is running and the data that's stored will persist through a power cycle!

How could that be useful?  Well, what if you need to know the last state or function that your program ran right before the power went out?  Or what if you need it to pick up where it left off?  EEPROM is great for that!

So how do you know how much you should have? 

Well, you must consider what you are going to be doing.  If you plan on chaining together tons of addressable LEDs and using displays, those items are memory gobblers and will quickly eat up tons of SRAM.

If you have tons of functions and hundreds of different variables then you'll want to make sure you have the largest Flash available to store the program you are writing. 

All of this type of memory is used inside of typical Microcontrollers, you know... the ones which are inside of our beloved Arduino and ESP32 boards.

Thankfully, you don't have to worry to much about them, as when you write your code, its all handled for you (depending on what you are doing).

For example, lets say you wan to build your own RGB controller, meaning you can control the color or a Red led, a Green LED and a Blue LED.

Now lets say you want to permanently store those colors that you dial in from an external source, like say a potentiometer.

Well for that you would use EEPROM, dial in what ever value you want from your potentiometers and then simply push them into EEPROM.

Even after power is cycled, you could retrieve those values, and immediately turn on your RGB led to make one of over 16 million different color combinations.

Cool right?

Well, if you want to build that very project, I invite you to check out the Dr.Duino Explorer and Pioneer Editions as that just one of the awesome projects which you'll get to build.

Click the links below to check out both platforms now!

If you have some electronics experience the Dr.Duino Explorer is the choice for you. Just click the photo below to find out more about.

If you're new to Arduino and electronics, then the Dr.Duino Pioneer version is the best choice. Click the photo below to learn more.

 

Which one will you choose, click here to learn more about the Explorer or here to learn about the Pioneer