ArcadeHID - Multi-HID Arcade Interface

by baritonomarchetto in Circuits > Arduino

917 Views, 4 Favorites, 0 Comments

ArcadeHID - Multi-HID Arcade Interface

IMG_20210610_082604.jpg
IMG_20210610_082615.jpg

If you are an arcade enthusiast you surely know how important is to have the right peripheral for the right game.

Genuine arcade controls are not plug-and-play, and special interfaces are needed to convert user inputs into something PC's can recognize and handle. There are a lot of commercial products to choose from, and sometimes it could be difficult to make the right choice.

In this Instructable I will show you how easy it is to interface most common Arcade peripherals to Arduino, expecially with the use of this simple shield: ArcadeHID.

I will also share with you a link to have ArcadeHID's printed circuit board manufactured at PCBWay, who kindly sponsored it.

Let's do that!

ArcadeHID - What Is It?

If you are facing a new arcade project, the first question to answer is: which interface board should I use?

There are literally dozens of commercial interfaces out there, an this makes difficult to orient yourself in the selection of the right one. Wouldn't it be nice to have a single interface capable of handling most arcade peripheral? :)

Well, this interface is out there since 2012 and is called Arduino Leonardo.

What makes Arduino Leonardo the right choice for arcade projects is:

- it can handle both digital and analog inputs

- It can natively emulate all human interface devices (HID) software emulators asks for to play: keyboards, mouse and joypads (no more need for joypad-keyboard-mouse hacks!)

- There are tons of libraries and examples to help you writing your code. You don't need to be a coder to write an Arduino sketch for Arcade use!

Ok, nice, but you didn't answer to the main question: what is ArcadeHID?

ArcadeHID is a very simple Arduino shield for arduino pro-micro, but also a collection of simple code pieces that in my intentions will help simplify the realization of any DIY arcade project, also by helping to break down the psychological barrier most Arcaders have when face-to-face with the "mistique of coding".

You can have your ArcadeHID manufactured directly from PCBWay at THIS LINK (PCBWay): select your favourite color, place the order, source components, get it delivered to you, assemble it and have fun with your new arcade project!!

Joysticks and Buttons

arcadeHID-button.png

Joysticks and buttons are the most common arcade peripherals.

They consist of simple non latching switches: when the button (or the joystick direction) is pressed, the switch is closed; when released the switch is open.

Connecting switches to any ArcadeHID D# (digital) or DA# (digital/analog) pin will let the board see the state of the switch and, with the appropriate sketch uploaded, emulate a keyboard (or gamepad) keypress accordingly.

In the attached picture you can see how to wire a classic arcade button. Notice that only two of the three button pins are connected: COM to ground (GND) and NO (Normally Open) to D10.

The simple sketch "ArcadeHID - buttons.ino" at THIS link (Github) will emulate an "a" keyboard key press every time a switch/button connected to pin D10 is closed. It will also emulate a "b" keyboard key press every time a switch connected to pin D14 is closed. The "Buttons" function is written in the more readable (verbose) way I could think of and you can easily modify it to add up to 17 buttons (total).

To avoid "false state change detections" (any actual switch "bounces" when pressed) there's also a simple but effective debounce routine.

Arcade Steering Wheels and Analog Pedals

arcadeHID-potentiometer.png

Racing cabinets where common when arcades where in auge. There are two main types of arcade wheels: optical wheels (also known as "360°"), and potentiometer wheels (also known as "270°"). In this step we are referring to analog, potentiometer wheels (optical wheels will be discussed in the next step).

Despite their dimensions, 270° wheels are made up of a simple, single potentiometer. The potentiometer is wired in a so called "voltage divider" configuration, with two pins connected to ground or logical +5V, the third pin (generally the central pin, called "wiper") returning a voltage from 0 to +5V as a function of the rotating position.

The exact same potentiometer technology defining the rotating position of the wheel was often used for pedals in arcade games asking for more control over the pedal position.

Be it a steering wheel or an analog pedal, in our emulators environment, ArcadeHID gets the variable voltage at one of it's analog pins (DA#) from the potentiometer wiper and translate it as an analog stick (gamepad stick) movement. In the attached picture, analog pin DA0 is used as input pin.

Being that ArcadeHID has 4 analog pins wired (DA0, DA1, DA2 and DA3), you can connect up to 4 analog devices.

In order to emulate a joypad we are in the need for the joystick library, a brilliant piece of software Matt Heironimus wrote and still maintain for the arduino community. Installation instructions are pubblished HERE (Github).

In the example "ArcadeHID-potentiometer.ino" at THIS link (Github) a potentiometer wiper pin is connected to ArcadeHID's pin DA0 and it's positions translated into analog stick movements on the X-axis.

Spinners, Trackballs and 360° Wheels

arcadeHID-optical.png
IMG_20210610_114944.jpg
spinner.png

In a nutshell, both spinners, trackballs and optical wheels are rotary optical encoders. An optical encoder is an electromechanical device that uses a light source (emitter), photosensitive detectors, and an optical grating to convert rotary or linear position to an electrical signal. One emitter-detector couple determines the speed of the grating, the other the direction of movement.

We are not going to see in deep how an optical encoder work because so much has already been written and some "google-fu" will suffice if you are curious (and you should to better understand the function I will write down here).

For what concerns this Instructable, the only important thing to note is that, despite they look very very different, spinners, optical wheels and trackballs are the same thing "under the skin", the only difference being the number of optical encoders used: spinners and wheels have one optical encoder (one axis of movement), trackballs have two encoders (two axis of movement).

To have those peripheral working with our PC, one approach is to have their movement translated in mouse movement. This is a simple task for arduino. In the example "ArcadeHID-optical.ino" at THIS LINK (Github) the two emitter-deterctors of a spinner are connected to ArcadeHID's pins D2 and D4.

Please, notice that pins D1, D2, D3 and D7 are "special" digital pins being that they support interrupts routines. This means that every time a state change is detected (a change from LOW to HIGH in my example), the function associated with the pin is run, and every other function put on hold until the interrupt routine has ended. This is useful for those applications where timing is important. This means that you can handle up to 4 optical axes (i.e. 4 spinners, 2 trackballs or 2 spinners and a trackball...) with single interrupt routines like the one I have posted in the link above.

The function uses only one interrupt pin, but it is possible to change it to have both emitter-detector couples "interrupting" the main code when a state change is detected. I have toyed with this and, for me, there's no need for two. This is not carved in stone, anyway, and you could change it in every moment. This is the great advantage an open firmware device gives us!

Please notice that different optical devices could have different pinout with respect to the one I posted.

​Acknowledgments

The ArcadeHID printed circuit board (PCB) pictured in this instructables was sponsored by those nice girls and guys at PCBWay - PCB Prototype The Easy Way. Their customers service is excellent and PCB's of the best quality.

Thanks!