Arduino – Toolchain

Getting started with the Arduino toolchain is not hard. This week, we will look at the development environment, some tips and tricks for Ubuntu users and, as the grand finale, we will look at working with the Arduino using only plain C.

If you don’t feel like working with C, do not panic. We will start by exploring the IDE and examples provided from the Arduino project.

The Arduino project has a set of instructions for installing the integrated development environment for most platforms. We will specifically look at the process in an Ubuntu based Linux environment.

When installing the toolchain on Ubuntu Linux, start by installing the arduino package. This will install avrdude and gcc-avr alongside the Arduino integrated development environment. We will look more at these soon, but first we must manually upgrade.

As the Ubuntu package has fallen behind the Arduino project, it is recommended that you upgrade parts of the toolchain. Do this by downloading the debs listed in these instructions. When performing the actual upgrade, i.e. the call to dpkg -i, you might have to execute the command twice, just to get part of the install through the first time, then the other half the other time.

Having the IDE in place, you can start experimenting with it. You will find the IDE under the Development category of your applications menu. From the IDE, you can pick a number of examples as a starting point for your exploration.

These examples are all based around the concept of the setup and loop functions. Apart from the names of these entry functions, and the wealth of functions available for accessing pins and other hardware features, the code looks like plain C. This is because it is plain C.

An Arduino program, a sketch, is a piece of C code run in a specific context. One could call it “bootstrapped C”. This also means that it is fully possible to use plain C to easily interact with the Arduino. This is where the gcc-avr package enters the picture. It holds a version of the GNU Compiler Collection targeting the AVR micro controller around which the Arduino is built.

The bootstrapping C code can be located in /usr/share/arduino/hardware/arduino/cores/arduino/. The folder contains the entire C support package used around the sketch code. The sketch itself is included as WProgram.h in these files. Simply edit this out and replace it, and you are on your way to interface the Arduino directly through C.

Working outside the IDE, you need to device a method to upload your resulting code to the Arduino. This is where avrdude enters the picture. It is a tool that allows you to flash software to a wide range of AVR micro controllers, including the Arduino. To program an Arduino Uno, you need to know that it behaves as an stk500v1 device talking at 19200 baud and that it uses an atmega328 MCU. That should help you write your flashing command line in no time.

This entry was posted in Arduino. Bookmark the permalink.