What is Arduino Nano, Arduino Shield IDE

What is Arduino Nano, Arduino Shield IDE

What is the Arduino nano, Arduino shield, and Arduino IDE 

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.

 

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. In this blog, we explain the complete Arduino family and also explain What is Arduino nano, Arduino shield, and Arduino IDE 

What is Arduino Nano, Arduino Shield

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.Let's now take a closer look at the most popular board models and their specific features and configurations.

 

Arduino Uno

 Arduino Nano, Arduino Shield and Arduino IDE

The Arduino Uno model is the evolution of the first Arduino board through the Arduino Diecimila and Duemilanove models.

 

A small footprint and a good pack of devices and available pins have 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. 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.

 

Arduino Mega 2560

Mega 2560

Traditionally, the Arduino Mega 2560 model has been the offer the Arduino team made for those who need a more powerful board with a wider number of pins than Diecimila or Duemilanove. 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.

 

Arduino Ethernet

ethernet

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.

 

LilyPad Arduino

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
  • 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.

 

They all are able to work under low voltages to reduce power consumption, and that is why they all work at a clock frequency of 8 MHz, which is half the frequency of its bigger brothers. 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-mile 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, Indefinite 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.

 

Arduino Yún

Arduino_yun

One of the latest incorporations to the family has been the Arduino Yún board, bringing a slightly different approach to the concept of the Internet of Things. 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. Taking a more detailed look at the technical specifications of this new board, we can realize the power we get to develop real Internet of Things projects.

 

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 storing 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.

 

The Arduino Yún board is, no doubt, a perfect device to develop not only physical projects but also to connect them to the network.

 

Arduino Mini, Micro, and Nano

Micro

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 inches by 0.75 inches), 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.

 

Other Arduino family members

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 blog, 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.

 

Esplora

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.

 

Arduino Robot

robot

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.

 

Among others, it is equipped with LCD, compass, speaker, a bunch of LEDs, five buttons in the control board, IR sensors, motor drivers, motors, and wheels in the motor board. 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 of your budget.

 

Arduino Due

arduino_due

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.

 

Arduino Due Unofficial boards

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

 

Shields

shields

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.

 

Some official Arduino shields

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. 

 

The Arduino platform has grown so much that today, there is a whole market around it, with providers developing shields for unimaginable purposes.

 

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).Just one to rule them all

 

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 blog, we will prepare our developing environments so that we can directly begin to program our boards and test our first assemblies.

 

Users teaching users

I told you previously that Arduino was not just a board and a compiler. One of the things that I personally think has made Arduino become such a big platform is its online community.

 

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.

 

The Arduino Development Environment

arduino_ide

In this blog, I'll show you how to get up and running with the Arduino development environment. We will download and install it, and we will take a tour of all its menus and commands. We will finish by uploading the first sketch to your board so that you can confirm that all that is needed to begin is working correctly.

 

A multiplatform tool

One of the things I like the most about the Arduino software is that it is truly multiplatform, which means that it is exactly the same environment whether you run it under OS X, Windows, or Linux. You could find some differences in the installation process of every operating system and differences to get it up and running, but once you have it up and running, it is just the same in any platform. So, let's go ahead and present to you the whole process to make it run under the operating system of your choice.

 

Downloading the package

The first thing you have to do is go to the Arduino site's download section at http://Arduino.cc/en/Main/Software and choose the right package for your operating system and the software branch that best suits your board.

 

At the time of writing this, there are two different branches. I'll recommend that you use the Arduino 1.0.X stable branch unless you are going to work with Arduino Yún or Due; in that case, you'll have to choose the 1.5.X branch that, at the time of writing this, is a beta version and, therefore, could be a little unstable or could lead to some errors.

 

However, I have to say that I have been working for more than a year with the 1.5.X branch to program both Arduino Uno and Arduino Yún, and I haven't seen any bugs.On the Arduino site, you will find precompiled packages for Mac OS X, Windows, and Linux and even a source code package. Let's take a closer look at each of the supported operating systems.

 

Windows

For Windows, there are two different precompiled packages: one prepared for the Windows Installer and another that consists only of a ZIP package that you have to uncompress by yourself.

 

The Windows Installer option is recommended in order to allow multiple users in your computer to access the software, but you need administrator privileges to install it system-wide.If you don't have an administrative account, you can download the ZIP compressed package and simply uncompress it in any folder where you have permission to do so, such as your own desktop.

 

Mac OS X

For Mac OS X, there is little to consider. There is just one package so that you have nothing to choose from. Just download your package and go to the next section to see how to install it.

 

Linux

For Linux, the only consideration to have in mind is the architecture of your computer so that you have to choose between the 32- and 64-bit precompiled packages. In both cases, the package provided in the Arduino site consists only of a compressed TGZ file that you have to uncompress by yourself.

 

Source code

If you use a different operating system, there is even a source code package that allows you to compile the Arduino development environment on your own.

 

Installing the software

We have seen the downloading considerations for every operating system; let's now go on to see how to install the package for each of them.

 

Windows

Under Windows, using the Windows Installer package is quite simple and doesn't require any special consideration. If you opted for the compressed package, you have to only uncompress it with an archive uncompressor such as WinZIP to make it available, which is not too hard.

 

Mac OS X

Under Mac OS X, the installation of the application consists only of dragging the application icon to the Applications folder of your computer. Simple. In the latest versions of Mac OS X, Java may not be preinstalled; if this is the case, you should go to the Java official website at http://www.java.com/en/download/ and download it.

 

Linux

Given the diversity of different distributions and the packages' dependencies system on which Linux relies, you should install some of them before you can run the Arduino development environment.

 

Thanks to the package management systems based on centralized repositories present in most Linux distributions nowadays, it is even possible to install the Arduino development environment directly from a repository along with all the needed dependencies using just a command.

 

It makes this the preferred way of installation if the available version in the repository is up to date. In Debian-based distributions, the Arduino development environment could be installed as easily as running the following command: apt-get install Arduino

In case of trouble

 

In case you encounter any problem during the installation process, you could go to the Arduino site and take a look at your corresponding operating system's Getting Started guide for more detailed step-by-step instructions at http://Arduino.cc/ en/Guide/HomePage.

 

Installing the drivers

As it is a USB device, the Arduino board might need its own drivers to be installed before your computer can talk to it.

The most recent boards, such as the Arduino Uno or the Arduino Mega 2560 board, don't need any special drivers to be installed. If you are using an older model, such as the Diecimilia board or any other board with an FTDI driver chip like the one shown in the following screenshot, you will have to install the specific drivers:

 

FTDI Chip

You can download the driver's version for your operating system right from the FTDI manufacturer page at http://www.ftdichip.com/Drivers/VCP.htm.

We will provide brief instructions on how to install these drivers for the operating system of your choice.

 

Windows

Under Windows, the installation may be a little tricky due to the fact that Windows will do its best to recognize the board and locate appropriate drivers for it, failing most of the times in doing so. To get the drivers up and running, perform the following steps:

 

1. You'll have to go to Control Panel and locate Device Manager.

 

2. Once you're there, look for a device with an exclamation sign, usually under the Ports section (also, take a look at the Other Devices section if you don't find it under Ports).

 

3. Once you have found it, right-click on it, select the Update Driver Software… option, and navigate to the folder on your hard disk where you uncompressed the FTDI drivers you downloaded from the previously mentioned URL of the FTDI site.

 

If you still can't get it correctly installed, take a look at the Getting Started with Arduino on Windows section on the Arduino site at http://Arduino.cc/en/ Guide/Windows.

 

If you are running Windows XP, there is even a step-by-step guide with screenshots of every step on how to install the Arduino Uno driver under this operating system at http://Arduino.cc/en/Guide/UnoDriversWindowsXP.

 

Mac OS X

As stated previously, the drivers' installation is only needed if you are using an old board, such as the Diecimila or Duemilanove board. In this case, you'll have to download them from the previously mentioned URL, double-click on the uncompressed package installer to install it, and reboot your computer after the installation.

 

Linux

The Linux kernel supports the FTDI drivers without the need to install any additional software, but if you are experiencing any trouble, you can take a look at the Installing Arduino on Linux section of the Arduino Playground tab at http://playground.Arduino.cc/Learning/Linux, where you can find more detailed information specific to the more common Linux distributions nowadays and, in particular, to the libraries and other' requirements your installation should meet.

 

Running the Arduino development environment for the first time Well, it may have seemed more complicated than it really was, but finally, you have your programming environment ready to work. It's time to create our first test, take a tour of it, and meet all its parts and structures.

 

On the first run, the Arduino development environment should look like this:

Basically, it's divided into three sections:

  • The toolbar at the top with buttons for the more usual commands
  • The code editor in the middle, where you will write your sketch, as we commonly call an Arduino program's code
  • The message area at the bottom, where you will get information about the status of your sketch and possible location of errors in it
  • Let's take a closer look at each one of these zones so that you can begin to use them.

 

The toolbar

In the toolbar, you're going to find a total of six buttons to call the more usual commands of the development environment.

 

Buttons on the toolbar

From the left-hand side to the right-hand side, they are as follows:

  • Verify: This button is used to verify the syntax in your code and compile it if no errors are found.
  • Upload: You can click on this button to upload the resulting machine code to the Arduino microcontroller. It will compile the code if it has not been compiled previously.
  • New: This opens a new blank sketch.
  • Open…: This loads a previously saved sketch from the disk through the use of a pop-up menu.
  • Save: This saves the currently edited sketch to the disk.

 

Serial Monitor: This opens the Serial Monitor window that allows you to visualize the interchange of data in a serial communication between your computer and the Arduino board

 

The code editor

The code editor is the zone where most of your work will happen and where you will spend most of your time.

 

It is a multitab editor, which means that you can open more than one document at the same time on different tabs. You can find a small downward-pointing arrow icon on the right-hand side of the tabs area that unfolds a menu with different tab-related options, such as New and Rename, or helps you move along the currently opened tabs.

 

It is not a very powerful editor but has all the features that one can hope to find in a modern code editor nowadays, such as syntax highlighting, which means that the different parts and words of your code are going to be presented in different colors that will help you classify the different elements in it, making it clear what a reserved word, a variable, or a constant is.

 

Another feature I really appreciate and that makes your work much more comfortable is the highlighting of parentheses and bracket pairs when you put the cursor over one of them so that you can easily view the opening/closing pair of such constructions.

 

The code editor showing syntax highlighting and the pop-up menu

These features apart, there are some other useful commands, such as Search in Reference, that take the word under the cursor and look for it in the Arduino Language Reference section on the Arduino website, showing you the help page of the reserved word or function.

 

There are other stylistic commands, such as Increase Indent, Decrease Indent, and Comment/Uncomment, which are available through the pop-up menu that is shown when you right-click on the editor area.

 

The message area

The message area is the zone where the Arduino development environment will tell you which errors it has found when trying to compile your code or any other issues it has found when trying to accomplish the command you asked. for example, a communication error when uploading the machine code to the microcontroller board.

 

The message area showing a syntax error and line highlighted in the code editor When the error is related to a line in your code, this will also be highlighted in the code editor.

 

The Arduino development environment will try its best to reference in the message area the line number where it thinks the error is. I say thinks, because the mistake is not always correctly located and, in some cases, it can be one or two lines before the line the message area is reporting. This is a typical situation when programming in C, but we will talk about it later on.

 

Preflight checks

In order to upload your first sketch to the Arduino board, you have to first make sure that the Arduino development environment knows two very important things about your board:

  • The type of Arduino board you have
  • The serial port through which it is connected to your computer

 

Both parameters have to be specified using the Tools menu in the menu bar and by selecting the Board and Serial Port commands.

In the next screenshot, you can see all the available options when selecting the board type. All board models available through the Board command in the Tools menu

 

Being a teacher myself and having worked with Arduino boards with my students for some years, I have found that the most common mistake they make the first time they try to upload their first sketch to the Arduino board is the wrong selection of the serial port. If you are like them and don't know for certain which one of the available serial ports in the Serial Port command to select, don't worry. In the worst case, it's just a matter of trying them all.

 

When the Arduino development environment can't communicate with your board due to an incorrect serial port specification, it will show you a message similar to the one you can see here. A typical message is shown when an incorrect serial port is selected

 

Uploading our first sketch

Once you know how to connect the board to your computer and how to let the Arduino development environment know about it, the moment has come to create our first real test.

 

We will upload the simplest sketch to the Arduino board just to confirm that all parts are correctly set up and that you can, for sure, begin to work with it and learn how to program it.

 

What we will do is load one of the examples that come with the Arduino development environment, in particular, one called Blink that makes use of the onboard integrated LED to make it do just that—blink. To do this, go to the File menu in the menu bar and select the Examples command, navigate to 01. Basics, and select Blink. The Arduino development environment should open a new window containing the following code for that example:

 

/* Blink Turns on an LED for one second, then off for one second, repeatedly. This example code is in the public domain. */

// Pin 13 has an LED connected on most Arduino boards.


// give it a name: int led = 13;

// the setup routine runs once when you press reset: void setup() {

// initialize the digital pin as an output. pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever: void loop() {

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the

voltage LOW

delay(1000); // wait for a second

}

 

We will go on with more details about the programming language and its characteristics in the coming blogs, but at the moment you just need to know that, it simply configures the Arduino board to use the onboard LED as an output in the setup function and turns it on and off infinitely, with a little delay in between, in the loop function, that is, blink an LED.

 

Once you have loaded your sketch, you only have to click on the Upload button on the toolbar (the one with the rightward-pointing arrow), which will cause the Arduino development environment to first compile the sketch if it wasn't already compiled and, if it finds no errors, it will upload it to the selected board through the specified serial port.

 

During the uploading process, you can see two other integrated LEDs labeled as TX/RX blinking, indicating that the serial communication has been established and that the Arduino board is receiving data from the computer and sending back an acknowledgment to it.

 

As soon as the uploading process has finished, the Arduino board will immediately begin to run the sketch and as a result, you should see the LED labeled L begin to blink at a 1 Hz frequency.

 

Congratulations, you have completed your first development cycle: edit the sketch (load it from the disk, in this case), compile it, upload it to the board, and run it there.

 

If that wasn't enough for you, perhaps you could try to simply change the two values in the delay functions from 1000 to, say, 300 and 500 and re-upload it to the board to watch how the blinking frequency changes.

 

Main menus and commands

Before going on to the next blog where we begin to deal with all the features present in the Arduino board, let's take a little tour of the Arduino development environment menus and commands. It has only five menus, and some of them are very similar to those present on any other application in your computers, such as File, Edit, or Help.

 

In the File menu, you will find commands to open a new sketch, load it from the disk, save it, or print it. Just as an addition, you can see two commands: Sketch book and Examples.

 

The Sketchbook submenu will unfold another submenu listing all sketches available in the folder you can designate in the Arduino development environment preferences as sketchbook folder. This makes it very easy to load your own sketches without the hassle of having to navigate through your entire filesystem folder structure to find the particular sketch you are looking for. The only drawback of this is that you have to store your sketches in the specified folder.

 

On the other hand, the Examples command will do something similar by showing all examples that come with the environment, which is very convenient when learning to program.

 

In the Edit menu, you'll find options such as Undo, Redo, Copy, Cut, and Paste as with every other application in your computer, but you'll also find commands such as Copy as HTML to publish the code in a web page or Copy for forum to prepare the code in a convenient way to be published in the Arduino Forum.

 

There are also commands to embellish and tidy up your code, such as the previously mentioned Increase Indent / Decrease Indent and Comment/Uncomment commands, and, of course, commands to find, and to find and replace, like in most editors.

 

The Sketch menu has just four commands:

Verify / Compile: This is just the same as the Verify button in the toolbar.

Show Sketch Folder: This opens the folder in your disk that stores the sketch being currently edited.

 

Add File…: This allows you to include one more file in the current sketch, allowing you to make your code modular by dividing it into different files.

 

Import Library…: This shows you another submenu listing all available libraries in the libraries folder inside the designated sketchbook folder of your hard disk. We will talk in more detail about libraries in other blogs of the blog.

 

In addition to the previously mentioned Board and Serial Port commands, the Tools menu has commands to format your code for better viewing or to create a ZIP package of your sketch to make it easier to send it via e-mail. The Serial Monitor command is just the same as its corresponding button on the toolbar and opens the Serial Monitor window to allow us to communicate serially with the board and see what the board is sending us back.

 

The Serial Monitor window

The Programmer and Burn Bootloader options are for advanced users who want to reprogram their Arduino boards' bootloader (a sort of operating system that makes the Arduino board run). Finally, the Help menu contains commands to show different sections and views of the Arduino documentation.

 

The Arduino language

As you may have noticed, the code you write for your Arduino sketches is very similar to the C programming language. It is, in fact, a subset of it, which makes it very convenient to use, given that the C programming language is almost a de facto standard in most platforms and devices. Traditionally, the C programming language has been portrayed as not being very user-friendly, but I prefer to refer to it as being friend-selective.

 

One of the missions of this blog is to introduce you to the C programming language so that if you don't have any previous knowledge of it, you can take your first steps in an easy and secure way and ensure you will become good friends with it.

 

The only thing you should do is strictly respect its syntax and know that in the C language, a comma or a semicolon is important and that the case when writing is also significant. Perhaps these two things are the origin of half the mistakes you will make when programming and that give the C programming language its bad reputation.

 

Digital versus analog signals

When working with electronics signals, you will constantly see references to digital and analog signals, and it is important that you differentiate between the two and know how to make Arduino deal with every type of signal.

 

A digital signal is one that takes only two clearly different states—no more, no less. To give you an example, switching a light on and off can be a typical case of a digital signal. You just have these two states, and it is on or it is off; it can't be both at the same time and nor can it have any other possible state in between.

 

In opposition to digital signals, analog ones are those that have a theoretically infinite number of possible values between a minimum and maximum one. Looking for an example relative to light, such as the one given for digital signals, we can think of the light coming from the sun through a window.

 

It has a minimum when there is no sun in the night, and a maximum when the sun is just in front of your window. However, between these two extreme values, there is an infinite number of them, differentiating one another in a very small increment as long as the sun goes from the minimum position to its maximum.

 

When working with computers and microcontrollers, digital signals are often represented by the 0 and 1 value, 0 is the value used for the off state and 1 for the on state, which makes them perfect to be represented as binary digits. In the Arduino language, we even have two more convenient constants to reference these two states, HIGH and LOW, as you may remember from the Blink code example we saw in the previous blog. In any case, we will see more about this on this blog.

 

On the other hand, when dealing with analog signals from the point of view of a computer, we usually represent them as real numbers or floating-point numbers in computer science jargon, but we will talk in more detail about this in Blog 4, Controlling Outputs Softly with Analog Outputs.

 

Our first circuit

circuit

To begin working with digital outputs, we are going to connect a very simple circuit to our Arduino board and write some code to deal with it.

 

In the rest of the blog, I'll present you with different circuits that we will have to assemble and connect to the Arduino board. Regarding the external circuits assembly, nowadays we don't really have to solder all parts to a printed circuit board to get our circuit up and running. We can simply use a bunch of short wires, called jumpers, and a breadboard. Before going on with our first circuit, let's take a look in detail at what a breadboard is and how to use it.

 

Using a breadboard

A breadboard is a square panel built in such a way that it allows the connection of the electronic component plugged into it without the need to solder them together or use any other form of connection among them.

 

A typical half size breadboard

As you can see in the preceding picture, the breadboard has a lot of holes distributed in four different areas:

  • Two horizontal rails up and down with two rows of holes
  • Two blocks for components' connections in the middle, usually with columns of five holes

 

