Main Content

atmega16u2 virtual serial example using LUFA Library

Sending data from a microcontroller is a pretty common requirement in a lot of the projects I work on. One way of doing it is sending serial data out from the uC to a serial to usb converter chip to a computer. This has the advantage of involving very little code overhead for both the uC and the computer. It does also make it more difficult to route on a PCB (especially trying to fit it onto a single layer) and of course you have to pay for the serial/usb converter chip which in my experience range from about 2.50 to 5 euro per chip. An alternative to this is to have the uC communicate directly via usb with the computer. This can be done on a uC entirely in software – the V-USB library for atmel microcontrollers allows almost any atmel micro to communicate via usb. This creates a large CPU overhead as most of the uC’s time is spent maintaining the USB connection – leaving little time for anything else. uC’s with USB hardware in them offset this problem to a certain extent by including dedicated USB hardware so less CPU time is needed to use USB. The LUFA (Lightweight USB Framwork for AVRs) is a library aimed at taking advantage of this USB hardware. It comes with loads of examples that work with several types of atmel chips. The one that I chose is the atmega16u2 because it was pretty cheap and it was used the arduino uno as the usb-serial converter for the board. This meant that there was schematics of the board layout available online which came in very hany for making my own board. This board was intended to be used as part of the PlantBot project I’m working on but it ended up just being a LUFA virtual serial test board.”

Link to article