In this first chapter, we are going to take a look at the microcontroller scene before the Arduino platform was presented. We'll see the changes it underwent that have made it a great success and that have led to it being widely adopted by hobbyists and technology lovers all around the world.
We will also meet some of the more popular Arduino models and compare their characteristics and features so that you can decide which model can be used in your next project.
The introduction, in 2005, of the Arduino platform brought a totally new panorama to the microcontroller scene of the moment.
By that time, working with microcontrollers implied to pay quite a big price just for the microcontroller-integrated circuit itself and all necessary components and circuitry needed to make it work, and even to pay a much bigger price for the development tools needed to program it.
These development tools were rarely made publicly available and in most cases, they were mostly based on proprietary languages or, in the best of cases, in the assembly language, none of which were especially easy to learn for nonadvanced users. On the other hand, the user support was normally restricted and limited only to the manufacturer's microcontroller.
The Arduino platform changed every one of these aspects.
To begin with, it is an open hardware platform that is not only limited to the microcontroller integrated circuit, but it also provides a full board with all the necessary elements to power it, make it work, and connect it to a computer at a fraction of the price of most other microcontrollers available in the market at the moment.
On the other hand, the development environment was made freely available from the first moment as an open source project, consisting of a very simple and intuitive editor with its integrated compiler, based on a subset of the standard, well-known, and documented C language, widely available for many other platforms and architectures. We could say that the Arduino Integrated Development Environment (IDE) is just C with a friendly wrapper around it.
Last but not least, the Arduino online community was born: it allows thousands of users to share their ideas, projects, and philosophy, which makes them all support each other.
The whole Arduino family, except Arduino Due, is based on 8-bit Atmel AVR microcontrollers, specifically those in the megaAVR series, ranging from the basic ATmega168 series used in the first Diecimila and Duemilanove models to the powerful ATmega2560 series of the latest Mega 2560 boards.
Apart from the ATmega series, the Arduino board incorporates every other electronic component necessary to make the microcontroller operate, including a crystal oscillator to set the working frequency that makes it run at up to 16 MHz.
Most models come with a USB port that enables you to connect the board directly to your computer so that you can program the microcontroller. The smaller models replace the USB connector with a direct RS-232 connection, which forces you to use a special USB-to-serial cable to connect the board to your computer.
Talking about powering, almost every model offers a power regulator that allows you to power the board directly from the USB port or through the jack connector, to power the board from an external power source such as a battery pack or a wall cube.
Finally, let's see a characteristic that also was an innovation when it was first introduced. The Arduino boards expose the microcontroller pins to the user through the use of two rows of female 0.1 inch headers, which makes it very convenient to connect the external components of your project, usually mounted on a breadboard, to your Arduino board with the simple use of jumper wires.
This distribution of external pin headers has made it possible to develop quite a bunch of different shields, which we will talk about later, that allow subassemblies to be easily connected to the main Arduino board.
A good number of models share the external footprint that has made the Arduino board so easily recognizable, including Arduino Diecimila, Duemilanove, Uno, Ethernet, and Yún.
For me as a programmer, one of the most important features is the fact that all members of the family share the same integrated development environment and language. This is the real common feature for all families.
Given the open hardware conception of the Arduino platform, the Arduino team has made publicly available the schematics, reference documentation, and even the EAGLE CAD files of all their boards.
For a full comparison of all Arduino boards' features and technical characteristics, you can visit the Arduino site at http://arduino.cc/en/Products.Compare.
A small footprint and a good pack of devices and available pins has made it the favorite board for beginners and advanced users who don't need great specifications to prototype and develop micro-controlled projects.
It is the most basic and cheapest model and is, in some way, the board that has made the Arduino platform what it is today.
It is based on the ATmega328 series, the descendant of the first ATmega168 series used in its older brothers, the Diecimila and the Duemilanove models. It works at a frequency of 16 MHz thanks to the use of a ceramic resonator, and offers a total of 32 KB of flash memory available to store your programs.
The Arduino Uno model exposes a total of 20 pins, 14 of which are digital input/output pins and 6 are analog inputs. Of the 14 digital pins, 6 can be used as analog output thanks to the included Pulse Width Modulation (PWM) mechanism, but we will talk in more detail about this in Chapter 4, Controlling Outputs Softly with Analog Outputs.
Some other peripherals offered by the board include serial and SPI communication ports, two external interrupts, an integrated LED (connected to pin 13), and an external Reset button.
The board comes with a type B USB connector that makes it very convenient to connect to your computer or even power it from any USB output, including your own PC or any wall cube designed to serve as a USB charger.
As mentioned in the preceding section, it also comes with a jack connector that allows it to be powered from an external power source, such as a battery or an AC/DC adapter.
In any case, an input voltage between 7V and 12V is recommended to power the board, even though 6V to 20V can be accepted.
For a more detailed specification of its characteristics and available peripherals, you can visit the Arduino site and take a look at its product page at http://arduino.cc/en/Main/ArduinoBoardUno.
It is the perfect board to get introduced to the Arduino platform—available through a lot of different providers, some of which could be really close to you—or through the new Arduino Store at http://store.arduino.cc. Its price is around $25, which is quite a cheap price for the brain of your next project.
Its footprint differs from that of Arduino Uno, making it a little longer than its little brother.
The Mega 2560 model is based on the super powerful ATmega2560 microcontroller, just like Arduino Uno, which works at a clock frequency of 16 MHz. However, unlike its little brother, it comes equipped with a vast number of peripherals.
One of the biggest advantages of the Mega 2560 model is the size of its flash memory, which goes up to 256 KB, equivalent to eight times the memory space offered by Arduino Uno, making the Arduino Mega 2560 model the target platform for those projects that need complex software to manage them.
On the other side, it has no less than 54 digital input/output pins, of which you can use 15 for analog output through the use of PWM and 16 analog input pins.
Related to its other characteristics, the Mega model comes with four serial communication ports, an SPI communication port, and a total of six different hardware interrupts.
Just like the Uno model, the Mega model implements one integrated LED and external Reset button.
When talking about powering the board, the Mega model can be powered just like the Uno model, that is, through the USB connector or through the external jack, supporting the same input voltage ranges as the Uno model (7V-12V recommended but 6V-20V accepted).
You can find its detailed specifications, schematics, and some more reference documentation about its product page on the Arduino site at http://arduino.cc/en/Main/ArduinoBoardMega2560.
This board is ideal for those who have to deal with projects that have wider requirements, in particular, those related to the number of input/output pins to interact with external devices and to the flash memory size needed to store the programs, allowing for much more complex programs than the Arduino Uno model.
On the lines of the Internet of Things, the Arduino team presented the Arduino Ethernet board, which included an Ethernet interface, making it able to develop projects that were connected to an Ethernet network or to the Internet itself.
The board is developed around the same ATmega328 microcontroller that is present in the Arduino Uno model, so the memory size and other characteristics are the same as in the Uno model.
The inclusion of the Ethernet module, however, forced some restrictions on the Arduino Ethernet model.
On one hand—and although the number of digital input/output pins is still 14 just like in the Uno board—some of them are reserved to interface with the Ethernet module, allowing only the use of nine of them for your project. On the other hand, the Arduino Ethernet board doesn't include a USB port. So, you have to use a dedicated six-male pin connector to upload your programs to the microcontroller through the use of a special USB-to-serial converter, usually known as an FTDI cable, due to the use of the FT232RQ chip around which the converter is normally built.
The Arduino Ethernet model comes with an integrated Micro SD card reader that allows you to store files and resources of a bigger size that are going to be served over the network. To get access to the SD card, the use of an external library is needed.
The full characteristics list of the Arduino Ethernet is on its product page on the Arduino site at http://arduino.cc/en/Main/ArduinoBoardEthernet.
Given that there is no USB port on the Arduino Ethernet board, the possibilities for powering the board are a little different. You can power your board through the external jack from an external power source by the use of the previously mentioned FTDI cable from a USB port or by the additional Power over Ethernet (PoE) module, which allows the board to draw current from the Ethernet connection itself, requiring your project to only be connected to the Ethernet network in order to start working.
The PoE module is not available as an add-on or as a shield, but it has to be ordered with your Arduino Ethernet board when you buy it. You can take a closer look at its product page in the Arduino Store at http://store.arduino.cc/product/A000061.
Apart from the previously mentioned Internet of Things, currently there is another line of product development called wearables, consisting of products you can wear as part of your clothing and that constantly interact with you and your environment as if they were an enhancement of your own body.
In this line of wearable technologies, the Arduino family incorporated a design by Leah Buechley, the LilyPad Arduino board, which is a little, round microcontroller device aimed at projects where it could be sewn to textile with conductive thread acting like normal wires.
The LilyPad Arduino board is a little subfamily of boards by itself with four different models and specifications:
LilyPad Arduino USB
LilyPad Arduino Simple
LilyPad Arduino SimpleSnap
All of them come with different microcontrollers, ranging from the ATmega168V series to the new Atmega32u4 series with flash memory sizes between 16 KB and 32 KB.
One thing to consider when choosing one of these models for your project is that none of them come with a serial communication port in case you need it.
The small dimension of the LilyPad Arduino board (approximately 50 mm in diameter) considerably reduces the number of pins and features it can offer. Only the LilyPad Arduino board has the same specifications as the Arduino Uno board with respect to the number of available pins, that is, 14 digital input/output pins with six PWM and six analog inputs. The rest of the LilyPad boards offer only nine digital input/output pins, of which four can be used as the analog output with PWM and four others that can be used as analog inputs.
In the case of the LilyPad subfamily, the available pins are not offered via a female header as is the case with other Arduino boards; in this case, they offer a number of silver-plated holes that allow you to sew the conductive thread to them. In the case of the LilyPad Arduino SimpleSnap board, the holes are replaced by snaps that easily allow you to connect and disconnect the external devices to and from the main Arduino board.
With respect to the connection to your computer, they also have to restrict the USB port and change it for a six-male pin header, having to connect the board to the computer through the FTDI cable mentioned previously. Only the LilyPad Arduino USB offers a micro USB port.
As a unique case, the LilyPad Arduino SimpleSnap board also incorporates a lithium polymer battery and all the circuitry required to charge it.
All of them can be hand washed except for the LilyPad Arduino SimpleSnap board, due to its battery, but in this case, disconnecting it from the textile should be easy, thanks to the integrated snaps.
You can find a complete list of features of every model on its own product page on the Arduino site at http://arduino.cc/en/Main/ArduinoBoardLilyPad for the LilyPad board, http://arduino.cc/en/Main/ArduinoBoardLilyPadUSB for the LilyPad USB board, http://arduino.cc/en/Main/ArduinoBoardLilyPadSimple for the LilyPad Simple board, and http://arduino.cc/en/Main/ArduinoLilyPadSimpleSnap for the LilyPad SimpleSnap board.
In definite terms, the small dimensions and reduced power consumption of this Arduino board make it ideal to develop wearable projects, where they can be directly integrated with clothes and are going to be running for long periods of time.
In this case, the board incorporates two different interconnected sections. On one hand, it has a usual Arduino board with its external pins and all the devices that we have already seen, but on the other hand, it is a totally operative Linux device with Ethernet and Wi-Fi support.
This way, you can build projects that benefit from both parts: the Arduino ease of use to interact with the real world and the power and connectivity options of a Linux device in which you can develop your own shell scripts or small programs with languages such as Python.
With respect to the Arduino side, it comes equipped with an ATmega32u4 board running at 16 MHz, exposing 20 digital input/output pins (seven of which can allow PWM to be used as analog outputs) and no less than 12 analog inputs.
On the Linux side, it runs on an Atheros AR9331 chip at a clock frequency of 400 MHz with an internal flash memory that acts as its main hard disk with a total size of 16 MB of which around 9 MB is dedicated to store OpenWrt, the Linux operating system inside the Yún. If you need more space to store resources needed by your projects, Arduino Yún is also equipped with a micro SD card slot that you can use as additional storage.
The whole device can be powered through a micro USB connector, but not having a voltage regulator makes it difficult, but not impossible, to power it from an external battery pack.
You can visit its product page so that you can get a full picture of this model board at http://arduino.cc/en/Main/ArduinoBoardYun.
Another very popular subfamily inside the bigger Arduino family is the one formed by the Arduino Micro, the Arduino Mini, and the Arduino Nano boards; the following screenshot follows the same order as the one mentioned:
These little boards, not much bigger than a postal stamp (approximately 2 inch by 0.75 inch), get, in most cases, very similar characteristics to that of their bigger brothers. They are just packaged in such a way that makes them ideal to connect directly to the breadboard or in projects where space is a must and the controller has to be small enough to be embedded in the general assembly.
To be more specific with its technical specifications, the Arduino Micro board comes with an ATmega32u4 microcontroller and both the Mini and Nano boards come with an ATmega328 chip; all of them run at a clock frequency of 16 MHz and come equipped with a flash memory of 32 KB to store your sketches.
With respect to the available pins, both the Mini and the Nano boards offer just the same number of pins as the Uno board but with two more analog inputs, making a total of eight. The Arduino Micro board goes even further with 20 digital input/output pins, seven of which can use PWM to act as analog outputs, and a total of 12 analog inputs.
Talking about how to power the boards, the Arduino Mini board simply doesn't have any facility, as it's your responsibility to provide a regulated power supply to allow the board to run. Both the Arduino Micro and Arduino Nano boards come with an integrated USB port with mini and micro USB connectors that you can use to power the board or even the final project from a typical USB phone charger.
Finally, except for the Mini board, the Micro and Nano boards come with a serial port that you can use to communicate your project with other serial capable devices.
They all share the same philosophy: to develop just the core of the microcontroller so that the size of the board can be reduced at a maximum, allowing for smaller boards suitable to be incorporated in your projects without using as much space as other bigger boards of the family.
If all the boards shown at the moment don't seem enough to you or you still haven't found the model that best suits the needs of your next project, don't worry. The Arduino team has also developed some other models with very different characteristics and orientations, but for the purpose of this book, they are all similar to the models already shown. They share the same general philosophy and, perhaps more importantly, can be programmed in just the same way with just the same tool.
In any case, we will just show them briefly without entering into too much detail and just revealing some of their more remarkable features and uses.
The Esplora board is the all-in-one board of the family. The main difference between this board and the rest of its brothers is that this board is not only a microcontroller board, but also a good selection of different sensors and input devices, such as a temperature sensor, accelerometer, microphone, or a joystick and some outputs, such as sound and light.
It is designed for those who have little or no previous electronic knowledge but want to start working with the Arduino platform from the very first moment.
The Esplora product page contains its full characteristics' list and information at http://arduino.cc/en/Main/ArduinoBoardEsplora.
Robotics is one of the disciplines that is constantly pushing forward and demanding for richer and more powerful advances in the microcontrollers arena, because as the microcontroller has more features, it is easier to build a robot with it.
As it is a very attractive discipline for kids and students, it is the perfect introduction to electronics and their microcontrollers.
This is why the Arduino team developed the Arduino Robot model, a fully featured, totally operable robot that shares the microcontroller it is based on with the other boards and, of course, the language it will be programmed in and the tool we will use to program it.
To be precise, the Arduino Robot model is really composed of two interconnected boards, a motor and a control board, each with its own microcontroller and dedicated to very different tasks.
You might be interested in taking a look at the Arduino Robot product page at http://arduino.cc/en/Main/Robot.
As discussed, Arduino Robot is a totally operative robot that you can program just the same way you do with your other Arduino boards by squeezing a little more off your budget.
The last board that I will show you is the Arduino Due board, which in some way, is the evolution of the Arduino Mega board but with an Atmel SAM3X8E ARM Cortex-M3 CPU, making it the only family member capable of 32-bit operation.
It runs at a clock frequency of 84 MHz and has an astonishing list of features among which the standout is its 512 KB of flash memory, 54 digital input/output pins, or four serial ports.
Another remarkable characteristic of the Due board is that it operates at 3.3V, being the only member of the family that operates at this voltage. From the point of view of powering the board, you shouldn't care because it comes with a voltage regulator that allows you to power the board from the USB port from an external battery or power source, but it can be a serious problem if you plan to use a shield designed for another member of the family that operates at 5V.
Given the open hardware nature of the Arduino project, there are now a lot of different boards. All of them are compatible with the original Arduino board, and some of them even extend the characteristics of its predecessor.
In some cases, they can even be found at just a fraction of the price of the original Arduino board, and, sadly, also at a fraction of the quality in other cases, so be especially careful when choosing your provider.
For a complete list of some of these Arduino clones, you can take a look at this list at Wikipedia: http://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems
There is a group of boards that, not being Arduino boards, are directly related to Arduino. They are called shields and are small add-ons that you can directly plug onto your Arduino board and that have all the necessary electronic components and circuitry to accomplish the mission they have been designed for.
There are hundreds of shields for Arduino out there. Just perform a simple search on Google and the number of results will amaze you: the results range from a GPS shield that allows our project to be location-aware to shields that link two Arduino boards via radiofrequency, passing by GSM/GPRS shields that make our project able to establish radio connections.
Furthermore, when most users finish the development of a project, they opt to create this shield to transfer the complementary components out of the breadboard.
The Arduino team has developed some official shields for Arduino, among which there is the Arduino GSM Shield that allows GPRS communications, the Arduino Wi-Fi shield that enables Wi-Fi connections, or the Arduino Motor shield that eases the operation of external motors.
Among the biggest shield developers are Adafruit (http://www.adafruit.com/category/17_21), SparkFun (https://www.sparkfun.com/categories/240?page=all), and Cooking Hacks (http://www.cooking-hacks.com/shop/™Arduino/shields).
I have already shown you all the significant Arduino models you might need to develop your project. As they are so different from each other, they all share a very important characteristic. They can all be programmed using the same language and the same tool.
This is a wonderful thing, because it allows you to program all models once you know how to program just one, making the selection of the board your unique concern.
In the next chapter, we will prepare our developing environments so that we can directly begin to program our boards and test our first assemblies.
On the Arduino site, you can find not only a traditional forum (http://forum.arduino.cc) where lots of users share their projects and troubles and help others, but also one of the sections I like the most: the Arduino Playground section.
The Arduino Playground section (http://playground.arduino.cc) is a section of the Arduino website where users publish information about ways to connect Arduino to other devices of all kinds, linking to their own websites in most cases filled with information about the project they have worked on. It is some kind of collaborative showroom.
For me, the Playground section is, perhaps, the most valuable site you can go to whenever you are beginning to work on your own project. There are plenty of possibilities that you can find in that piece of information that can serve you as a starting point.
In this chapter, we took a look at the microcontroller context before and after the introduction of the Arduino platform. We met some of the family members and we came to know about their most significant features so that you can decide which one of them best matches the requirements of the project that you are thinking about.
We also learned about the Arduino extensions, called shields, and saw some of the official shields developed by the Arduino team.
In the next chapter, we will download, install, and take a tour of the Arduino IDE, and we will finish by uploading our first sketch to our board, so roll up your sleeves as we begin to enjoy working with our favorite microcontroller.