Git Product home page Git Product logo

arduino-usb-hid-retrojoystickadapter's Introduction

Arduino-USB-HID-RetroJoystickAdapter

What is this?

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 and HID-support. Arduino board with ATmega32u4 chip with help of Joystick-library does all the USB-work. Tested with Windows and Linux desktop computers and ARM based computers like Raspberry Pi and Orange Pi.

ATmega32u4 can be easily changed to act as keyboard and/or mouse too. With keyboard device it is easy to make adapter for many mobile devices which don't have gamepad-support out of box. I have tested it with Samsung Galaxy S4 Android phone and Samsung Galaxy Tab 10.1 Android tablet with OTG-USB cable.

Supported controllers

² = 2 controllers supported

* = needs Joystick-library

If you use Linux and want to get more than 1 controller with one Arduino, check "Linux and more than one controller with one Arduino"-topic in this same page.

Short version

  • Get ATmega32u4 Arduino board
  • Connect joystick or gamepad to Arduino (in most situations soldering is required)
  • Install Arduino IDE
  • Install Joystick library (if needed)
  • Open sourcecode to Arduino IDE and select controller by commenting and uncommenting and edit pin-numbers (if needed)
  • Upload
  • Done

Long version

What you need

Arduino board

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 (N64/Gamecube) (5V is 16MHz and 3.3V 8MHz, so timings are different and 16MHz code doesn't work for N64/Gamecube with 3.3V version). 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.

Example of Arduino Pro Micro:

Arduino Pro Micro

Computer with Arduino IDE

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.

Joystick library for Arduino IDE

https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-1.0 (note that only version-1.0 works. version-2.0 is incompatible)

Joystick(s) or gamepad(s) and way to connect them to Arduino

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. 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. Example in Hardware folder.

Example of NES-controller wiring:

NES wiring

Setup

  • Download and install Arduino IDE: https://www.arduino.cc/en/Main/Software

  • Tools->Board->Arduino Leonardo

    In Arduino IDE you have to select board. In 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. Connect now your board ATmega32u4 through USB, the RX and TX leds should blink (if not, try another USB port).

  • Tools->Port->COMx

    Arduino IDE shows 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 (Armbian Linux), port was /dev/ttyACM0. In Windows environment, do not use any USB HUB, it may interfere with the comunication with ATmega32u4 board.

  • Test your programming environment and upload

    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.

  • Install joystick library (needed only with some controllers - check list at top of this page)

    Go to https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-1.0 and press Clone or download -> Download ZIP. Extract Joystick2 folder from zip to %HOMEPATH%\Documents\Arduino\libraries (Windows) or ~/Arduino/libraries (Linux).

    After extraction check that you have files %HOMEPATH%\Documents\Arduino\libraries\Joystick2\Joystick2.h and Joystick2.cpp or ~/Arduino/libraries/Joystick2/Joystick2.h and Joystick2.cpp. Close and start Arduino IDE again so it searches and finds library.

    Playstation analog controller RetroJoystickAdapter_PlaystationAnalog.ino needs Joystick\Joystick.h and Joystick\Joystick.cpp.

  • Load RetroJoystickAdapter.ino to Arduino IDE (check right filename from list at top of this page)

    Select controller by commenting and uncommenting and edit pin-numbers (if needed).

  • Press Upload

  • If you got the message "all done" and no errors, your done here.

Time to Enjoy

MS Windows

  • You should go now to Control Panel -> All Control Panel Items > Devices and Printers (some Windows versions in Game Controllers) and try to find Arduino Leonardo device. Right click on Gamepad controller definitions > double click in one of the options (1st is the controller one, and the 2nd is the controller two) and you can now test the buttons.
Notice With Windows!

If you move adapter to other Windows machine, you may have to install the arduino drivers. To have the last updated ones, just download the file Windows ZIP file for non admin install from the page https://www.arduino.cc/en/Main/Software. After the download, unzip the folder. Go to the Computer > right click > Manage > Device Manager > Unknown devices > right click > Update Driver Software > Browse my computer for software > Browse... > and try to find the folder \arduino-1.6.xx\drivers inside the folder you unziped before. Click Next and Windows should install the driver. Arduino would apper as the name Arduino Leonardo inside Ports (COM and LPT) with an associated COM port (like COM9 for example).

Linux

  • Just connect, open your command line and test whit jstest /dev/input/js0.
Notice With Linux!

Linux usbhid-module doesn't support out of box multiple controllers with one USB without USB-hub-features.

You have to give parameter quirks=0x2341:0x8036:0x40 (first numbers are VID and PID of Arduino) to usbhid-module.

Here is example how to do it with RetrOrangePi 2.5.2:

  • Make backup of /boot/boot-retro.cmd and /boot/boot.scr
  • Edit /boot/boot-retro.cmd setenv bootargs -line and add usbhid.quirks=0x2341:0x8036:0x40 to kernel parameters.
  • sudo mkimage -C none -A arm -T script -d /boot/boot-retro.cmd /boot/boot.scr
  • Reboot
  • Check with cat /proc/cmdline

Lakka 2.0:

  • Remount r/w: mount -o rw,remount /flash
  • Make backup: cp /flash/boot.scr /flash/org.boot.scr
  • Make file /flash/boot.cmd:
setenv machid 1029
setenv bootm_boot_mode sec
setenv bootargs console=ttyS0,115200 boot=/dev/mmcblk0p1 disk=/dev/mmcblk0p2 consoleblank=0 usbhid.quirks=0x2341:0x8036:0x40
fatload mmc 0 0x43000000 script.bin
fatload mmc 0 0x42000000 KERNEL
bootm 0x42000000

mkimage -C none -A arm -O u-boot -T script -n "Lakka Boot" -d /flash/boot.cmd /flash/boot.scr

  • (you need to get mkimage from somewhere (e.g. use Armbian), because it is not included in Lakka)
  • Reboot
  • Check with cat /proc/cmdline

Tutorial

There is simple tutorial in Tutorial folder. We tried to make it as clear as possible, so even if you are not familiar with coding, you may can do modifications to it (example add a button).

Misc

Changing VID/PID so Windows and Linux works without drivers or quirks

Linux problem with multiple controllers are solved with changing VID and PID to something that already has HID_QUIRK_MULTI_INPUT (0x40) activated in kernel. Here you can see what quirks are activated to different VID/PIDs: https://github.com/torvalds/linux/blob/master/drivers/hid/usbhid/hid-quirks.c

In these instructions, USB_VENDOR_ID_MOJO 0x8282, USB_DEVICE_ID_RETRO_ADAPTER 0x3201 are used.

Edit C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt (update 26.7.2022: C:\Users\[USER]\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5) or in linux arduino-x.x.xx/hardware/arduino/avr/boards.txt (close Arduino IDE before editing):

# leonardo.build.vid=0x2341
# leonardo.build.pid=0x8036
leonardo.build.vid=0x8282
leonardo.build.pid=0x3201
# leonardo.build.usb_product="Arduino Leonardo"
leonardo.build.usb_product="Retro Joystick Adapter"

WARNING!

There is possibility that serial port is not recognized after VID/PID change. We have tested with two Windows 10 machine and Linux with no problems. If you "brick" your Arduino, you get it back to life with resetting it rapidly two times in a row (grab a wire and make a shunt with RST->GND, they are located between A3, VCC and RAW) and then upload sketch (example blink.ino) with normal Arduino VID/PID. Be quick, because you have only 8 seconds to start uploading (try to hit Send button before make the reset).

Changing number of buttons in joystick-library

If you want that less than 16 buttons are shown in joystick-settings, edit Joystick.cpp/Joystick2.cpp/Joystick3.cpp "USAGE_MAXIMUM"-line (0x10 = 16). You may to have create new project after that, because all libraries are not recompiled every time and we don't know how to force full recompile.

Menu for multiple adapter names

Adapter shows as "Arduino Leonardo", but if you want it to show some other name, edit C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt (update 26.7.2022: C:\Users\[USER]\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5). You can even add sub menu to tools-menu by adding these lines (after editing boards.txt, you have to close and reopen Arduino IDE):

menu.usb_name=USB Product Name
leonardo.menu.usb_name.leonardo="Leonardo"
leonardo.menu.usb_name.leonardo.build.usb_product="Arduino Leonardo"
leonardo.menu.usb_name.leonardo_1="Genesis 6"
leonardo.menu.usb_name.leonardo_1.build.usb_product="Genesis 6-button adapter"
leonardo.menu.usb_name.leonardo_2="Genesis 3"
leonardo.menu.usb_name.leonardo_2.build.usb_product="Genesis 3-button adapter"
leonardo.menu.usb_name.leonardo_3="NES"
leonardo.menu.usb_name.leonardo_3.build.usb_product="NES-adapter"
leonardo.menu.usb_name.leonardo_4="SNES"
leonardo.menu.usb_name.leonardo_4.build.usb_product="SNES-adapter"

New board to Arduino IDE

If you add new board to Arduino IDE, it survives from Arduino IDE updates. Copy boards.txt to {sketchbook folder}\hardware\retroadapter\avr\.

Restart Arduino IDE and select Tools -> Board -> Arduino Pro Micro Retroadapter.

It changes VID to 0x8282 and PID to 0x3201 (Keio Retro Adapter).

Arduino Uno R3

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): https://github.com/NicoHood/HoodLoader2

Software USB

USB-device without ATmega16u2/32u4. Needs 3 resistors and 2 zener diodes.

https://www.obdev.at/products/vusb/index.html

PS/2

PS/2-keyboard can be connected directly to Arduino and there is library for that.

http://playground.arduino.cc/Main/PS2Keyboard

USB host

You can also use Arduino vice versa. You cannot read USB with normal Arduino, but there is shields to make Arduino as USB host. With that you can connect modern USB-joysticks and gamepads to old consoles.

https://github.com/felis/USB_Host_Shield_2.0

Level shifting and voltage levels

Converter

Very handy level converter with 3.3V AMS1117 regulator. Search from Ebay with Logic Level Converter Module AMS1117 DC 5V to 3.3V

Level converter with AMS1117

Playstation, 3.3V, 3.7V or 5V?

There is contradictory data about Playstation controller voltages. I have one commercial adapter and it's 5V. I haven't measured official Playstation, but it is probably 3.3V.

Wii extension controllers

Wii extensions are 3.3V, but I have used Wii Nunchuck and Classic Controller with 5V (VCC and signals) without problems.

Konami code

You can also enable or disable Konami-code-shortcut with some controllers. For now it works only with Genesis 6-button controller (X+Y+Z+UP (or DOWN)), SNES-controller (X+Y+R1+UP (or DOWN)) and PSX-controller (rectangle+circle+triangle+UP (or DOWN)). "UP"-version is normal and "DOWN"-version swaps A and B. 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.

