A month or two ago I ordered some of Atmel’s ATmega32u4 microcontrollers to play around with. I was excited to get them, but at the time I was really busy at work, so I quickly forgot about them. Last Friday I received some TQFP44 breakout boards and decided to spend some time this past weekend getting the Arduino bootloader and some example sketches up and running on the ATmega32u4. Turns out, it was pretty easy.
One of the big features of the ATmega32u4 is that is has a built-in USB interface. This means that it’s super simple to program (just connect a USB cable and you’re good to go). Now in order to upload Arduino sketches to it, I first had to burn the Arduino bootloader to it. Since I don’t have a programmer, I used an Arduino Uno.
The breakout boards for the ATmega32u4 I got from one of my favourite online shops; Dipmicro. I soldered the microcontroller using my hot air station. I could have used my soldering iron, but that’s less fun.
Once that was done, I uploaded the ArduinoISP sketch to my Uno. Then I put the 10uF capacitor between RESET and GND. I added the 32u4 to my breadboard and put a 1uF decoupling capacitor between pin 6 and GND. Then I added the 16MHz crystal and 22pF ceramic caps, wired the appropriate SPI pins, and wired all of the GND and VCC pins. Here’s a diagram of the wiring:
I believe that some of the VCC and GND connections are also made internally on the 32u4 but it doesn’t hurt.
Once it was all wired up, I plugged my Uno back into my laptop, opened the Arduino IDE, chose “Arduino Leonardo” from the list of boards, and hit “Burn Bootloader.” After about 20 seconds, it was finished. Once
Now, in order to test it, I removed my Arduino Uno. What I had now was a very basic Arduino Leonardo clone. I added an LED on pin 25 (digital pin 4), and a switch from the RESET pin (13) to GND. If you haven’t used an Arduino Leonardo before, they are a little tricky for loading sketches – you have to hold the reset button, hit Upload in the Arduino IDE, and then release the button. If you get an error, just try again.
Lastly, I added the USB connections. I used a stripped USB cable, which had four wires:
- Black – GND
- Red – 5V
- Green – D+
- White – D-
The GND and 5V, I connected to the power rails, and the data lines I connected to pins 3 and 4 through a 22ohm resistor. Pin 3 is D- (white) and pin 4 is D+ (green):
With the wiring done, I plugged the USB cable into my laptop and switched back over to the Arduino IDE. I opened the Blink example, changed the LED pin to pin 4, held down the reset button, hit Upload, and let go of the reset button.
A few seconds later, my LED started blinking. Success.