Getting Started

Open Hardware – Arduino

© Lead Image © Burmakin Andrey, 123RF.com

© Lead Image © Burmakin Andrey, 123RF.com

Article from Issue 214/2018
Author(s):

Whether you are building your own device or customizing one, Arduino technology often functions as the foundation for your open hardware project. Here's how to get started with Arduino products.

Arduino single-board microcontrollers [1] were originally intended for educational and do-it-yourself projects. Increasingly, though, they are a foundation for Internet of Things (IoT) projects and open hardware. Sometimes, they are used only for prototyping, but, just as often today, they are found in commercial products ranging from keyboards to prosthetics. If you are involved in open hardware, knowing how to work with Arduino products is quickly becoming essential.

Arduino boards are influential for several reasons. To start, while limited in scope, Arduino boards are powerful enough for many dedicated purposes. If they are not, chaining them or using extension hardware known as shields can easily extend their usability. Just as importantly, Arduino boards can interact with Linux, OS X, or Windows, as well as other single-board microcontrollers like the Raspberry Pi.

Moreover, Arduino offers widespread support for all user levels. This support includes its own IDE and a programming language that is a variant of C, a Creative Commons license, and a community of thousands. With this support, users can begin to work without experience in electronics or programming. At the same time, Arduino is flexible enough to meet the needs of experts as well.

Regardless of whether you are building your own device or customizing a product that uses Arduino hardware, at the heart of working with an Arduino board is customizing the firmware for a board or shield. Exactly what you can do depends on the hardware with which you are working. Since nearly two dozen boards (Figures 1 and 2) and almost the same number of shields are currently available, detailed instructions would fill a book, if not several [2]. What follows is a general overview of how to get started, from preparing to work with the Arduino IDE to flashing the device's firmware.

Figure 1: The UNO is a popular Arduino board for hobbyists.
Figure 2: One of the more powerful Arduino boards, the MEGA 2560, is finding its way into commercial devices.

Installing the Arduino IDE

Regardless of which Arduino board you are working with, the first step is to download and install the Arduino IDE. Different versions of the IDE are available for different operating systems. Especially if you are working with a newer board, you should install the latest version of the IDE, not the one available from your distribution's package repositories. Note that Linux has 32- and 64-bit versions, as well as an ARM version [3].

On Ubuntu, begin installation with the following commands:

cd ~/Downloads
tar xvf arduino-1.8.5-linux64.tar.xz
sudo mv arduino-1.8.5 /usr/local/arduino
cd /usr/local/arduino
sudo ./install.sh

Next, check that your regular account is in the dialout group by running the group command. If the username is not listed, add it with the commands:

sudo adduser $USER dialout
newgrp dialout

You will also need to add dependencies like GCC and Java, as well as make the ARDUINO_PATH part of your environment:

sudo apt-get install gcc-avr avr-libc
sudo apt-get install openjdk-6-jre
sudo update-alternatives --config java
export ARDUINO_PATH=/usr/local/arduino

Check for any additional instructions for the hardware and your Linux distribution. If you are using an Arduino clone – of which there are as many sold as true Arduino hardware – you may also need to install software for it as well.

To check that the IDE is ready for use, power up your Arduino board or device and plug it into a USB port that is not part of a USB hub without its own power supply, so that it can draw power from your computer. Use Tools | Board to make the IDE recognize the device, and, if necessary, Tools | Port. Then you can test that the IDE and the device are communicating by clicking File | Examples | 01.Basics | Blink to make the LED on the Arduino board flash.

Using the Arduino IDE

The Arduino IDE has its own structure and jargon. In the Arduino folder created in your home directory the first time you run the IDE, code for the hardware is placed in the hardware directory. Files containing firmware source code are called sketches (*.ino) and each is installed in its own separate directory along with the resources required to work with it. Much of the programming can be done within the sketch, but lengthy modifications are sometimes stored in the libraries subfolders, together with general IDE resources.

You do not need to use the IDE to edit firmware. In fact, many users prefer to use their favorite editor instead. Nothing is wrong with using another editor, but to apply your modifications, be sure they are placed where the IDE can locate them. Moreover, the IDE is filled with useful tools and utilities, including:

  • File | Examples: Small bits of code that show you what can be done with Arduino technology and that can be borrowed and modified as needed.
  • Files | Preferences: In addition to the general look and feel of the IDE, this dialog sets network connections and the verbosity displayed when code is run.
  • Tools | Archive Sketch: Stores the current sketch, protecting it against being accidentally altered or overwritten.
  • Tools | Board Info: Displays basic information about any board attached to the computer on which the IDE is installed. Tools | Port needs to be set before you can get information.

These tools are in addition to those found in the Editor menu for automating the writing of code and navigating within a sketch.

Programming

Arduino C, the programming language used to create Arduino firmware is a simplified version of C and C++. Unlike other versions of C, Arduino lacks the header section of a C program. Additionally, a sketch begins with a reserved routine called setup, which is executed only once and contains commands for initializing the hardware. The rest of a sketch is a routine called the loop, which is a block of statements that are repeated over and over until the hardware is disconnected or the sketch is overwritten. When you start a new file in the IDE, code for the setup and loop routines are added automatically. Otherwise, if you are familiar with C programming, you can probably adjust quickly to Arduino C (Figure 3).

Figure 3: The Arduino IDE is both an editor and a collection of useful utilities.

If you are not familiar with C programming, you can do far more than you might imagine by modifying examples of the firmware provided with a particular device. You can begin by altering default settings set by the firmware and then experiment with code snippets on your own. You can click Sketch | Verify/Compile to check the validity of your experiments as you work. For those who prefer formal learning, the Arduino site has detailed information about Arduino C [4].

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Decisions, Decisions

    When it comes to open hardware projects, the choice of an Arduino or a Raspberry Pi board can determine success or failure. Read on for guidance in selecting the best board for your specific needs.

  • Perl: Arduino Project

    With a few lines of self-written firmware and a simple Perl script, Perlmeister Mike Schilli trains one of his Linux computers with a plugged in Arduino board to switch electrical equipment on and off using a relay. Enchanting.

  • Arduino's cofounder describes the quest for simplicity

    Arduino's cofounder describes the quest for simplicity.

  • Free Software Projects

    Free/​Open Source isn’t just about software, it’s also about hardware. Open hardware projects are proliferating, and just like open source software, you can get started inexpensively. Here are three projects that are fun, useful, and suitable for beginners to embedded programming, robotics, and building electronic devices.

  • A Graphical Interface for Customizing Keyboard Layouts

    How is the popular keyboard manufacturer's graphical installer after nine years in development?

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News