Skip to content

How it works

Nico edited this page Jan 18, 2015 · 1 revision

Two Microcontrollers are better than one

This section describes how the whole thing works together and gives some background information. For better understanding I recommend to read this.

As you might know the Arduino Uno/Mega have two AVR Microcontroller. The Uno has a 328 and the Mega has a 2560. What most people dont know is that both Arduinos also have a 2nd Microcontroller, the 16u2 (before it was a 8u2 and even earlier it was a simple FTDI USB-Serial bridge). Some cheap Arduinos might not have a 8u2 or 16u2 because simple FTDI chips might be cheaper and normally not needed for its normal use.

Here I refer to the 16u2 which is standard for every R3 model of Uno/Mega. The 16u2 is normally used to program the main MCU 328/2560. Its a USB-Serial Bridge. But it can be used for many different things because its a standalone AVR with USB functions like a 32u4 on a Leonardo/Micro board. For example: Hiduino, Darrens Arduino Uno Keyboard HoodLoader1 or any other custom firmware.

So what does this tell us? You can use the 16u2 as a normal microcontroller of course. The problem was that its not accessible to everybody because its a bit hard to understand how to flash the 16u2, how to compile a program for the 16u2 (especially with LUFA) and the biggest problem: How to flash the main MCU (328/2560)? Because if you change the 16u2's firmware you cannot simply flash the Arduinos main MCU.

The HoodLoader1 solved this problem for the first time and its still a good and usable firmware to use USB functions and upload sketches to the main MCU at the same time like you are used to. But there were a few challenges with that. The biggest problem was just that it is hard to explain how that complex stuff works. I think it wasn't clear all the time, also because I had two repositories (HID Project and HoodLoader1).

The HID stuff always relied on a Serial communication between 16u2 and 328/2560 which wasn't perfect. The 16u2 got HID commands with a special NHP from the main MCU and filtered every other signal and sent it to the PC Serial (CDC Serial). Because when the PC USB-HID side was slow it had no chance to wait for the USB keys to flush. And the main MCU had no chance to get any response back from the 16u2. Otherwise I had to modify the normal Arduino core libraries very bad to filter out incoming back data (a 'flushed, next key press' signal) again and it would also blow the sketch size. Last but not least there were some problems with the multi report descriptor of the HoodLoader1). To keep things simple for now: Some OS (linux especially with gamepads) had problems with too many USB-HID devices in a same report (Keyboard, Mouse, 4 gamepads, Media, etc).

This time I want to keep things more clear but still more flexible. And I also want to add more documentation for those of you who want to learn this USB stuff and develop more professional things on their own. I know that its hard to understand the USB protocol. Its a lot of text in the readme, but hopefully some people are glad about that information.

But I am not perfect neither. I learned everything on my own. Learning by doing. I started from scratch at the end of Jan 2014 with Arduino/Electronics! So you can do that too, I believe in you :)