Vous êtes sur la page 1sur 6

Recipe for a cheap 12-axis, 64 button joystick encoder for your sim pitting needs.

I've heard a lot of people saying that arduinos are great interfaces for creating elaborate sim cockpits, but the dudes saying that are the
ones who already have an aptitude for programming. I have not seen any of them share a turnkey solution using an arduino to make a
cheap joystick encoder suitable for a sim pit. I know, because I've looked for such a thing and never found one. All the sim pit builders
who have used arduinos have never shared the details of how exactly they used one.

A previous solution that I had high hopes for described how to turn an arduino into a HID
joystick, but it only worked for the UNO and only provided one button and 2 axes, and of
course was missing the oh-so-important sketch (program that runs on the arduino) that makes
it all work. I guess they just assume that anyone willing to buy an arduino was also willing to
dive headlong into an oddyssey of countless hours learning C+, C#, or Processing language to
program their own sketches that poll each pin and perfectly pass it to the USB file descriptor
function. Example sketches based on that code were never fully functional had NEVER had
any comments in the code describing how it worked making it near impossible for someone
without a programming background to use.

After months of disappointment trying to figure out the HID joystick example code and learn
what the hell bitshift, pointers, and dereference operators were, an easy solution came to my
rescue. It's called Megajoy, which is based off of Unojoy code that allows you to turn an
Arduino UNO into a working joystick, complete with the sketch. With the purchase of a
cheap Arduino Mega that you can get shipped from China off Ebay for like $18, you can
easily build a 12 analog axis, 64 button joystick interface that you can use to build a CDU,
UFC, a bunch of panels, whatever you want. Anyway, lets get started:

Step 1: First find a suitable arduino.


You want an Arduino Mega due to the sheer number of digital and analog inputs available, and that's the one that works for the
software I used in this tutorial.

The one I got is an Arduino Mega 2560. An arduino is just a brand name
for a line of Italian circuit boards that have a programmable chip in the
middle and the crystal it uses for timing, along with other features such as
easy-to-connect pin headers, power, and a
way to connect it to the computer. On
my Arduino Mega 2560, the chip in the
middle that makes up the brains is
stamped with "ATMEGA2560 16AU
1126" and it has a USB-B connector, a
DC-in jack, 53 digital pins, 16 analog
pins, and a bunch more other stuff that I
don't know what it does. I got mine off of Ebay for $18. Mine is not one of the newer "R3"ones that
have a combined DFU and USB Serial firmware, so I don't know if those R3s will work with
Megajoy or not.

Here's some current auctions selling what I have for around $18:
http://www.ebay.com/sch/i.html?_sacat=0&_nkw=mega+2560&_frs=1
http://www.ebay.com/itm/New-Mega-2560-ATmega2560-16AU-Board-Arduino-compatible-/300841945511
http://www.ebay.com/itm/New-Nice-1PCS-ATmega2560-16AU-Board-with-USB-Cable-For-ARDUINOs-IDE-MEGA-2560-
/170930838194

Namco51 - reddit.com/r/hoggit Page 1 2/24/2013


