Arduino Uno R3 as HID: Difference between revisions
No edit summary |
No edit summary |
||
| Line 42: | Line 42: | ||
Unplug your Arduino and plug it back in. It should work as before. Try uploading a sketch from the Arduino environment to check. | Unplug your Arduino and plug it back in. It should work as before. Try uploading a sketch from the Arduino environment to check. | ||
== Flashing HID firmware to the 16U2 == | |||
We're going to chenge the arduino into a HID device now. The code we are using is from the [http://www.fourwalledcubicle.com/LUFA.php LUFA project] and [http://hunt.net.nz/users/darran/ hunt.net.nz], who used this library to create some ready made arduino firmwares. | |||
Download the keyboard firmware and supporting files from [http://hunt.net.nz/users/darran/weblog/b3029/Arduino_UNO_Keyboard_HID_version_03.html here]. | |||
First, load the example sketch "kbd_usb_demo" on the Arduino. | |||
Open a terminal and flash the firmware to the Arduino: | |||
- Reset 16U2 (explained above) | |||
- flash the chip: | |||
sudo dfu-programmer atmega16u2 erase | |||
sudo dfu-programmer atmega16u2 flash Arduino-keyboard-0.3.hex | |||
sudo dfu-programmer atmega16u2 reset | |||
Unplug the arduino. Open a text editor. Attach the arduino while having your text editor in focus. The Arduino should now write "hello world" and set the volume. | |||
== Re-programming the Arduino after it is set as HID == | |||
The change the sketch on your R3 again, you will have to load the standard firmware fisrt, as explained above. | |||
Revision as of 10:33, 26 August 2014
Overview
To change your arduino into a usb HID device - for example a USB-keyboard - you will have to load a new firmware on the ATMEGA 16U2 chip on your Arduino board. That is the small square chip just behind the USB port on the board. This procedure is called DFU-programming or updating the firmware.
Updating the ATMEGA 16U2
First step is to reflash the ATMEGA 16U2 so we know that our setting is actually working. This instructions are based on some useful sites and forum hints on the web: - Updating the Atmega8U2 and 16U2 on an Uno or Mega2560 using DFU - Arduino-forum: Using Uno R3 on Linux? And some more hints in different forums I cannot recall already.
Install dfu-programmer
Download dfu-programmer from your distribution repos. For Ubuntu and Debian:
sudo apt-get install dfu-programmer
Once installed, check the version with
dfu-programmer --version
It has to be at least 0.6.1 for the following steps to work. If it's not, download the programmer directly from the authors: DFU-Programmer at GitHub
Reset 16U2
The Arduino Uno R3 (I'll call it just R3 from now on) comes with pin headers for the 16U2. To reset the chip, connect the two pins closest to the usb-port.
Flash Arduino's standard firmware to ATMEGA 16U2
The following instructions are for linux OS's.
Download the latest firmware from GitHub. The file is called Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex at the time of writing. You will have to open the file on GitHub as raw and save it locally with your browsers' "save" function. If the hex is stored in a wrong format locally, the flashing will fail with the error message: "Error parsing the line."
Open a terminal and change to your download directory.
Check if the programmer sees the 16U2:
sudo dfu-programmer atmega16u2 dump
You should get a gazillion of qustion marks on the terminal as a response.
Erase the chip, upload firmware and reset:
sudo dfu-programmer atmega16u2 erase sudo dfu-programmer atmega16u2 flash Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex sudo dfu-programmer atmega16u2 reset
Unplug your Arduino and plug it back in. It should work as before. Try uploading a sketch from the Arduino environment to check.
Flashing HID firmware to the 16U2
We're going to chenge the arduino into a HID device now. The code we are using is from the LUFA project and hunt.net.nz, who used this library to create some ready made arduino firmwares.
Download the keyboard firmware and supporting files from here.
First, load the example sketch "kbd_usb_demo" on the Arduino.
Open a terminal and flash the firmware to the Arduino:
- Reset 16U2 (explained above) - flash the chip:
sudo dfu-programmer atmega16u2 erase sudo dfu-programmer atmega16u2 flash Arduino-keyboard-0.3.hex sudo dfu-programmer atmega16u2 reset
Unplug the arduino. Open a text editor. Attach the arduino while having your text editor in focus. The Arduino should now write "hello world" and set the volume.
Re-programming the Arduino after it is set as HID
The change the sketch on your R3 again, you will have to load the standard firmware fisrt, as explained above.