Emulators

A USB game controller with an Arduino Pro Micro and Nintendo Switch thumbsticks

by Cory on October 10, 2020 10:00 PM (Edited October 11, 2020 5:40 PM)

I couldn't decide how to package up this update, but I don't think the fully detailed update will be ready for a while. In the meantime, I'm just gonna post a "journal update" instead.

So last time I said I was gonna work on the buttons and viola! here they are:

What you can see above is a breadboard that I've wired up a bunch of buttons to an Arduino pro micro. In the second video I bought a replacement Nintendo Switch thumbstick and wired it to the Arduino as well.

I was initially a little intimidated about doing this because I had no idea how to make buttons, but it turned out to be a lot easier to setup than I thought. It's still difficult because there's so many tiny little parts and things that need to come together for the full experience, but software-wise, a lot of stuff is already done for you.

I used an Arduino pro micro, which is a tiiiiny version of the arduino mounted on a small PCB that has 16 pins and a usb micro interface. The best part about this is you can get chinese knock-offs for real cheap (like $2 per) off Amazon or Aliexpress.

The arduino community also has developed a library for making USB devices. HID is a standard that describes how a computer should communicate with USB peripherals. It's a general protocol that lets people make new peripherals that computers can still understand, given that both sides follow the protocol. I just stumbled upon this through some quick google searches. I found this amazing blog post that explains the theory and history of the protocol. It's technically not necessary to understand this to build the gamepad, but it is really educational.

The NicoHood lirbary gives you a Gamepad device wrapper complete with an example. The documentation is a little sparse, but still workable. All I had to worry about is how to wire up the buttons to the arduino.

I got push buttons from an arduino starter kit to prototype with and I wired up 4 in a pull-up resistor configuration:

I spent a lot of time looking up how to get analog sticks on this thing. I initially wanted to use the 3ds circle pad, but after looking into it, the 3ds pad is really inconvenient. There's like the thumbstick module itself, a thumbstick cap, a washer, and a dust shield that you need to buy before even thinking about trying to fit it into the case. That's a lot of pieces and not to mention that it could cost like $10 per thumbstick when it all adds up.

At the same time, I bought some replacement thumbsticks for the Nintendo Switch. While these are a full fledged analog stick, I really like the appearance and compact form factor of the 3ds ones. It's too bad. Maybe someday I can develop my own design from scratch. But in the meantime, the switch thumbsticks are great. They're cheap (again $2 per), and they come fully assembled. Much fewer parts. Basically all you need to do is cut a hole of the right size and add in a gasket to collect dust. Another big difference was that the switch thumbsticks could click in like the playstation/xbox controllers while the 3ds analog stick isn't designed for that.

Testing this was a pain. The first hurdle, ironically, was trying to figure out what everything was called so I could search it on the internet. Here's some facts:

The ribbon cable coming out of the thumbstick module is called an "FPC" (fine pitch connector). You need to measure the width between wires coming out of the cable, which is called "pitch". Also you need to count the number of wires coming out of it. This number is known as the "number of positions".

I found this extremely helpful webpage that lead me to the terminology above. I was able to track down the FPC connector (white plastic part in the previous picture) on digikey. And then I found this page with an explanation of the thumbstick pinout.

Next I needed to solder this connector down to a PCB to use it in a breadboard. This was kind of a pain. I found a cheap 0.5mm FPC breakout board for this. Soldering surface mount components is its own art, but I decided to wing it with my shitty inadequate tools. It worked for now, but I'm going to need to upgrade if I make it to the final PCB making phase. I dabbed some solder onto the contacts after heating them up. Then I use the soldering iron head to wick up the excess solder until there was a thin layer and no unintended bridges. Then I put the component down and reheated the contacts until it stuck.

Here's a close up of the board after I soldered everything:

Once I attached the thumbstick, I cut out a little section of padded paper to mount both parts to. Also, I spent a while debugging the connections because I couldn't get the pins to change when fiddling with the analog stick. After a surprise nap, I woke up and realized that the analog stick was in "upside-down" when I checked the datasheet.

Here you can see I flipped it and then everything just started working! So that's another thing I learned today. When you buy FPC's off digikey they will also be specified to be "Bottom contacts", "top contacts", or "top and bottom contacts". This refers to the contacts on the interior of the connector and that determines what orientation the cable should be when you connect it. Mine was contacts on the bottom, so I had to flip it over because the switch analog stick exposed its contacts facing upward...

So right now I'm at the point where I can get windows to recognize my device and it sees me moving the joystick. However, trying to configure this thing in retropie is giving me an issue. For some reason, it won't recognize the analog movements as buttons, so I can't set them in the configuration wizard.

I noticed that while the analog stick should give you x and y axis values between 0 and 1024 (with 512 being the middle), I'm only getting a range of between 200 and 865 from the switch joystick. I modified my arduino program to compensate for this, but retropie still doesn't recognize this.

TO BE CONTINUED



This Thought is part of Emulators

Cory tries to make the perfect handheld emulator

back to the

top