Using an Arduino? Love the CLI (Command Line Interface)? Perhaps Makefile is for you.

Hopefully I will be doing a series on Arduino and make. We will see if there is any demand. Hopefully, this is just the first. This is specifically for the Leonardo for now. The rest will be more flexible.

Since you are here, I suppose you know that the Leo is developed around the Atmel ATmega32u4. The highlighting part for choosing this chip is the onboard USB.

You will need:

Using avrdude for this chip is pretty straight forward. It’s not unlike any other AVR for the most part. The only thing that you have to do differently is kick the chip into the bootloader – without manually hitting the reset button. The way this happens is: Connect to the chip at 1,200 baud, and disconnect. Wham, chip is in bootloader. Now you may connect with avrdude at the upload baud(57,600).

There are two parts to this: A Python script to kick the chip into bootloader, and the avrdude command to upload. Here are the files for your pleasure.

<br />
#!/usr/bin/env python</p>
<p>import serial, sys</p>
<p>serialPort = sys.argv[1]</p>
<p>ser = serial.Serial(<br />
    port=serialPort,<br />
    baudrate=1200,<br />
    parity=serial.PARITY_NONE,<br />
    stopbits=serial.STOPBITS_ONE,<br />
    bytesize=serial.EIGHTBITS<br />
<p>ser.isOpen()<br />
ser.close() # always close port</p>


<br />
PORT = /dev/ttyACM0</p>
<p>burn:<br />
    python $(PORT)<br />
    sleep 2<br />
    avrdude -patmega32u4 -cavr109 -P$(PORT) -b57600 -D -Uflash:w:./Blink.cpp.hex:i</p>

Need help with avrdude? Ladyada has an excellent tutorial for it.

Enjoy! I have a project for this: Fork it, improve it, and send me pull requests.