https://en.wikipedia.org/wiki/Konami_Code https://en.wikipedia.org/wiki/List_of_Konami_code_games

Other ideas

Of course Arduino can be used many other ways. Add a PIR motion detector module from Ebay (under $2) and your computer wakes up from sleep when you walk to room. Just read PIR-sensor data pin and if it is 1, send some keyboard button (which normally does nothing) to computer so it wakes up. Or make info-board to your kitchen or hallway wall from old Android tablet and it turns on backlight only when someone goes to kitchen.

Links

Arduino

http://playground.arduino.cc/Main/InterfacingWithHardware

NES

http://www.mit.edu/~tarvizo/nes-controller.html

SNES

http://wiki.superfamicom.org/snes/show/Schematics,+Ports,+and+Pinouts

https://github.com/burks10/Arduino-SNES-Controller

Sega Megadrive / Genesis

https://www.cs.cmu.edu/~chuck/infopg/segasix.txt

https://jonthysell.com/2014/07/26/reading-sega-genesis-controllers-with-arduino/

Playstation

http://www.gamesx.com/controldata/psxcont/psxcont.htm

http://playground.arduino.cc/Main/PSXLibrary

http://problemkaputt.de/psx-spx.htm#controllersandmemorycards

Playstation Dualshock:

https://gist.github.com/scanlime/5042071

