5.b. Programming AVRs in Mac OS X

If you have an Orangutan or 3pi Robot or wish to use the Pololu AVR C/C++ Library for some other reason, we recommend following the Pololu AVR Programming Quick Start Guide instead of this tutorial.

Installing CrossPack

To program AVRs in Mac OS X, you will need the free avr-gcc compiler, avr-libc, AVRDUDE, and other associated tools.

  1. Download the CrossPack for AVR Development, which is packaged as a .dmg file.
  2. Open the .dmg file, and double-click on CrossPack-AVR.pkg. This package will create a sub-directory called CrossPack-AVR-<version-date> on your hard drive (probably under /usr/local), along with a version-neutral symbolic link CrossPack-AVR referencing the same sub-directory. It will also add an entry to the PATH environment variable referencing CrossPack-AVR/bin.
  3. Programs for the AVR can now be compiled at the command line using the avr-gcc C compilers and the avr-as assembler. For detailed instructions, see the CrossPack development manual, which is installed in the CrossPack-AVR directory along with the tools.

Using AVRDUDE

Once an AVR program has been compiled to a .hex file, it is ready to be flashed to the AVR. The AVRDUDE program (which was installed as part of the CrossPack package) may be used for this purpose.

To see the full command-line syntax for AVRDUDE, type avrdude --help at the command line, or consult the AVRDUDE documentation. Typical usage would be as follows:

avrdude -p <partno> -c avrisp2 -P <port> -U flash:w:<filename>.hex

For example:

avrdude -p m328p -c avrisp2 -P /dev/cu.usbmodem00022331 -U flash:w:test.hex

If all goes well, the output should look something like this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "test.hex"
avrdude: input file test.hex auto detected as Intel Hex
avrdude: writing flash (3392 bytes):

Writing | ################################################## | 100% 0.88s

avrdude: 3392 bytes of flash written
avrdude: verifying flash memory against test.hex:
avrdude: load data flash data from input file test.hex:
avrdude: input file test.hex auto detected as Intel Hex
avrdude: input file test.hex contains 3392 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.72s

avrdude: verifying ...
avrdude: 3392 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.