You plug the components' legs into the holes. They are equipped with metallic clips inside that fit the electronic components once inserted. They are distributed in the breadboard in such a way that it connects all holes in every rail's row and every hole in every five-hole columns in the components' area.

 

To allow you to connect the circuit to the Arduino board or other external components not placed in the breadboard, you should use small pieces of wire that go from a hole in the breadboard to the external component leg. For more detailed information, with very illustrative images and examples of use, you can visit the excellent Sparkfun tutorial on how to use a breadboard at https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard.

 

At the moment, you don't have to worry about being very capable with a breadboard, because I'll give you detailed schematics and diagrams on how you should connect every one of the proposed circuits to your breadboard.

 

The LED circuit

LED_circuit

The first circuit we are going to assemble is a simple LED with its current limiting resistance, and we will connect it to a digital output of our Arduino board.

 

Arduino has two different rows of pin headers:

  • One with the powering pins and analog inputs in the lower side of the board
  • The other in the upper side, with all digital pins

 

An Arduino row of digital pin headers

You can see that some of the pins in the digital row are marked with ~, which, as stated in the board serigraphy, are available for use as analog outputs through the use of Pulse Width Modulation (PWM), about which we will talk more in the next blog. This doesn't mean that you can't use them as digital pins, but it simply means that when you are going to use analog outputs, you should use only those pins that are marked PWM.

 

For our example, we will connect a current limiting resistance of about 220 Ohms to the Arduino pin 12, the other leg of the resistance to the LED anode, and finally, the LED cathode will be connected to the ground of our Arduino board, available at the bottom pin header through any of the two pins marked as GND.

 

An Arduino row of power and analog pin headers

This way, we will power the LED directly from the Arduino digital output pin in a programmatic form, and it will be our code that will determine when to turn the LED on and off by just setting that digital output pin HIGH or LOW, which will set it to 5V or 0V, respectively, thus providing or not providing current to the LED.

 

Circuit schematic

I'll always try to give you an electronic schematic of our assemblies so that you can understand what we are going to connect when using the breadboard or if you prefer any other method to make the necessary connections. The complete assembly for the connection of the LEis as shown in the following schematic:

 

Breadboard connections diagram

Once you have understood what we pretend to connect to the Arduino board, it's time to make the real connections using a breadboard. Here, you have a diagram where you can clearly see the connections that should be made to implement the circuit on the breadboard. All these diagrams have been made using Fritzing, which is an excellent free application that you can find at http://fritzing.org.

LED

 

A diagram of a connection to the LED assembly in a breadboard

In this diagram, you can appreciate something that you should get accustomed to as a good practice when assembling circuits on a breadboard and that you will see in all the diagrams in this blog.

 

As you can see, in the preceding diagram, I have connected a wire from the Arduino GND pin to the first hole of a rail in the breadboard, and from there, I've used another wire to connect that rail's row to the LED cathode. I haven't directly connected the LED cathode to the Arduino GND pin, although I could have done so.

 

This way, and given that all holes in every rail's row are interconnected, I have all the rail's connections tied to GND, which allows for a very fast and convenient way to connect the negative side of additional components to GND. This is done without the need for a wire from every component's negative side to the Arduino GND pin, which will be impossible to achieve given that there are only two GND pins in the Arduino board.

 

Later in the blog, we will also need to power other electronic components with a positive voltage, and we will use the same technique shown here, that is, we will take a wire from the Arduino 5V pin to another row of a rail, thus getting a whole row with positive voltages ready to power additional components on the breadboard.

 

Asymmetric blinking code

Once we have assembled the circuit and connected it to our Arduino board, it is time to leave the physical part of our project and begin to work on the logical one: the software we will program our microcontroller with and that will allow us to command the physical side of our project.

 

For this first example, we will use a modified version of the Blink example you saw in the previous blog and will blink the LED in an asymmetrical pattern, that is, having different durations for the on and off cycle of the blinking:

void setup() {

pinMode(12, OUTPUT);

}

void loop() {

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(100);

}

