Close
0%
0%

Mega2USB

USB/HID adaptor for Sega Mega Drive/Genesis controllers

Similar projects worth following
80 views
0 followers
I wanted to be able to connect my original Sega Mega Drive controllers to my RetroFlag MegaPi running RetroPi, so I built a USB HID adaptor from a Digispark Pro clone...To keep things simple (and small) I used an ATTiny167 which (practically) limits support to 2 controllers. But if you buy a bigger Arduino (ie. more GPIO pins) the codebase is ready to support 4 controllers.Full code and schematics on Github: https://github.com/csBlueChip/Mega2USB

The Voltage Divider

The AtTiny167 didn't have enough pins for two controllers so, for each port, I made a voltage divider out of three resistors which allows two digital inputs to be read by one analogue GPIO pin.  You can see the circuit working here.

You need two big resistors and one small. The small one needs to be "about 70.2%" the size of the large one ...I chose 10K and 6.8K

They are all joined together at one end. One of the large resistors goes to Gnd, the remaining two resistors go to the two pins you wish to read.

If you use different size resistors, you will need edit RG_OHM, and R9_OHM in the source code ...then some unreadable macros will do all the maths for you :)

Microcontroller Support

I forked the Digistump repo, and updated the USB library to obdev's latest USB code. This means Mega2USB will work on most Atmel chips.

WARNING: For some reason Digistump decided that every example would have its own copy of the USB code. So it is ONLY Mega2USB that has the latest USB code!

I also believe I am the first person to make (publicly) a multi-device [TWO joysticks adaptors] USB profile, so you might find some useful code laying around in the main directory :) ...Everything I release is MIT licensed : "free as in free".

3 & 6 Button Controllers

The code will auto-detect both 3-button and 6-button (in both 3-button and 6-button mode) Mega Drive controllers, and all buttons will trigger unique HID Joystick events ...So you can easily test your device with joy.cpl (WIndows) or `jstest` / `jstest-gtk` (Linux)

How do the Controllers work?

It's not trivial, but neither is it Rocket Surgery ...and it is all explained on the Github page, and in Wiring.txt in the example folder - which will open automatically if you use the Arduino IDE to compile the code.

Connector Physical Support

Connecting the Mega Drive controllers takes quite a lot of force - make sure your ports are firmly supported.

In my device the lower port is braced by the base of the (pressed steel) sweet tin, and the top port is braced with a scored-and-folded coffee shop loyalty card.

I got the sweet tin (with sweets) as a Christmas present, but the barcode is the photo if you want to try and find one online.

The Future

I can think of many exquisitely pointless features you could add:

  • Use M on 6-Button to affect auto-fire
  • Add das blinken LEDs ...surely this project would be better with an LED to tell you whether you just connected a 3 or 6 button controller!
  • Add internal logic for auto-fire and a switch to enable/disable it.
  • Add a button to press UP, DOWN, LEFT, RIGHT, A+Start
  • Buttons to allow you to press UP+DOWN or LEFT+RIGHT

MegaUSB.zip

Full source code - see ReadMe.txt and Wiring.txt in the 'examples' folder

x-zip-compressed - 145.92 kB - 09/30/2020 at 00:49

Download

  • 1 × DigiSpark Pro [clone] / AtTiny167
  • 4 × 10K resistor
  • 2 × 6.8K resistor
  • 2 × 9-Pin D-Sub Male connector

  • 1
    Circuit diagram
    [5v0]---+-------+--------------------------------[5v0]
            |       |
            |       | ,------------------(4)---------[GPIO-D7]
            |       | | ,----------------(3)---------[GPIO-D2]
            |       | | | ,--------------(2)---------[GPIO-D1]
            |       | | | | ,------------(1)---------[GPIO-D0]
            |       | | | | |
            |    .--|-|-|-|-|--.
            |     \ 5 4 3 2 1 / DB9/1
            |      \ 9 8 7 6 /
            |       `|-|-|-|'
            |        | | | |
            |        | | +-}------------(Clk)--------[GPIO-D8]
            |        | | | |      R16
            |        | | | `-----^v^v^---+-------+---[GPIO-A6]
           (5)       | | |               |       |
            |        `-}-}-------^v^v^---'       >
            |          | |        R19            < R1G
            |  .--(8)--+ |                       >
            |  |       | |        R29            |
            |  |     ,-}-}-------^v^v^---+---+---{---[GPIO-A5]
            |  |     | | |               |   |   |
            |  |     | | | ,-----^v^v^---'   |   |
            |  |     | | | |      R26        |   |
            |  |     | | | |                 |   |
            |  |    ,|-|-|-|.                >   |
            |  |   / 9 8 7 6 \           R2G <   |
            |  |  / 5 4 3 2 1 \ DB9/2        >   |
            |  | '--|-|-|-|-|--`             |   |
            |  |    | | | | |                |   |
            `--}----' | | | `---------(1)----{---{---[GPIO-D9]
               |      | | `-----------(2)----{---{---[GPIO-D10]
               |      | `-------------(3)----{---{---[GPIO-D11]
               |      `---------------(4)----{---{---[GPIO-D12]
               |                             |   |
    [Gnd]------+-----------------------------+---+---[Gnd]
    
    Resistors: Rxy ->  x -> Controller number
                       y -> Pin Number / Ground
    
    RxG == Rx9 == 10K
           Rx6 == 6.8K  (~70.2% of Rx9)
    
  • 2
    Code

    Either download the source from here, or github (probably Github, as that will get realtime updates)

    Place the code in : /path/to/.../digistump-avr/libraries/MegaUSB

    Restart your Arduino IDE

    Select Mega2USB from the examples menu

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates