- Get to know the basic Arduino boards and their features.
- Understand what a PIC is.
- Show the different kind of available memories.
- Learn to use the internal EEPROM without fear.
BILL OF MATERIALS
|Patience and 20 minutes to spare.|
ON ARDUINO BOARDS AND THEIR FEATURES
It’s time we start talking about the different Arduino boards available and which are its differences. But to understand them properly, we need also to know the different processors and what differentiates them, their kind of memories, type and capacity.
And since this is a course designed to start from scratch, it is time to make a small summary of processors and memories, their differences and their purposes. Get comfortable.
Doing a bit of history (little, keep calm), the first entitled micro processor was the Intel 8080 back in the late 70s.
It was the first chip that integrated everything needed to build a central processing unit (or CPU), on a single chip, and upon it the first personal computers were built just adding more memory and input/output devices).
Not to be boring, I would say simply that this model based on CPU, memory and I/O (Input Output) has remained in force until today, in what is nowadays known as PCs.
Numbers have grown exponentially, of course, but the conceptual model remains the same, from 8080 to modern Intel I7.
|Model||IBM PC 1981||Intel I7||Multiplier|
|Clock speed||8.8 MHz||2.4 GHz||x300|
|RAM memory||128 kB – 640 kB||4 Gb – 64 Gb||x2.000|
|Hard Disk Drive (HDD)||500 kB||4 Tb||x2.000.000|
Processors have had a period of infinite expansion, but still have the same problems as the first day:
- It has no connection or influence on the physical world. Can you imagine turning on some LEDs, or move a motor using your PC? It is not impossible, but we would not know where to start.
- We can save data to increasingly huge hard disk drives, but programs must be run from RAM, and this has been a bottleneck, especially with modern operating systems like Windows or OSX which devour eagerly as much memory as is installed.
- If the power supply stops working, the data stored in the RAM vanish and go straight to the wastepipe, if you have not had the foresight to save it to disk periodically.
- Modern microprocessors are designed to be extremely fast making complex calculations, and have reached such a processing power that they have exceeded long ago what a normal user needs to do, although it has taken them a few years to realize.
Meanwhile and in parallel, small manufacturers, who are hardly known by the public, have been building less ambitious small processors, but more aimed at solving a type of problems that Intel, AMD and some other ignored. (I consciously avoid to discuss the issue of mobile phone processors, because it would open a door out of what concerns us now)
This is what has been called physical computing, in which the result of the calculation is not only a numerical result, but a physical operation that moves to the real world.
One of these manufacturers is ATMEL, and our Arduinos are built from one of its processors: the ATMEGA328 for Arduino UNO, which is sold in two kinds of encapsulations: DIP (Dual in-line package) and SMD (surface-mount device).
You can find Arduino ONE boards with both kinds of encapsulations and their only difference is the plastic part that covers them, although the first type is usually mounted in a socket, so that it can be replaced when you do something you should not.
- In a future session we will assemble an Arduino on a breadboard, so you can see how easy it is.
Its technical specifications are modest at first, if you compare them with the latest Intel processors:
- An 8 bit processor.
- A 16 MHz clock.
- 32k FLASH memory.
- 2 Kb SRAM
- 1 Kb EEPROM
Now you can understand why we have to talk about the types of memory.
But they incorporate digital pins that can receive and send commands to the outside world (something to which the followers of these chapers are already quite used to) in addition to analog to digital converters (ADC).
Is the mixture of these features which give processors like our Arduino (which incidentally are called PICs, Peripheral Interface Controller ), the capability they show. Are complete computers with processor, memory and input and output capabilities. They are not too powerful but they can do peripheral work, for which the great stars of Intel or AMD have no resources.
Right away we will talk about the different processors of our Arduino boards, but first we have to talk about memory.
TYPES OF COMPUTER’S MEMORIES
We can think that computer’s memory is like a row of boxes or drawers, all the same size and numbered from 0 to n, where n is the size of your RAM. When you turn on the computer, the CPU wakes up and goes to the drawer 0 in order to see what instruction is there and execute it. After the duty is fulfilled it jumps to the next drawer, 1, reads the instruction and executes it, then jump to the drawer 2 and so on, and so on…
The first instructions you have in the drawer 0, are called the boot strap (which is something like the starter handle of an outboard motor). In our case these are the instructions that teach how to interpret the Arduino model in order to download our sketches to the board. When it finishes, the boot strap leads the execution directly to our instructions as computers execute orders in sequence, because they simply do not know to do it otherwise, unless we command them to jump to other drawers depending on given conditions.
The first computers had only two types of memory: RAM and ROM, but you know that things tend to chaos and all have been complicating since then.
All that we run on our PCs must be stored in RAM or Random Access Memory. They can be read and written but have the bad habit of disappearing when the power is removed.
When you boot your PC, it knows how to do some things, like reading the boot strap. Therefore the boot strap can’t be stored in RAM memory (otherwise it would be lost when power off) but in ROM memory.
The ROM memories (Read Only Memories), as the name suggests, are read-only and can be only written by the manufacturer when they are built.
Traditionally a wise combination of RAM and ROM enabled the development of all kind of microcomputers, but soon diversity began:
|RAM||They can be read and written but they are volatile, that is, data is lost when power is turn off.|
|DRAM||Dynamic Random Access Memory. This is the typical computer memory type. They are built based on capacitors and can integrate huge amounts of them in a single chip cheaply. However they must be refreshed every bit, which complicates the design by using techniques to refresh memory (Of course out of the eyes of the proud owner).|
|SDRAM||Synchronous Dynamic Random Access Memory. They are also DRAM memories but use synchronous refreshing techniques.|
|DDR||Double Data Rate Synchronous Dynamic Random Access Memory. Nowadays this kind of memory is used in the desktop computers. The latest is versión DDR5.|
|ROM||Read Only Memory. They are not volatile, but they can only be used to read not to write.|
|PROM||Programmable Read Only Memory. They are not volatile and we can write and rewrite them using special equipment. They have almost fallen into disuse nowadays.|
|EEPROM||Electrically Erasable Programmable Read only Memory. They are like PROMs, but with curiosity that can be rewritten electrically which avoids the hassle of carrying them to reprogram in strange machines. However they are slow to write and have a limited number of writes before its death.|
|FLASH||It is a derivative of the EEPROM, with several advantages, the main thing is that no information is lost when power is turned off and they can also be read and written on the go. The drawback is that they are slow. It’s the kind of memory that is used to make the pen drives and other USB memories.|
After this salad of acronyms, we can return to the Arduino boards and their features.
You must know that our programs are written to the flash memory (which is quite slow when writing), but the variables that define our program are stored in SRAM memory (which is much faster to write)
So our familiar Arduino UNO, is going to fall short soon because it has very little memory. As you begin to include libraries in your programs the amount of available flash memory will be reduced dangerously and in the meantime, the amount of SRAM dedicated to handle variables can be filled easily, provided that you don’t control the sizes of these variables or of the arrays that you can build.
In fact, perhaps you have not realized that each time you compile and download your Arduino sketch, the IDE reports on the available and used memory, of one kind or another:
So, as your programs and projects grow, is interesting that you have in reserve an Arduino Mega, just in case. That, of course, is the next Arduino that you must consider adding to your collection.
Why a Mega and not a DUE?
DUE is a very sexy beast of burden, but as disadvantage it operates at 3.3 V, what leaves it in a sort of no man’s land, being not easy to recommend it without knowing exactly what for will it be used, otherwise you can have more disadvantages than advantages.
If you need computing power to process audio, make Fourier transformations (FFT) or digital filters, where what prevails is the power and speed, DUE is your candidate, without any doubt.
But if you want to use a shield (we will talk about them) or hook it with TTL integrated circuits and the like, the 3 volt level of the DUE pins are going to make your life complicated immediately. If you want an improved Arduino UNO for everything that you can need, get the Mega (which is also much cheaper than a DUE) and you’ll be delighted.
In addition to the evolution of prices downwards, you will probably end up buying one of each.
There are more Arduino boards out there:
There are more boards on the way, but so far we won’t complicate matters still further.
USING ARDUINO’S EEPROM
I do not want to miss this chance to talk about the Arduino internal EEPROM.
Why does Arduino have an EEPROM? Because although the program is stored in FLASH memory and therefore is not lost when is powered off, it does not happen with the variables that are stored in SDRAM, so their values are lost every time we power off.
So there are times in which it is interesting to preserve user settings, without having to ask the same thing every time you restart.
Imagine a digital clock always asking users if they prefer 12 or 24 hour format or the time to set the alarm.
Let’s write a small program that shows how to store values in the EEPROM, so that we can recover them even if the power goes out.
To write in the EEPROM, we have to include the appropriate library:
#include <EEPROM.h> for (int i = 0; i < 255; i++) EEPROM.write(i, i);
And to read the EEPROM:
#include <EEPROM.h> value = EEPROM.read(pos);
Where pos is the EEPROM position where we want to write. For an Arduino UNO pos can reach up to 1024, which is the length of EEPROM available. For an Arduino Mega it can reach up to 4 kb = 4096.
And little more can be said on this matter. It is a kind of sequential mini hard disk drive, available within your Arduino, and it is good to know that you can use when needed.
- This EEPROM memory degrades with use and just becomes unusable, as everything in life, so it is worth reviewing the manufacturer’s documentation (yes, the damn manual must always be read) which says that it accepts 100.000 rewrites before degrade.
- So if you store four data daily, It will spoil after, let’s see, (100.000/4)/365 = just over 68 years, so you know, be very careful when writing the EEPROM not to waste it.
- There seems to be an absurd fear of using the EEPROM inside the Arduino community. I recommend you writing it without fear. There are many positions and if one spoils, you can always use the other positions. The Arduino UNO has 1024 different positions.
- We have talked a little about the different types of memories and their purposes.
- We have seen the features of different processors on which the different Arduino boards are built.
- We have introduced the different kinds of Arduino boards.