Wednesday 5 October 2022

8-bit joystick adapter using Arduino

One day, I was looking for a 9-pin joystick ("Atari" or "Kempston") to modern PC adapter. After some disappointments, I googled for a comparable DIY Arduino project and found what I wanted from here:

https://hackaday.io/project/9552-digital-joystick-8-bit-to-usb-adapter

There isn't anything to code, as the functioning joystick examples are already supplied with the library. But as the instructions are a little on the short side I thought I'd add my experiences.

Firstly, the Arduino I had installed from the Linux repository was too old. Most of my time was wasted trying to get the library to work, whereas if I'd just downloaded the latest IDE, I could have added the library very easily.

One way to do this is to download the library as a zip, then use the Add .ZIP library function from the Arduino IDE menu. It's possible the IDE may need to be re-run. If the library has been installed, the GamepadExample can be selected from the File -> Examples -> Joystick submenu.

Not just any Arduino board can do this. Arduino Micro and Leonardo are seen as HID devices, so they can pretend to be joysticks, mice and keyboards depending on what you tell them to do. I had to buy an Arduino Micro to even try this.

ArcadeStickExample may sound attractive, but it requires an Arduino Micro Pro instead! Obviously a single-button arcade style joystick could work here.

The hackaday page isn't very explicit about which wires to connect to which pins, although the GamepadExample.ino will give some pointers.

Adapter port view pins:

 1 - Up to Arduino digital pin 2
 2 - Down to Arduino digital pin 4
 3 - Left to Arduino digital pin 5
 4 - Right to Arduino digital pin 3
 5 - Not Connected
 6 - Fire to Arduino digital pin 6
 7 - 5V (Not Connected)
 8 - GND to Arduino GND
 9 - Not Connected

I'm unsure of connecting the 5V to Arduino 5V, it looks like it was enough to connect the ground (GND).

It's also possible to have multiple joysticks, but I don't need that now.

Quick and unscientific lag-test: On Vice 64 I tried Buck Rogers, Commando, Decathlon, Giana Sisters, H.E.R.O. and Stunt Car Racer and Giana Sisters (again) on Amiga emulator.

With some of the more crisp C64 games I could perhaps see tiny bit of lag but not more than Raspi BMC64 or The 64 Mini/Maxi. All within sensible limits to me, and possibly not even because of the adapter really. Playing 50hz games on 60hz display is all kinds of wrong to begin with, anyway. Stunt Car Racer on the Amiga felt pretty good.


Building the box

I toyed with the idea of placing the Arduino inside my main PC, and have the 9-pin port through the casing. At the other extreme, I thought about putting the adapter inside a joystick.

But it's of course best to have it as a separate adapter after all.

For once, I thought it would be better to build the box from something else than chipboard or wood. Looking around, an old Mini-DV cassette case looked the right size.

I cut a prototyping board with 3x1 islands to the precise inside dimensions of the box so it would be held in place even without screws. The 9-pin connector required a large hole at the other end of the box. As the proto board was now in the way I simply cut a hole in it.

As the wires needed more space this proved to be insufficient and I cut the whole board shorter, as can be seen from the above picture. But it stays in place well enough.

Also, to save space the Arduino had to be soldered directly to the proto board. I cut excess pins from top and bottom as the wires needed some more room. A different positioning could have helped here. I didn't foresee it but in a way longer wires could have been easier to fit.

The micro-USB connector was initially meant to stick out neatly of the box, but because of all the mess with the wires, the port is a little deeper. Another idea was the box would also keep the USB cable in place, but the box is a little too flimsy to help keep the cable in place. Also I didn't want to make the cable a permanent part of the adapter.

So, the usual story, a relatively clean and well-intentioned project becomes messy at the point when soldering and wires are needed. I had to cut and whittle the box in so many places the end result is no longer very robust, but it will do. It keeps the things inside cleanly enough.

No comments:

Post a Comment