reprogramming the Arduino Uno R3 to be a ledwiz-compatible device

hi,

a very geeky post right now.

After a question on ArcadeZentrum’s Facebook page (https://www.facebook.com/groups/arcadezentrum) about whether or not it is possible to use an arduino uno or mega2560 as a ledwiz replacement, I got to work trying it out.

what is ledwiz? It is a usb device that works together with several arcade emulator frontends and virtual pinball frontends to light up leds and spin motors etc in response to game-events. (sold on http://groovygamegear.com) Unfortunately it is quite expensive to get to Europe.

We stumbled upon this: http://forum.arcadecontrols.com/index.php?topic=132903.0, where philip88 is using a bare atmega-32u2 chip on a breakoutboard as the ledwiz replacement. You have to download LWCloneU2.zip from there. (or here: www.bertclaes.be/ledwiz/LWCloneU2.zip) and unpack this.

I tried to replicate it, using the 16u2 present on the uno R3 (the 16u2 replaced the old 8u2).

First I had to reset the 16u2, so I could reprogram it. This is done by powering the arduino (e.g. by plugging in the usb) and shorting these two pins  here:

shorting these pins will reset the 16u2
shorting these pins will reset the 16u2

(CAREFUL: on the R3, there is already the correct transistor there (just above those pins), on R2 and R1, you have to follow this guide: http://arduino.cc/en/Hacking/DFUProgramming8U2)

Second step is to build the firmware philip88 provided with the latest LUFA-source code.

Lufa source code can be found here: http://fourwalledcubicle.com/LUFA.php
The necessary AVR chainset can be found on: http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORWINDOWS.aspx?tab=documents

Be sure to put either (64bit) C:\Program Files (x86)\Atmel\AVR Tools\AVR Toolchain\bin or C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin (32 bit) in your PATH enviroment variable.

Then you have to edit the file “makefile” in the firmware directory of your unpacked LWCloneU2.zip.
You will have to change  “LUFA_PATH    = ../../LUFA/LUFA-120730/LUFA” to the correct path where you have put the LUFA source code. I also changed “MCU          = atmega32u2” to “MCU          = atmega16u2” just to be sure.

After that you will have to build the new firmware for the 16u2, by running make when in the firmware directory.
If the building is successful it will say “Finished building project \”LWCloneU2\” and several files will be created inside the firmware folder.

Third thing is flashing that firmware onto the 16u2. For this you will need Atmel’s Flip application, which you can download on http://www.atmel.com/tools/flip.aspx. in flip you have to select your target device (ATmega  16U2) and the Communication Medium (USB). If flip gives the error “could not open USB device”, you haven’t correctly reset the 16u2 and have to short the two pins again. Another error i got was “atlibusbdfu.dll not found”, I resolved that one by unplugging the usb of the arduino and plugging it back in, it installed a driver at that moment.

If you have successfully selected the right target device and Communication Medium in Flip, you can load the HEX file from the firmware folder of LWCloneU2 and press the Run button at the bottom left. It takes a couple of seconds, and the firmware is now replaced.

To test the chip, you can use the testapp.exe inside the LWCloneU2.zip in the command line, but you will have to install  Microsoft Visual C++ Redistributable from here:  http://www.microsoft.com/en-us/download/details.aspx?id=30679 (32 and 64 bit just to be sure) or it will tell you “The program can’t start because MSVCR110.dll is missing from your computer.” If all goes well, both the Tx an Rx leds on the arduino board should light up and you will get “ledwiz device found, id: 4” on the command line.

Another app to test it out is Ledblinky’s simple led test, and there you will find out that port 10 corresponds with the rx line and 11 with the tx one and port 13 with the built in test led. just don’t put it on full intensity, because the led will just go out…

Next step will be to try to use all the ports on the arduino by speaking to the mega328-chip trought the 16u2… not sure this is possible…

Some other useful links:

http://hunt.net.nz/users/darran/

http://blog.arduino.cc/category/hacks/lufa-hacks/