Resources for AVR and Arduino microcontroller programming.

avr-gcc is an open-source toolchain for AVR processors. If you want to program an AVR microcontroller, you usually have two choices: Use the Arduino IDE. This is the easiest option for beginners: All you need is an Arduino board (either the original board, sold on http://arduino.cc or one of the many clones available, such as the Akafugu Serial and ISP Breadboard Adapter).

If you do not want to use the Arduino IDE, or you want to program a chip it does not support, such as an ATTiny chip, you will need to install avr-gcc. If the chip you want to program does not have a bootloader, you will also need an ISP programmer.

Windows

We recommend using WinAVR:

WinAVR

You can use WinAVR inside the Windows command line, but to make your life easier, installing Cygwin is a good idea:

Cygwin

OS X

We recommend using CrossPack:

CrossPack

Linux

On Ubuntu, you can use the package “gcc-avr.” This seems to contain a pretty old version of the compiler, so you might want to build it from source.

See here for more info: Installing the GNU tools (avr-gcc) for AVRs

Hardware

First of all, you wil need some sort of AVR processor development board. There are many options, including:

Both of these options come with a built-in bootloader, and can be used with avr-gcc directly through your USB port.

If you have a board without a bootloader, such as an empty chip, you will need an ISP programmer. There are many different versions available: Follow the instructions available for your programmer to make sure that it works properly on your computer.

Usage

If you prefer to program through an IDE, look at the next section. Otherwise, all you need is a plain text editor (emacs and vi are popular, but something very simple like Notepad will do in a pinch) and a command line shell.

  • Let’s start by downloading the hello world sample code. GitHub.

  • Open up a command line shell, and change to the directory where you installed the hello world example. On Windows, we recommend using Cygwin. On OS X, the standard Terminal works well. On Linux, just about any terminal program should work well.

  • There are subdirectories available for each supported processor. If you have an Arduino or Arduino clone or the Akafugu Serial ISP Adapter, you should change into the atmega328p subdirectory. (If your processor is not available, you can use one of the available examples as a starting point)

  • Create a file user.mk in your user home directory. In it, you should set up your programmer. See the avrdude documentation for information on how to use your specific programmer. Some examples follow:

To use with an avrispmkii programmer:

To use with an usbtiny programmer:

  • Type ‘make’ to compile the example code. If avr-gcc is installed completely, the code should compile.

  • Type ‘make install’ to download the binary to the chip. The user LED on your board should blink on and off.

IDE

It is also possible to use avr-gcc thorugh an IDE.

On Windows, you can use the Atmel AVR Studio IDE: See here for details

There is also a plugin available for the cross-platform Eclipse IDE available: The AVR Eclipse Plugin