Home‎ > ‎CS 11M‎ > ‎Variable Types and Serial I/O‎ > ‎

Lab 2: HEX Files

In this lab you will download a HEX file to your Arduino.


The HEX file contains runnable machine code for Arduino. Most Arduino programs are open source (you can download and the C++ code) so you can use the familiar process for loading the code. In rare cases (like my reference programs) you will find pre-compiled programs for Arduino. Pre-compiled hide the source code. In this lab you'll learn how to download HEX files. Before you begin use the link below to download a compiled copy of the blink sketch: 


For this week perform the Tutorial Exercises in CodeLab 1 


There's an easy GUI program on Windows that will load HEX files. The easy way out is to use the program:

The program is a "wrapper" around the instructions for Mac and Linux in the next section. 

Mac and Linux (Manual)

Arduino has the built-in ability to download HEX files. Doing it yourself requires you to do a little digging. Start by bringing up the preferences dialog using:

    File -> Preferences

Select the checkbox as shown. It enables verbose debugging of the upload process.

When you have debugging enabled and you use the Upload button you will see a lot of output in the Arduino terminal. Locate the AVRDude command line which is highlighted in the picture below: 

You should be able to copy-and-paste the command into a terminal window. The command shown in the picture above is: 

/opt/arduino-1.6.10/hardware/tools/avr/bin/avrdude -C/opt/arduino-1.6.10/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/build12bc3df4f3ab87749ce4d031032cb7bb.tmp/bin4counter.ino.hex:i 

The highlighted section contains the name of a HEX file. To download a different HEX file replace the highlighted section with the path to your file. 

/opt/arduino-1.6.10/hardware/tools/avr/bin/avrdude -C/opt/arduino-1.6.10/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:your_file_here.hex:i 

Mac and Linux (Script) 

My CS-11M repository contains a shell script to automate the downloading process: 

You must have the Arduino software installed on your system for the script to work. You can execute it like this: 

download.sh your_file_here.hex 

If the script doesn't work for you be sure to copy-and-paste the terminal output when you report the problem. 

Turn In

  1. A screenshot showing that you have downloaded a HEX file. 
Submit your homework on canvas.


  • 5 points for the tutorial exercises in CodeLab 1
  • 5 points extra credit for completing the assignment.
Michael Matera,
Sep 12, 2016, 10:16 AM