Arduino USB Serial firmware from scratch

I have need to change the USB descriptors of the Arduino Uno R3, for a project that will have it acting as a peripheral to another device.

This post documents how you can make from scratch the USB Serial firmware for ATmega16U2 on the Arduino Uno R3, using Atmel Studio 7 and its LUFA Library extension. It can be flashed quite easily using the built-in DFU firmware and Atmel’s FLIP tool. Source code is available at GitHub.

Install LUFA Library extension if not already installed (Tools -> Extensions and Updates…).


Source files that perform the actual USB/serial proxying are reused from USB to Serial Converter example project for at90usb1287 (File -> New -> Example Project…). Go ahead and create that project and grab the files. Some additions to the USB/serial code such as allowing a sketch to be uploaded from the Arduino IDE, have been taken from the official source code at GitHub.


Create a new project for the ATmega16U2 (File -> New -> Project…).



Use ASF Wizard (ASF -> ASF Wizard) to add LUFA modules and remove the Generic board support (driver) module.


Configure GCC symbols (Project -> Properties). Change BOARD to BOARD_UNO, and add F_CPU=16000000UL, and F_USB=16000000UL.


Resolve build errors by mostly eliminating code. Source code that builds without errors is available for comparison at GitHub. Program (Tools -> Device Programming) the firmware using the FLIP tool.


Reboot the Arduino.

Arduino USB DFU firmware from scratch

The Device Firmware Upgrade (DFU) firmware for the ATmega16U2 on Arduino UNO R3 is used to flash the USB Serial firmware, among others, using Atmel’s FLIP tool.

This post documents how you can build from scratch DFU firmware using Atmel Studio 7 and its LUFA Library extension. You’ll need an ISP/ICSP programmer to program the ATmega16U2.

You can install the LUFA extension from the Extensions and Updates dialog (Tools -> Extensions and Updates).


Create a new project based on the DFU Bootloader example (File -> New -> Example Project…).


Change the compiler optimization setting to -Os in toolchain properties (Project -> Properties).


Build the solution and flash (Tools -> Device Programming) using an ISP/ICSP programmer connected to the ICSP2 header.



Getting Started with the ESP-03

The ESP-03 is a very affordable Wi-Fi module built around the ESP8266EX chip by Espressif. TheESP8266 has become very popular among makers who want to affordably add wireless smarts to things at home and work.

The ESP-03 has two useful modes of operation that can be initiated by controlling its GPIO pins – normal mode and flash mode.

Normal mode wiring is show in the figure below. ESP-03 shown here is powered using SparkFun’s FTDI Basic Breakout – 3.3V – USB to serial module.

Normal Mode

In this mode, ESP-03 executes firmware programmed to the SPI Flash. SPI Flash is an external NOR Flash chip where program instructions are stored, and retrieved during execution.

The ESP-03 has a 4 Mbit 25Q40BT part which allows for 512 KB of program space. Of that, about 423 KB is available for your own programs.

Serial Flash Chip

In flash mode, new program instructions can be flashed to SPI Flash, using tools such as the ESP Flash Download Tool. The wiring is similar to that for normal mode, with the addition of GPIO0 connected to GND.

Flash Mode

ESP8266 can be programmed using an SDK distributed by Espressif. Popular embedded development platforms such as the Arduino IDE, MicroPython, and Lua can also be used.

Adafruit provides instructions for configuring the Arduino IDE for ESP8266 development. Here’re the settings I use with the Arduino IDE – under Tools menu.

Arduino Settings

Try the example project under File -> Examples -> ESP8266WiFi. With it, you’ll be controlling a GPIO pin on the ESP-03, over your Wi-Fi network, in no time at all.

Wi-Fi Web Server

Programming an Arduino using BlocklyDuino

Blockly is an experimental drag-and-drop programming environment not unlike Scratch. BlocklyDuino is based on Blockly and provides an open source drag-and-drop programming editor for Arduino. It doesn’t yet build the resulting code, but you can copy-paste it into the Arduino IDE.

Here’s something quick I built to try it out. If an input digital pin is logic high, it prints text to the serial port.

BlocklyDuino Editor

Try and make it yourself, or open the following XML using BlocklyDuino’s Load XML feature.

<xml xmlns="">
  <block type="controls_if" inline="false" x="59" y="70">
    <value name="IF0">
      <block type="logic_compare" inline="true">
        <title name="OP">EQ</title>
        <value name="A">
          <block type="inout_digital_read">
            <title name="PIN">2</title>
        <value name="B">
          <block type="inout_highlow">
            <title name="BOOL">HIGH</title>
    <statement name="DO0">
      <block type="serial_print" inline="false">
        <value name="CONTENT">
          <block type="text">
            <title name="TEXT">Hello, World!</title>

You can copy-paste code from BlocklyDuino’s Arduino tab into the Arduino IDE.

BlocklyDuino Arduino Tab

You can then use Arduino IDE to verify it, and upload.

Arduino IDE with code copied from BlocklyDuino

Toggle Pin 2 between 3.3 (Arduino Pro) or 5 volts and GND with a wire. You should see text appear in the serial port output when the pin is high.

Monthly news review

This post begins a new series of monthly posts where I’ll review news of the month that has passed.

Facebook releases Paper for iOS

Before Paper, I was spending less time in Facebook and more time in FlipBoard. After Paper, I am spending less time in FlipBoard. FlipBoard still gives me more (still relevant) news than Paper, such as new and on-sale app recommendations. One curious fact, the Paper app was designed using a prototyping toolkit called Origami.

Google releases Cast SDK

This was also the month I bought a Chromecast, my first Google device purchase.

Here’s what I like about it:

  • Price
  • Ease of use
  • Cast content of any tab in Chrome, including videos, using the Google Cast extension
  • Over the air updates

Here’s what I don’t like about it:

  • Doesn’t ever go into sleep mode, so it is sucking power all the time
  • Not as many apps as there should be, but that should change quickly now

Telerik Platform

It’s a comprehensive platform for building cross-platform native, hybrid, and web applications. Developers can use Visual Studio, or a web-based IDE.

MasterCard and Visa endorse Host-based Card Emulation (HCE)

With this endorsement payment card information can now be stored in the cloud. An Android app can then communicate that information to a NFC reader.

Atmel releases beta of Atmel Studio 6.2

Atmel is steadily improving its unified IDE for AVR and ARM MCUs. This release improves debugging and tracing capabilities. I’ve been using the IDE on a continuous basis for AVR and Arduino-based projects, and find it to be quite a productive tool.

Broadcom releases source code of VideoCore driver stack

VideoCore is also used in their SoC that runs the Raspberry Pi. Releasing the source code should allow community driven improvements and fixes to proliferate.

Nokia releases an Android-based device

It doesn’t sport the Google Play store though. They are reportedly porting Windows Phone apps to Android using Xamarin. I love how Xamarin has been enabling .NET for cross-platform development.

Is this how your circuits arrive?

TKJ Electronics did a very bad job of packaging and shipping this circuit to Brazil. They placed it in a bubble mailer envelop and shipped it. One of the headers is soldered wrong too. I paid them extra to solder the headers, a choice I now regret.


Visual Micro is an alternative IDE for Arduino

For those doing any kind of Arduino programming, and searching for a better IDE, Visual Micro is the answer. It is a Visual Studio plugin that makes coding Arduino sketches much easier. Visual Studio has always had an excellent code editor for C/C++, but it is pricey and requires you to be a Windows user. If you’re interested, download and test the Visual Micro plugin. If you don’t own Visual Studio, the plugin also works with the free Atmel Studio 6.1 IDE.