Introduction to this series

In this book, we will look at the Arduino hardware and software platform.

When someone mentions “Arduino” in conversation, the word can mean a number of things. Arduino is a company (actually two companies, but we won’t get into that now) that produces electronics hardware and software. An Arduino device is often simply called an Arduino, although each model also has a more specific name. (“My project uses an Arduino.”) Software for these devices is developed using the Arduino IDE and associated code libraries. And Arduino can refer to the whole ecosystem surrounding all of this hardware and software. (“Have you looked into Arduino?”)

For many hobbyists and students, what Arduino really represents is a stepping stone from the world of computers into the world of electronics.

The hardware

There are a variety of Arduino devices, perhaps the most common being the Uno, the Due, and the Mega 2560. Although their specs vary, they all serve essentially the same purpose. On each board is a microcontroller with a primitive CPU and tiny amount of memory, and several pins for input and output. Also present is a USB port for power and communication with a computer, and a jack for providing power when USB is not being used.

The software

There are three main types of software related to Arduino: The bootloader, the integrated development environment (IDE), and code libraries.

The Arduino bootloader is a tiny bit of code that is preloaded on the microcontroller, enabling it to be programmed over the USB port. It is possible to overwrite the bootloader with your own code, but then you will have to use specialized hardware (called an in-system programmer, or ISP) to program it. Interestingly, you can also use one Arduino board as an ISP to program other chips.

The Arduino IDE is a desktop application that provides an easy path to get started writing code for your device. Although it is a reasonably capable application, it does not provide a lot of the functionality found in other code editors and IDEs such as Visual Studio. As you begin to write more advanced code, you may find that the Arduino IDE no longer meets your needs.

The Arduino libraries provide pre-written code for functions such as controlling motors, reading and writing data, and communicating with other devices. Several standard library capabilities are included with the Arduino IDE, and many more have been made freely available by third-party developers.

Your first program

The simplest Arduino program looks like the following:

void setup() {
}

void loop() {
}

What we have done here is define two functions, one named setup and one named loop. These are two special functions that are automatically called (or executed) after the Arduino device starts up.

Now let’s get familiar with some terminology that will recur throughout this text. If you have already done some programming in a “C-like” language, this will all be review, so feel free to skip to the next section.

The void indicates that the function doesn’t return any value to its caller. Later we will write functions that return numbers, strings of text, or other values. In those cases, void will be replaced with the appropriate data type.

After the function name are two parentheses, ( and ). This is where we would describe the function’s parameters. Parameters declare the types of data that the function expects to receive when it is called. Each parameter also has a name that allows us to work with the data within the function. The two functions above do not have any parameters, so the parentheses are empty.

Finally, anything that we write between the opening and closing braces, { and }, is the code that will run when each function is called. As you can see, there is no code between the braces, so this program does nothing!

Although you will find many code examples throughout this text, it will be immensely helpful if you already have some skill with programming, especially using a language similar to C or C++.


 MENU