Step 2: Download the programming environment and the drivers from Arduino's website.
This file package includes Windows drivers plus the programming Integrated Development
Environment (IDE) you need. An IDE is just a fancy way of saying the program you type your
programs into, that also includes a bunch of libraries, example code, and also happens to translate
your program into machine code and upload to the device.
Download File: http://arduino.googlecode.com/files/arduino-1.0.3-windows.zip
(see website for other OSes: http://arduino.cc/en/Main/arduinoBoardMega2560)

Step 3: Unzip the arduino-1.0.3-windows.zip file to somewhere on your


computer.
I put it at E:\Program Files (x86)\arduino-1.0.3. You don't install arduino, you just
unzip the package run the arduino.exe folder from wherever you put it, so you
should probably pin the executable to your start menu so you can find it easily.

Step 4: Connect the Arduino to your PC over USB.


When you connect the arduino to your PC Windows will fail when trying to find the driver.

Once it does this go to Device Manger (Hit Windows Key + R, then type in
devmgmt.msc and hit enter) and locate the "Arduino Mega 2560" with the
yellow exclamation point and right click and "Update Driver".

Click "Browse my computer for driver software" Point it to find the driver at: E:\Program
Files (x86)\arduino-1.0.3\drivers, or wherever you put it.

Step 5: Download the MegaJoy software:


Download File: http://unojoy.googlecode.com/files/MegaJoy19Jan2013.zip
(Website: http://code.google.com/p/unojoy/downloads/detail?name=MegaJoy19Jan2013.zip )
Again just unzip it somewhere. I put mine at E:\Program Files (x86)\arduino-1.0.3\MegaJoy

Namco51 - reddit.com/r/hoggit Page 2 2/24/2013


Step 6: Upload the Megajoy sketch:
Run the arduino.exe and connect to your device. After you plug in your Arduino, you
have to tell the arduino.exe program where your device is before you can upload to it.
Click Tools - Serial Port - and click the com port where your device probably is. It
usually is NOT COM1, but the next one below that. As a test, click File > Examples > 1
Basics > Blink and click the right facing arrow to see if you can upload the Blink sketch
to your device. You should see the LED at pin 13 start blinking. If you can do this, then
you're ready to upload the MegaJoy sketch .

Click File > Open, navigate to the MegaJoy folder and open
"MegaJoyArduinoSample.ino". Hit the arrow to upload that sucker. Once you're done
you can close Arduino.exe and move on to the next step.

Step 7: Download the ATMEL FLIP DFU software:


The Atmel FLexible In system Programmer Defice Firmware Updater software is what you need to reprogram the firware on the little
ATMEL chip on your arduino to stop acting like an arduino USB to Serial converter and start acting like a USB joystick device
instead. It does this by overwriting the default arduino mega 2560 firmware with the specially written USB HID joystick device
firmware included with the Megajoy package.

Just download and install this package:


Download File: http://www.atmel.com/Images/JRE%20-%20Flip%20Installer%20-%203.4.7.112.exe
(Website: http://www.atmel.com/tools/flip.aspx )

Step 8: Put your Arduino temporarily into DFU mode:


There's a special jumper that you have to trigger to change the device so that it is in DFU mode
which makes it able to be programmed. To do this, plug in the USB cable and on the bottom of the
arduino, find the two solder pads that are located directly behind and underneath the USB port
(circled in green) and short them together with a loop of wire, and while you're holding that you
need to trigger a reset by shorting the two pins closest to the USB port (circled in red).

As soon as the arduino goes into DFU mode you will hear the "de-dunk" sound as the arduino device disappears, then you'll hear the
"du-dink" sound as a new device appears, the Arduino Mega DFU device.

Namco51 - reddit.com/r/hoggit Page 3 2/24/2013


Step 9: Install the Atmel USB DFU device driver:
Windows will try to automatically install a driver for this DFU device, but will again fail.
Run device manager again, right click on the new Atmel DFU device and once again
"Update Driver". Point windows to look for it in the C:\Program Files (x86)\Atmel\Flip
3.4.7\usb folder.

Step 10: Launch the Flip software and tell it what kind of arduino you
have:
Before the Flip software can reprogram your chip you have to tell it exactly
which atmel chip you have. This is usually what it shows up as in device
manager when in DFU mode. Mine shows up as an at90usb82 device. To do
this click Device > Select...

Then select at90usb82 from the list, or whichever chipset is on your arduino

At this point you can pretty much read and write to and from that little atmel chip on
your arduino using the Flip software. Why don't you take this opportunity to backup
and save that firmware? You can do so by clicking the USB icon then clicking
"Open"icon to make that connection to the device. 7th from the left that reads "Read
Target Device Memory". Save the resultant file as backup.bin somewhere.

This isn't necessary however since you can always restore the regular arduino firmware at
any time. The bins to do this are easily downloaded. I think the default firmware is called
Arduino-usbserial-mega.hex and is sitting in the E:\Program Files (x86)\arduino-
1.0.3\hardware\arduino\firmwares\atmegaxxu2\arduino-usbserial folder.

Namco51 - reddit.com/r/hoggit Page 4 2/24/2013


Step 11: Close Flip and use the Megajoy batch file to flash the firmware:
Megajoy makes it easy to flash the arduino's atmel chip with the HID Joystick firmware. They give you a batch file that does it for you
using the Flip command line software, you just have to make sure that the arduino is attached to the PC's USB port and placed into
DFU mode and you properly configured Flip as shown in the previous steps.

To do this just run the "E:\Program Files (x86)\arduino-1.0.3\MegaJoy\MegaJoy - Attack!.bat" file and it will do all the work for you
flashing the firmware using Flip.
Here is the output after running the "MegaJoy - Attack!.command" batch file:

Abracadabra!
Attempting to re-flash for an Arduino Uno R1/R2

E:\Program Files (x86)\arduino-1.0.3\MegaJoy\ATmega8u2Code\HexFiles>batchisp -de


vice at90usb82 -hardware usb -operation erase f memory flash blankcheck loadbuff
er "MegaJoy.hex" program verify start reset 1024
Running batchisp 1.2.5 on Fri Feb 22 11:27:37 2013

AT90USB82 - USB - USB/DFU

Device selection....................... PASS


Hardware selection..................... PASS
Opening port........................... PASS
Reading Bootloader version............. PASS 1.2.0
Erasing................................ PASS
Selecting FLASH........................ PASS
Blank checking......................... PASS 0x00000 0x00fff
Parsing HEX file....................... PASS MegaJoy.hex
Programming memory..................... PASS 0x00000 0x00b31
Verifying memory....................... PASS 0x00000 0x00b31
Starting Application................... PASS RESET 1024

Summary: Total 11 Passed 11 Failed 0


'else' is not recognized as an internal or external command,
operable program or batch file.
Now, you need to unplug the Arduino and plug it back in,
but it will show up as a joystick! Press any key to exit....

Namco51 - reddit.com/r/hoggit Page 5 2/24/2013


Final Step 12: Just unplug the arduino to get it out of DFU mode and enjoy!
Once the batch file finishes, just unplug it and plug it back in. You should end up with a single new USB device called Unojoy
joystick represented by two separate joysticks in the Game Controllers panel, each one with a shitload of axes and buttons.

You'll notice the communication light on the device flashing several times per second as it sends USB descriptor information through
the USB port to the computer.

Each digital button is "pulled up" meaning each pin on the device has a charge of +5v and will register that a button has been pressed
when it sees that it has been "pulled low" to 0v. What this means is you wire one side of each button to the arduino's ground pin and
the other side to one of the digital pins which is internally pulled high with a 5v signal. Pressing the button connects the digital pin to
ground pin dropping the voltage to 0v and registering as a button push. Practice grounding digial button pins with a piece of wire by
connecting one side to the ground pin and the other to each digital pin and watch as the buttons light up in the joystick properties page.
Note that button 12 on the first UnoJoy joystick is showing as constantly pressed because it's actually pin 13, which shares its
connection with an LED that is constantly lit. Perhaps you can setup its button to a normally closed switch, or ignore it altogether (or
if you're some kind of goddam programming genius reprogram the sketch and reupload it.)

For analog pins I'm pretty sure you connect one leg of a potentiometer to ground, one leg to +5v, and another pin to the analog pin. I
still have to play with this a bit but it shouldn't be too hard.

If you want to make changes to the running sketch you have to put the device back into DFU mode by shorting the pad and shorting
the reset pins, then using Flip to write the MEGA-dfu_and_usbserial_combined.hex back to the device.

And this is where the journey ends for now. This is as far as I've gotten myself, but it should be a pretty easy operation to wire up a
control panel now.

If you have any questions, come over to http://reddit.com/r/hoggit or http://webchat.freenode.net/?channels=hoggit and ask away!

Namco51 - reddit.com/r/hoggit Page 6 2/24/2013

Vous aimerez peut-être aussi