Linux

Mitch Altman and I are in the process of writing a book about Making Cool Things with Microcontrollers (for people who know nothing.)

The book features several DIY projects that use AVR microcontrollers.  We’re aiming to teach absolute beginners how to solder, basic electronics, and the process of turning a cool idea into reality by using microcontrollers.

I wrote these instructions about setting up a working avr-gcc environment in Windows, Mac OS X, or Linux.  Mitch and I felt that they could use some beta testing in the real world before bring included in the book, so we decided to make them available here.  We also felt that they might help some people get started with AVRs before the book is available.

We want to make the process of writing and compiling code for the AVR simple and accessible, so we’re not using any fancy IDEs (eg. no AVR Studio).  We also wanted to use the same software on all three operating systems, so Windows-only tools were out.  Instead, we’re using avr-gcc, the compiler behind WinAVR, CrossPack, and Arduino.

I would appreciate any feedback on these instructions.

AVR Toolchain Installation Instructions – Linux

Note: At the time of this writing, following the step-by-step instructions below will result in a working AVR toolchain being installed on your computer.  However, computers, operating systems, and software are constantly changing.  This means that while these instructions are valid today, they may not be by the time you read this.  If you run into trouble, fear not!  Entering a few carefully chosen keywords into your favorite search engine will often yield just the information you need to resolve the issue.

Installing the AVR toolchain on Linux is different from Windows and Mac OS X because there isn’t a bundled toolchain package available like WinAVR or CrossPack.  This is because all of the tools we need to compile for the AVR are easily installed using Linux’s built-in package management system.

The instructions below were developed and tested with Ubuntu Desktop 10.10.  The procedure should be almost identical for other flavors of Linux that use ‘apt’ to manage packages.  If you’re using another distribution, the procedure to find and install packages may be different.  Alternatively, you might need to compile the toolchain from source.

To install the AVR toolchain within Ubuntu Linux:

1. Open a Terminal window.  You can do this by opening the Applications menu and clicking Accessories->Terminal.

2. To install avr-gcc and other helpful programs, enter the command

sudo apt-get install gcc-avr avr-libc binutils-avr avrdude

If prompted, enter your password to authorize the installation.

It will take a few moments for the packages to download and install.  If the installation completes successfully, you should see something like this:

3. You can test the installation by entering the command

avr-gcc --version

You should see the response

avr-gcc (GCC) 4.3.5

and a copyright notice.  Note that the version number might be different.

4. Unlike Windows, Ubuntu includes built-in drivers for the Adafruit Industries USBTinyISP.  Unfortunately, a permissions issue with USB in Linux will cause problems programming devices (you’ll need to run avrdude as root) unless we fix it here.

If you are using another programmer (such as the Atmel AVRISP mkII) you can skip this step, but there may be related issues.  Consult your favorite search engine or the support forums for your programmer.

To fix the permissions problem, create a new udev rule by entering the command

gksudo gedit /etc/udev/rules.d/10-usbtinyisp.rules

This will open a new editor window (you might be asked for your password again.)

Type the text below into the editor window.  It is one long line, so just keep typing without pressing return.  Double check that what you entered into the editor window matches the text given below exactly (Note, it is case sensitive).

SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="adm", MODE="0666"

Save the new file by clicking the Save button in the toolbar and close the editor window.

Back in the Terminal window, enter the command

sudo restart udev

This tells Linux to load the new file, which grants permission to all users to access the USBTinyISP.

For more information, see https://mightyohm.com/blog/2010/03/run-avrdude-without-root-privs-in-ubuntu/
5. To test the USBTinyISP, plug it into an open USB port.  If you already plugged it in, unplug and plug it back in again.  The programmer’s green LED should be on.

If you are using the Atmel AVRISP mk II, substitute “avrisp2” for “usbtiny” in the command below.  If you are using another programmer, follow the manufacturer’s instructions or consult your favorite search engine.

Type the command

avrdude -c usbtiny -p m168

and press enter while you watch the USBTinyISP’s red LED.  The red LED will flash once and you should see the following message:

avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done.  Thank you.

If you don’t see the red LED flash, try executing the command again.  The LED flashes quickly and is easy to miss!

The initialization failed error shown above is not a problem, it is displayed because there is no microcontroller connected to the programmer.  At this point, if the red LED flashes, the programmer is working.  If you don’t see the red light flash, or you get a different error message, see the notes below.

If you see the error message

avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)
avrdude done.  Thank you.

double check your USB connections and make sure the green light on the USBTinyISP is on.

If you see the error message

avrdude: error: usbtiny_transmit: error sending control message: Operation not permitted
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude: error: usbtiny_transmit: error sending control message: Operation not permitted
avrdude done.  Thank you.

try following the instructions in step 4 again.

This completes the Linux AVR toolchain installation.  You are now ready to start programming microcontrollers!

4 thoughts on “Linux”

  1. Hi,

    I still get the error as could not find USB,… and so,..
    Im not sure exactly what programmer do i have, but its small , USB connectivity and ATMEL 1048 ATMEGA8L – 8PU ic on it

    is that usb tiny,. if not how do i figure it out what programmer it is and how can i communicate and burn.

    Can somebody help me plz,..

    1. It’s not a USBTiny. I suggest talking to whoever you bought the programmer from, they should be able to tell you what it is and what drivers you need.

  2. For Mandriva Linux (2010) I believe the packages are:

    * cross-avr-gcc
    * cross-avr-gcc-cpp
    * cross-avr-binutils
    * avrdude

    Optionally AVR assemblers include tavrasm or avra.

    These can be be installed with:
    # urpmi cross-avr-gcc cross-avr-gc-cpp avr-binutils

    I don’t see an equivalent package for avr-libc.

Comments are closed.

Join the resistance.

%d bloggers like this: