A couple years ago I tried my hand at building an interface for reading Sega Genesis / Mega Drive controllers with an Arduino. I documented my first attempt with Reading Sega Genesis controllers with Arduino, and my updated version with Sega Genesis controllers and Arduino revisited.
That was three years ago, and I’ve gotten a lot of feedback about those projects. While they worked well enough for me, many people had problems getting my code to work. My research had led me to an implementation that relied heavily on having correct timing delays, and others found they had to constantly tweak those timings.
Of course, as any decent programmer will tell you, if your code relies on a bunch of seemingly random sleeps to work properly, you’re probably doing it wrong. And it turns out I was.
I recently found the Six Button Controller page on SegaRetro, where I gleaned some new vital pieces of information:
- The controller must be cycled through 8 different states.
- Reading the controller involves knowing the current state.
- If the state isn’t changed for 1.5 ms, the controller resets.
Using this information, I decided to take another crack at my Arduino code. And with a little bit of work (not all of the information on the SegaRetro page was accurate) I created a much more deterministic, stable, delay-free program. Taking it a step further, I refactored the code into a proper Arduino library, both to learn how to do that, and to make it much easier for Arduino enthusiasts to use in their own sketches.
So if you’re interested in reading Sega controllers in your Arduino projects, check out my new SegaController Arduino library on GitHub. Replacing the original sketches are two new examples, one which reports the button states via the serial port (good for testing) and one which sends Keyboard key presses (good for driving other software).
Also, since my research into how the controllers worked led me to mixed results (no one’s documentation had it 100% right) I’ve created some documentation on my own in the SegaController wiki at How To Read Sega Controllers.
Enjoy and happy hacking!
9 thoughts on “Introducing the SegaController Arduino library”
You are the best! Thank you!
I have a question. Reading the source code I found that you removed the 2 controllers and leaved only 1. Is there a reason for that? Reading it I can tell that it’s not hard to add one more, but maybe there was a reason to remove it. Thanks!
The original code was an all in-one sketch for two controllers, but IIRC it took up every pin on a uno or leo. So you couldn’t really do much else IO-wise, which is kind of a waste of an Arduino IMHO. If you just want to connect two Sega controllers to a PC via USB, there are cheaper, nicer options that register as actual HID joysticks, not as a keyboard.
When I refactored the code into a library, I wanted to enable users to integrate sega controllers into their Arduino projects. So instead of an entire sketch built around just reading the buttons and reporting them, users have an API they can use like any other hardware device. They can connect as many controllers as they have dedicated pins for.
In order to have examples I added sample sketches that do what the original sketches did, but they aren’t the end goal of the project.
I get it. There is no problem in adding a second controller with different pins then, however both Arduino Leonardo and Arduino Micro have 20 DIO, you’ll need 14 DIO for 2 controllers, leaving only 6 for the rest of the project, so I get your point.
I’m actually doing this to connect 2 controllers to the PC and this was the only real project about it that didn’t involve a parallel port (which I don’t have and I don’t plan in buying a PCI card for, it’ll involve a lot of time and money spent to only work in the PC with the PCI card). And I really don’t have a lot of knowledge in electronics, so I’ll apreciate if you could tell me those cheaper/nicer options. I liked this one because I can buy a cheap Pro Micro and use it as USB in every PC, but if there is something better I’m open to possibilities.
Thanks for your time!
The one I have is from Retro-Bit, it was $12 back in 2013 when I bought it. Looks like they’re harder to come by these days. All I can find in eBay for cheap are made by Mayflash, and I’ve not tried them. https://m.ebay.com/sch/i.html?_nkw=genesis+usb+adapter
Thanks for the information! But I think I’ll keep with the arduino project, actually because those options are quite expensive for my budget (also I can’t find them on Argentina where I live and the shipping cost are way too high, adding to some taxes and the time wait).
However, thanks for introducing me to the arduino world!