Live data from Hacker News

Building a USB SNES Controller

blog.chybby.com

71–80 of 101 posts

Re: Building a USB SNES Controller

#71
post #48

Earlier quoted context omitted.

It's extremely loose! Using a custom PCB to connect the controller over RJ45 to a custom Pi hat I wrote some code to simply display the button presses on screen, to test the functionality of the controller (we are modifying hundreds). I had to play around a lot with the timings to match up the response of the program with the speed of my finger pushing a button, else the program would return "you pushed B" a dozen ti…

The physical switches may actually bounce, so you might need some debounce logic, if it wasn't the shift register glitching out. It's pretty common for buttons to need this, often seen in keyboard firmware as well for similar reasons, the physical mechanism actually will oscillate a bit between states.

The way the NES and SNES work is that once per frame you read from the memory address mapped to the shift register to get all the bits out, one at a time. For certain inputs you only care if it's pressed now. Others you compare to previous state to see if it changed.

Bounce could, theoretically, cause an input to be read as a non-input if it just bounced at exactly the wrong time, but it won't cause multiple inputs, as it's only polled every 1/60th of a second.

Re: Building a USB SNES Controller

#72
post #39

Are there any implications of the polling rate not quite aligning as the original controller would've?

If for the sake of argument we are plugging this into an SNES emulator running at 60Hz, then the stack between the USB gamepad and the emulator already has to handle that the gamepad is not rigidly synced to the emulated SNES and will presumably take every input from the gamepad and use it as the emulated input to the SNES next time it asks, unless a new one comes in first.

At slightly faster than 60Hz, the net effect will be that the delay between input and having an effect on the SNES will wander about 1/60th of a second over time, as the sync varies, and every once in a while a particular input will be overwritten before it makes it into the emulator. It may be very difficult to perceive this, though, due to other delays already built into such a set up. On a real SNES, it would be right on the edge of perception anyhow.

Being very close to the poll rate but not quite there is probably near the theoretically worst case. It would probably be much better to poll at 240+Hz, cutting the latency between input to a consistent 1/4ish of a frame. However, I doubt this improvement could be "felt" by very many people at all.

Re: Building a USB SNES Controller

#73
post #39

Are there any implications of the polling rate not quite aligning as the original controller would've?

Yeah I too wondered why the author would target 60Hz at all. The fact that the SNES controller is polled at 60Hz is simply a consequence of the game reading the input at that rate. As mentioned in the other comment in this setup the polling of the controller is not in sync with the game reading the input at all. Thus even if you target a polling rate of 60Hz perfectly you'd actually have worse input latency than the original hardware.

It would be much better to target 120Hz or higher to reduce input latency and bring it as close to the original hardware as possible by ensuring there is always an up-to-date input state ready for the game to read.

Re: Building a USB SNES Controller

#75
Controllers are surprisingly super easy to work with and a good gateway to some basic electronics hacking.

I've actually gone the opposite direction from this post. I have a Neo Geo arcade board (JAMMA) and it has plugs for Neo Geo controllers (as in the controllers for the console version of the Neo Geo). I wanted to use the Neo Geo without plugging it into an arcade cabinet, so I got a "Supergun" board to play it on an RGB monitor. However, I didn't have a controller for it.

I noticed that there was an emulator-based "Neo Geo X" system out in the wild and you could purchase a controller accessory on its own, so I got one, not realizing it was purely a USB controller in the shape of the original Neo Geo ones, but no problem. I bought a Neo Geo controller cable and just desoldered the button to USB connections inside the controller and connected them directly to the Neo Geo controller cable. Worked like a charm!

Re: Building a USB SNES Controller

#76
post #4
post #2

Of course completely awesome to make a modification like this. However, if you yourself want a USB SNES controller, consider buying one instead. 8BitDo offers them with the SN 30 Pro - the quality is good, they work with the Nintendo Switch or PC (including Linux), they have the additional buttons needed for modern games, there is a wired and a wireless version and the newer variant has afaik a replaceable battery (u…

I did try different 8BitDo controllers, and one issue with them is the "multi-mode": in order to make them work with Android/iOS/Windows/whatever, you need to press some key before connecting them, to change the way the OS recognizes the input. Which is a deal-breaker for small children, and prevents keeping things simple (e.g. "remember to disconnect and reconnect the USB before turning the power on", e.g. when usin…

[deleted]

Re: Building a USB SNES Controller

#77
post #75

Controllers are surprisingly super easy to work with and a good gateway to some basic electronics hacking. I've actually gone the opposite direction from this post. I have a Neo Geo arcade board (JAMMA) and it has plugs for Neo Geo controllers (as in the controllers for the console version of the Neo Geo). I wanted to use the Neo Geo without plugging it into an arcade cabinet, so I got a "Supergun" board to play it o…

And I'll add my controller hacking as well:

https://imgur.com/a/Mu43dqg

As a poor college student, I home-built a dance pad for Dance Dance Revolution, out of wood and foil and by soldering the connections into a controller. Worked perfectly!

Re: Building a USB SNES Controller

#78
post #75

Controllers are surprisingly super easy to work with and a good gateway to some basic electronics hacking. I've actually gone the opposite direction from this post. I have a Neo Geo arcade board (JAMMA) and it has plugs for Neo Geo controllers (as in the controllers for the console version of the Neo Geo). I wanted to use the Neo Geo without plugging it into an arcade cabinet, so I got a "Supergun" board to play it o…

And I'll add my controller hacking as well: https://imgur.com/a/Mu43dqg As a poor college student, I home-built a dance pad for Dance Dance Revolution, out of wood and foil and by soldering the connections into a controller. Worked perfectly!

Well done and good job using what looks like a cheap controller and aluminum foil to keep costs down. :)

Re: Building a USB SNES Controller

#80
post #74

Is Arduino real-time? I.e. is a 6 millisecond delay guaranteed to actually be 6 milliseconds?

The Arduino is a single-threaded microcontroller running a single code loop, plus interrupts.

delayMicroseconds is a busy-wait loop, so is relatively precise (to within a few instruction's execution time.

However, interrupts can happen during that sleep, and the time spent handling interrupts won't be accounted for properly.

It isn't a real real-time system, but for a project like this, it'll be good enough.

Post reply on HN