Notes on Programming AVR Microcontrollers with C and Linux

Hardware

I used an ATmega328P-based device that I found on Amazon. It is a clone of the Arduino Nano. This is a diagram of the pinouts of the device.

A breadboard, some electronic components like LEDs and resistors, and a mini USB cable are the additional items that are needed.

Programming

I used the Arch Linux package manager to install avr-gcc. An extensive manual is available for this tool suite.

Follow the code examples in this tutorial to make your first program.

I used the following command to generate a .hex file for flashing to the device.

avr-gcc -Os \
        -mmcu=atmega328p \
        -o test.hex test.c

Follow the code examples on this site to make a more advanced program.

Flashing

I used the Arch Linux package manager to install avrdude.

I used the following command to back up the existing program to disk.

avrdude -c arduino \
        -p m328p \
        -P /dev/ttyUSB0 \
        -U "flash:r:existing.hex:r" \
        -b 57600 -v

I used the following command to flash my new program.

avrdude -c arduino \
        -p m328p \
        -P /dev/ttyUSB0 \
        -U "flash:w:test.hex" \
        -b 57600 -v

Vendors

If you're looking to add more components or just see what the options are, these online retailers are the way to go: