Megadrive pad Arduino uno Code via Unojoy

Hi everyone,

I tried out a few codes found on the net but nothing seems to work (for me). Either i have buttons in a state or another (HIGH: A start /LOW B C) but not together.

Every pin of the DB9 pad is in a digital inputof the uno (except pin 0 & 1) pin 5:+5V pin 8: Ground

Pin 7 is the select button (as OUTPUT).

Anyone have an idea ?


Ok I found out !

I used this code :

[#include "UnoJoy.h"

int up = 2;
int down = 3;
int left = 4;
int right = 5;
int ab = 6;
int slct = 7; //setting this pin HIGH/LOW reads A/B and Start/C
int startc = 8;

void setup() {
  for (int i = 2; i <= 6; i += 1){
    pinMode(i, INPUT);
  } //pins 1-6 inputs
  pinMode(slct, OUTPUT); //'select' pin is an output
  pinMode(startc, INPUT);

void loop() {
  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData); //Unojoy loop taken from example sketch

dataForController_t getControllerData(void) {
  dataForController_t controllerData = getBlankDataForController();
  digitalWrite(slct, LOW); //set 'select' LOW to read A and Start
  controllerData.squareOn = !digitalRead(ab); //UJ data is inverse of pad data
  if (digitalRead(startc) == LOW && digitalRead(up) == LOW) { 
    controllerData.homeOn = HIGH; //Start and Up for Home button
  else {
    controllerData.homeOn = LOW;
    controllerData.dpadUpOn = !digitalRead(up); 
    controllerData.startOn = !digitalRead(startc);  
  if (digitalRead(startc) == LOW && digitalRead(down) == LOW) {
    controllerData.selectOn = HIGH; //Start and Down for Select Button
  else {
    controllerData.selectOn = LOW;
    controllerData.dpadDownOn = !digitalRead(down); 
  digitalWrite(slct, HIGH); //set 'select' HIGH to read B and C
  controllerData.dpadLeftOn = !digitalRead(left);
  controllerData.dpadRightOn = !digitalRead(right);
  controllerData.crossOn = !digitalRead(ab);
  controllerData.circleOn = !digitalRead(startc);
  return controllerData;
} /code]

But you have to create a unojoy folder containing unojoy.h in you library folder as follows:

Next simply configure inputs in your emulator(I personnaly prefer Kega fusion: great video and sound options) and you're ready to go !

Good retro gaming ;)