Nintendo 64 / Gamecube:

https://github.com/NicoHood/Nintendo

https://github.com/brownan/Gamecube-N64-Controller

Wii Classic Controller:

https://github.com/robotgeek/WiiClassy

http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Classic_Controller

Gamecube / N64

http://www.int03.co.uk/crema/hardware/gamecube/gc-control.htm

https://github.com/NicoHood/Nintendo/wiki/Gamecube

PC Engine/Turbografx

(I don't have this controller, so it is not implemented, but it should be implemented very easily)

https://emu-docs.org/PC%20Engine/tg16cont.html

MSX

https://www.msx.org/wiki/Joystick_control

How to reset Arduino (in case of emergency)

https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/troubleshooting-and-faq#ts-revive

C64 Mini

https://www.tsb.space/projects/c64-mini-arcade2usb-converter

arduino-usb-hid-retrojoystickadapter's People

Contributors

adrianoafonso avatar alex-ong avatar mcgurk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-usb-hid-retrojoystickadapter's Issues

Sketch for PS2 not detected as /dev/input/jsX

Hello!
The project looks very cool and promising, but I got stuck with HID core.
I am using RetroJoystickAdapter_Playstation.ino, and in debug mode it seems to work fine, joystick state can be easily read from the console.

When I plug it in, /dev/input/mouseN+1 appears, but not jsX device.
What am I doing wrong?

The sketch does not use Joystick2 library, is that correct?

This is my first time touching HID devices with Mega32U4, so sorry for stupid questions

The Joystick2 library can only be used with a USB MCU

Hello, I'm trying to compile the x-arcade.ino but I'm getting the following error:

x-arcade:59: error: #error The Joystick2 library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).
 #error The Joystick2 library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).
  ^
x-arcade:63: error: #error "legacy HID core (non pluggable)"
 #error "legacy HID core (non pluggable)"
  ^
exit status 1
#error The Joystick2 library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).

I'm using Arduino Nano V3, HID version 1.0.0 and HID-Project 2.4.4

Can you help me?

C64MINI / THEC64 - NES joystick to USB works on PC but not on C64Mini :(

Hey there
I had the great idea of using a Quickshot joystick designed for NES for the C64 Mini.
I have successfully connected a Quickshot joystick for C64 to the C64mini, but the advantage of using the NES version is the additional buttons that can map to the "MENU" button that's on the C64mini's supplied joystick.

I am using RetroJoystickAdapter.ino with an Arduino Pro Micro and this works perfectly on a PC with emulators etc, but I cannot get this to work on the C64Mini. The closest I get is for the buttons to work but never the X and Y axis.

I have to use the following PID and VID in boards.txt for buttons to be recognised :
VID: 22BA
PID: 1020

If I use the suggested VID and PID, the C64Mini completely ignores the device.

Is anyone able to offer any pointers please? This reports as 2 devices but I'm cabled to port 1 and all works as expected on a Windows PC.

Why not a simple double paddle with 1 buttons for each one?

I'm so happy for your retrojoystick adapter (Atari/Msx with 2 buttons), so I would suggest a similar things for 2 paddles.

My idea is based on 1 potentiometer + 1 button for each paddle in a similar way of double joystick adapter.
Do you think it's doable?

Better pinout documentation?

Not really an issue, but more so a suggestion. When users land here and absorb the entirety of the docs (readme, system folders, code comments), they may be left with a few stumbling points just because they docs aren't aligned on a 'default' pinout. For example, building the megadrive circuit I printed out the nice color pinout image from the system folder (actually the color birds nest didn't help much, but the tables on the side were nice... also note that some boards are labeled MOSI/MISO/SCK not 14/15/16). Then I flashed the default code and noticed player 1 worked fine, but p2 was all backasswards. I went in code and saw right away those images went along with the second set of pin definitions in the code.

So in this case, it seems like it might be best to change the default code to use pinouts that match the schematic images, since most users landing here will use that image to build right away.

On another note, some more docs may need to be added to things here and there as time is available. For example the atari code is posed fairly generically, but it isn't clear it works with 2 button controllers, paddles, or rotary Atari controllers. Looks to me like it just does 1 or 2 button joysticks... that needs to be spelled out clearly, because when folks see "Retro Atari Controls", that includes many other types of controls (that aren't so easy to code for every type, and doing so with a micro/leonardo will require additional circuitry).

NES Zapper integration, suggestion

Been going back and forth with this for a couple of days trying to understand how to integrate the two Zapper NES controller pins. There's romhacks that make a zapper usable on any type of display http://neslcdmod.com/schemes/

Got it wired in the same way as above with trigger to arduino pin 5 and the light sensor to arduino pin 6, I'm able to make the light sensor return a signal (all controller buttons+dpad flicker on and off quickly as I point the zapper at a light), the wiring and light sensing works great. But I can't figure out how to code it to make the trigger and light sensor convert into a single on/off USB controller button press when they activate.

Would be great to have the two unused zapper pins integrated for the RetroJoystickAdapter project, for an all-in-one 2x controller adapter and zapper adapter.

Any help is greatly appreciated!

RetroJoystick

In RetroJoystickAdapter_Atari.ino:

How many fire buttons are defined?
I see 6 pins for every joystick. So 4 for direction and 2 fire? (Pin A1,A2,3,4 are fire buttons?)
//DB9 (8=GND): 1 2 3 4 5 6 7 8 9
const uint8_t inputPinsPort1[] = { 5, 6, 7, 8, A2, 0, 0, 0, 4};
const uint8_t inputPinsPort2[] = {10, 16, 14, 15, A1, 0, 0, 0, 3};

in code:
Row 54 = 0x29, 0x01, /* USAGE_MAXIMUM (Button 1)
Row 56 = 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
is it right for 2 fire buttons for every player? (I see Max = 1, but the fire buttons are 2)
How is the max number of fire buttos?

Is this plug and play like a real gamepad?

Thanks

PC Engine/Turbografx support

I'd like to suggest adding PC Engine/Turbografx pads support as there are few commercial adapters for these.
Some schematic of the interface are here.

X-Arcade .ino files naming confusion

Hi, just found out your project and i was thrilled to know that i could get to use my old dual x-arcade working through ps2 to usb adapter but i quite didnt get what is the difference with the two .ino files
in the project dir
x-arcade.ino & x-arcade_c64.ino
Can you please clear it up for me so i can flash away? Thanks

Genesis 6 button

I followed the passes and got to ride, but the x, y, z and MODE buttons do not work, is there any option that needs to be activated in order for them to work?

Can't upload C64_joystick_atmelstudio hex file

I downloaded the hex file for this joystick adapter and when I try to use avrdude to upload I get the below errors:

avrdude: invalid file format '\Users\cvsch\Documents\Arduino\ATARI_USB/CLASS_JOYSTICK1.hex' in update specifier
avrdude: error parsing update operation 'flash:w:C:\Users\cvsch\Documents\Arduino\ATARI_USB/CLASS_JOYSTICK1.hex'

The command I am using is:

C:\WINDOWS\system32>"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -v -v -v -pm32u4 -c avr109 -PCOM14 -D -V -Uflash:w:C:\Users\cvsch\Documents\Arduino\ATARI_USB/CLASS_JOYSTICK1.hex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.