Although you have the complete code in the code examples accompanying this blog, I'd suggest that you type it by yourself, because this is the only way to really learn how to code and try to strictly respect the C programming language syntax.

 

This simple code will help us to analyze and understand the common structure of an Arduino sketch. As you can appreciate, the code is divided into two different sections called functions. To be precise, we have a function called setup() and a function called loop(), and each one has a very concrete mission in a sketch:

 

setup(): The purpose of this function is, as its name indicates, to set up the board and its peripherals in the way the sketch needs, for example, setting pins as inputs or outputs, assigning a predefined value to a variable, or initiating a serial communication with your computer. It's only executed once—right at the beginning of the program.

 

loop(): This function is where the real code execution occurs. It runs through every instruction within it in a sequential way from the top to the bottom and begins again once it has reached the last instruction. This function never finishes its execution, so the only way to stop running a sketch in Arduino is by powering the board off.

 

The logic of the code is quite simple. In the setup() function, we just tell Arduino that we want to use pin 12 as an output using the pinMode(12, OUTPUT) function call that, as you can see, takes two parameters:

 

The first is the pin we want to configure

The second is the mode we want it to be in, which is OUTPUT in our case

 

Once the setup is finished, Arduino enters the loop() function.

The first thing we do there is written a digital HIGH value in pin 12 using the digitalWrite(12, HIGH) function, which generates a 5V signal on the pin, making the LED turn on. After that, we wait for 500 milliseconds with the call to the delay(500) function and go on by writing a digital LOW value on the pin with the call to the digitalWrite(12, LOW) function, thus generating a 0V signal that makes the LED turn off.

 

C language syntax considerations

This being our first code, I would like to consider the syntax of the C language used in it. This, once understood, will help you minimize the syntax mistakes you could make when writing C code, and that would generate compiling errors. They are as follows:

 

The C language is case-sensitive; this means that it is not the same as a word written in uppercase or lowercase: pinMode() is correct whereas pinmode() isn't. The use of functions includes the accompanying pair of parentheses that serve to specify their parameters. Even when they don't have any parameters, the parentheses have to be included.

 

Every function content or block of code requires the use of a pair of curly brackets to delimit the instructions that belong to them and separate them from the rest of the program. Missing a closing curly bracket would result in a compilation error, which is sometimes hard to detect and correct.

 

As you can see, there is a semicolon at the end of every instruction. They are required by the C language to know where every instruction ends and where the next one begins. A simple carriage return isn't enough.

 

Everything after // or between a /* … */ block is considered to be a comment and thus, it won't be compiled by the Arduino development environment. The use of comments to explain the code is a common and very desirable practice that you should adhere to.

 

Troubleshooting faults in the circuit

It's difficult to have any trouble with such a simple circuit, but who knows, and perhaps there is something wrong in your assembly and you don't get the expected results. In the case of problems, here is a list of things you should check:

 

Go over your connections carefully, especially in the breadboard. The clips under the plastic housing of the breadboard tend to open wide gradually and sometimes, even when the component or wire is inserted in the hole, it may not make a correct contact.

 

On the Arduino side, be sure to connect the wire going to the resistance to pin 12, which is the one you are referencing in your code to be a digital output and the one you are using to turn the LED on and off. It wouldn't be the first case, as I've spent plenty of time looking for an error in the breadboard's connections when it was just that I had connected the wrong pin in the Arduino board.

 

The LED is a polarized component. This means that its legs have different functions. The anode usually has a longer leg and the cathode has a small flat in the plastic capsule to differentiate them. Ensure that it is connected the right way, that is, the anode is connected to the resistance and the cathode to the wire going to the ground rail.

 

If it still doesn't work, try with another LED, unwire everything, and connect it once again or try with another breadboard.

 

Dealing with multiple outputs

Once we have our first real circuit up and running, or blinking if you prefer, and once you are a little bit acquainted with the structure of a typical sketch and the C language syntax, why don't we try to make something a little more complicated?

 

It isn't hard to connect two more LEDs and their corresponding current limiting resistances and build a traffic light and modify our sketch to make it operate like a real one. Here, you have the schematic of such a circuit