1
0
mirror of https://github.com/mcgurk/Arduino-USB-HID-RetroJoystickAdapter synced 2024-11-14 05:05:01 -05:00
Arduino-USB-HID-RetroJoysti.../README.md

83 lines
5.6 KiB
Markdown
Raw Normal View History

2016-09-05 15:33:10 -04:00
# Arduino-USB-HID-RetroJoystickAdapter
2016-09-05 17:12:48 -04:00
## What is this?
2016-09-05 17:33:24 -04:00
Very cheap and quite easy way to connect many non-USB joysticks and gamepads or DIY arcade cabinet controller to almost any machine with USB-port. Arduino board with ATmega32u4 chip with help of Joystick-library does all the USB-work.
2016-09-05 17:15:38 -04:00
Tested with Windows and Linux desktop computers and ARM based computers like Raspberry Pi and Orange Pi. Also worked with Samsung Galaxy S4 Android phone and Samsung Galaxy Tab 10.1 Android tablet with OTG-USB cable.
ATmega32u4 can be easily changed to act as keyboard and/or mouse too.
2016-09-05 15:33:10 -04:00
2016-09-05 17:05:10 -04:00
## Short version
2016-09-05 17:30:56 -04:00
- Get ATmega32u4 Arduino Board
- Install Arduino IDE
2016-09-05 17:30:35 -04:00
- Install Joystick library (https://github.com/MHeironimus/ArduinoJoystickLibrary)
2016-09-05 17:28:59 -04:00
- Connect joystick or gamepad to Arduino (in most situations soldering is required)
2016-09-05 17:31:28 -04:00
- Open sourcecode to Arduino IDE and select controller by commenting and uncommenting and edit pin-numbers (if needed)
2016-09-05 17:05:54 -04:00
- Upload
2016-09-05 17:17:09 -04:00
- Done
2016-09-05 17:05:10 -04:00
2016-09-05 17:06:41 -04:00
## Long version
2016-09-05 17:07:25 -04:00
### What you need
2016-09-05 15:35:25 -04:00
2016-09-05 17:07:25 -04:00
#### Arduino board
2016-09-05 17:18:29 -04:00
Starting point is ATmega32u4 based Arduino board. There is two versions of ATmega32u4, IO-logic with 5V or 3.3V. Many controllers (like basic Atari-controller) doesn't include any logic, so 5V and 3.3V versions are fine. Most of controllers with some logic needs 5V (NES, SNES, Genesis) and some rare ones needs 3.3V (Gamecube). Make sure that Arduino includes USB-port. There are some versions which doesn't include USB-port and then you have to add USB-connector for it. Arduino Leonardo includes ATmega32u4, but cheapest and smallest ones are named Pro Micro. Arduino Pro Micro and ATmega32u4 are good words to use when searching from Ebay etc. Cheapest starts from about $4.
2016-09-05 15:55:34 -04:00
2016-09-05 16:28:24 -04:00
Example of Arduino Pro Micro:
![Arduino Pro Micro](https://github.com/mcgurk/Arduino-USB-HID-RetroJoystickAdapter/raw/master/Arduino_ProMicro.jpg)
2016-09-05 17:07:25 -04:00
#### Computer with Arduino IDE
2016-09-05 16:50:00 -04:00
Arduino IDE works with Windows, OS X and Linux and ARM (beta). If you use small card computer like Rasperry Pi or Orange Pi, you can program adapter even with them (tested with Orange Pi PC and RetrOrangePi 2.0). That way you don't even have to unplug adapter from your emulator/game-platform if you want reprogram adapter.
2016-09-05 16:17:51 -04:00
2016-09-05 17:07:25 -04:00
#### Joystick library for Arduino IDE
2016-09-05 15:55:34 -04:00
Install joystick library (instructions for installing library: todo)
2016-09-05 15:35:25 -04:00
https://github.com/MHeironimus/ArduinoJoystickLibrary
2016-09-05 15:48:48 -04:00
2016-09-05 17:07:25 -04:00
#### Joystick(s) or gamepad(s) and way to connect them to Arduino
2016-09-05 16:31:45 -04:00
Some joystick/gamepads uses their own connectors and original connectors can be very pricey. Sometimes you can find extension cord cheaper than plain connector and you can take cable and plug from that.
2016-09-05 16:58:26 -04:00
You can use any IO-pins, but try to avoid pins 0 and 1. They are serial port TX and RX pins and even though they are not used right now, they are handy for debugging and other uses.
2016-09-05 15:48:48 -04:00
2016-09-05 17:07:25 -04:00
### Setup
2016-09-05 16:28:24 -04:00
Download and install Arduino IDE:
https://www.arduino.cc/en/Main/Software
2016-09-05 16:44:57 -04:00
- Tools->Board->Arduino Leonardo
2016-09-05 17:25:40 -04:00
2016-09-05 16:44:57 -04:00
In Arduino IDE you have to select board. On my case some reason "Arduino Leonardo" selections works better than "Arduino/Genuino Micro". With Leonardo-setting RX and TX leds are normally off and blinks when data is transfered to/from USB. With Micro-setting LED's are normally on and they blinks to off when data is transferring.
- Tools->Port->COMx
2016-09-05 17:25:40 -04:00
2016-09-05 16:48:39 -04:00
In Windows Arduino IDE shows only available com-ports. In most cases it's biggest numbered COM-port. COM-port number can change when you start to upload program first time (COM-port number can be different after joystick-features are enabled). If this happens, just change COM-port and start upload again. When I tested with RetrOrangePi (Raspbian Linux), port was ttyACM0.
2016-09-05 16:44:57 -04:00
2016-09-05 17:26:15 -04:00
- Test your programming environment and upload
2016-09-05 17:24:43 -04:00
You can now test your setup. One basic example is "blink". With this board, it doesn't blink, because there is no led in pin 13. Nevertheless you can use it as a test that your IDE and Arduino works.
Select File->Examples->01.Basics->Blink and press Upload (Arrow to right -symbol top of code windows). If you get no errors, you are good to go.
2016-09-05 17:34:40 -04:00
- Install joystick library (instructions for installing library: todo):
2016-09-05 16:28:24 -04:00
https://github.com/MHeironimus/ArduinoJoystickLibrary
2016-09-05 17:07:25 -04:00
### Code
2016-09-05 16:28:24 -04:00
This code supports Atari, SMS, NES, SNES and Genesis (3 and 6 button) controllers. Select your controller by commenting and uncommenting stuff from beginning of source code and give your IO-pin numbers.
2016-09-05 17:36:22 -04:00
Every one uses same button numbering, so if you make multiple adapters for different controllers, you have to teach buttons to emulator/game (or whole emulation system like RetroPie or RetrOrangePi) only once.
2016-09-05 17:00:11 -04:00
2016-09-05 17:07:25 -04:00
#### Konami code
2016-09-05 17:02:13 -04:00
You can also enable or disable Konami-code-shortcut. For now it works only with Genesis 6-button controller (X+Y+Z+UP (or DOWN)) and SNES-controller (X+Y+R1+UP (or DOWN)). Some games demands that not other buttons are pressed before code and that's why only last pressed button can be button which have some function in emulator.
2016-09-05 16:06:27 -04:00
2016-09-05 17:00:11 -04:00
https://en.wikipedia.org/wiki/Konami_Code
https://en.wikipedia.org/wiki/List_of_Konami_code_games
2016-09-05 16:06:16 -04:00
2016-09-05 17:00:11 -04:00
## Misc
2016-09-05 17:16:35 -04:00
Arduino UNO R3 includes ATmega16u2 (along with ATmega328p) and it can be used too, but it needs some extra work (code doesn't work without modifications with UNO):
2016-09-05 15:48:48 -04:00
https://github.com/NicoHood/HoodLoader2
2016-09-05 17:55:04 -04:00
## Todo (writing)
- example (D-connectors straight to Arduino)
2016-09-05 17:56:48 -04:00
- structure of code, sends only when something changes
2016-09-05 17:55:04 -04:00
- button numbering (genesis C as select)
- changing maximum buttons from joystick library (maybe pointless)
2016-09-05 17:55:35 -04:00
- joystick library instructions
2016-09-05 17:56:22 -04:00
- some words of analog controllers?
2016-09-05 17:58:20 -04:00
- some words of Arduino acting same time as serial port
2016-09-05 18:06:50 -04:00
- very simple test. test without joystick and test to connect one IO-pin to GND.