Help with sega genesis controller

Hi, i am new to arduino but know a bit of C so the language wasn't hard to pick up. I was looking around for something to do with my new arduino and noticed my old sega genesis/megadrive controllers. i got a pinout from pinouts.ru and hooked it up to the arduino. I have genesis pins 7 and 8 connected to ground and pin 5 connected to 5v. pin 1-6(excluding 5) are connected to digital 1-5 respectively. I do not know much about how coontrollers work, my program is just supposed to display what if a button is being pressed after reading it, if it is not pressed the output is "none".
For some reason, it always senses left and start when they are read even if they are not pressed and it never senses right even when it is pressed. If anyone can help me understand more about the genesis controllers or can help me optimize my code that would be greatly appreciated. this is my code:

int up;
int down;
int left;
int right;
int a;
int start;

void setup()
{
Serial.begin(9600);
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
}
void loop()
{
up = digitalRead(0);
if (up == LOW)
{
Serial.println("up");
delay(1000);
}
if (up == HIGH)
{
Serial.println("none");
}
down = digitalRead(1);
if (down == LOW)
{
Serial.println("down");
delay(1000);
}
if (down == HIGH)
{
Serial.println("none");
}
left = digitalRead(2);
if (left == LOW)
{
Serial.println("left");
delay(1000);
}
if (left == HIGH)
{
Serial.println("none");
}
right = digitalRead(3);
if (right == HIGH)
{
Serial.println("right");
delay(1000);
}
if (right == LOW)
{
Serial.println("none");
}
a = digitalRead(4);
if (a == LOW)
{
Serial.println("a");
delay(1000);
}
if (a == HIGH)
{
Serial.println("none");
}
start = digitalRead(5);
if (start == LOW)
{
Serial.println("start");
delay(1000);
}
if (start == HIGH)
{
Serial.println("none");
}
}

ok, that code isnt going to do anything. you are reading the output lines without driving the input lines. the gamepad expects a control signal to be put into it before anything will happen. let me read up on it and ill get back with how to drive it.

msarnoff.org - USB Adapter for Sega Genesis Controller <-- protocol info

ok. so it looks like all you have to do is provide power and drive the Sel line high and low

like this

void setup()
{
pinMode(selpin, OUTPUT);
}

void loop()
{
digitalWrite(selpin,HIGH);
//code to read the outputs.
digitalWrite(selpin,LOW);
//read the output pins again, but keep in mind the buttons read are different
}

also, using a bunch of ints is an inefficient way of using data. integers hold 16 bits of data. each button state is a 1 or a 0, so you only need 1 bit to store its value. look at the bitRead() and bitWrite() functions. they will let you write a 1 or a 0 to a bit in a variable instead of using all the bits to store 1 value. you will need 1 bit per button, so for 10 bits you can get away with using an 1 integer instead of 10 of them.

ok, so would my code look something like this:

int reading;

void setup()
{
Serial.begin(9600);
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
pinMode(7,OUTPUT);
}
void loop()
{
digitalWrite(7,HIGH);
bitWrite(reading,0,digitalRead(0));
if (bitRead(reading,0) == 0)
{
Serial.println("up");
delay(1000);
}
bitWrite(reading,1,digitalRead(1));
if (bitRead(reading,1) == 0)
{
Serial.println("down");
delay(1000);
}
bitWrite(reading,2,digitalRead(2));
if (bitRead(reading,2) == 0)
{
Serial.println("left");
delay(1000);
}
bitWrite(reading,3,digitalRead(3));
if (bitRead(reading,3) == 0)
{
Serial.println("right");
delay(1000);
}
bitWrite(reading,4,digitalRead(4));
if (bitRead(reading,4) == 0)
{
Serial.println("a");
delay(1000);
}
bitWrite(reading,5,digitalRead(5));
if (bitRead(reading,5) == 0)
{
Serial.println("start");
delay(1000);
}
digitalWrite(7,LOW);
bitWrite(reading,0,digitalRead(0));
if (bitRead(reading,0) == 0)
{
Serial.println("up");
delay(1000);
}
bitWrite(reading,1,digitalRead(1));
if (bitRead(reading,1) == 0)
{
Serial.println("down");
delay(1000);
}
bitWrite(reading,2,digitalRead(2));
if (bitRead(reading,2) == 0)
{
Serial.println("left");
delay(1000);
}
bitWrite(reading,3,digitalRead(3));
if (bitRead(reading,3) == 0)
{
Serial.println("right");
delay(1000);
}
bitWrite(reading,4,digitalRead(4));
if (bitRead(reading,4) == 0)
{
Serial.println("b");
delay(1000);
}
bitWrite(reading,5,digitalRead(5));
if (bitRead(reading,5) == 0)
{
Serial.println("c");
delay(1000);
}
}

still, when i press nothing it read right and left and then when i press other buttons it never reads the right thing or just doesn't read at all. i will recheck my wiring but i think it is right. this probably has something to do with that switching pin, even though i thought i had accounted for that in the code, maybe not. thanks for your help.

ok, well heres some code you can try. also, whenever you post code, hit the pound icon in the post menu and put your code inbetween it. it makes it easier to read.

int reading;

void setup()
{
  Serial.begin(9600);
  pinMode(0,INPUT);
  pinMode(1,INPUT);
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  pinMode(6,INPUT);
  pinMode(7,OUTPUT);
}
void loop()
{

int bitcounter = 0; //which bit to read
int digitalLine = 0; //which digital line to read
digitalWrite(7,HIGH);
delay(3); //let the data lines settle
while(bitcounter < 12)
{
 digitalLine = 0;
  while(digitalLine < 7)
  {
    bitWrite(reading,bitcounter,digitalRead(digitalLine));
    digitalLine++;
    bitcounter++;
  }
  digitalWrite(7,LOW);
  //let the data lines settle
}
  
  
int counter = 0;
while(counter < 12)
{
  if (!bitRead(reading,counter))
  { Serial.println(counter);
  }
  counter++;
}

}

I see what you are doing with that code, using loops to read input into reading twice once with select high once with low. Although it still isn't working, i am just getting a bunch of 6,3, and 10's no matter what i press. i think it might be the wiring, they don't fit in the sockets too tight and i think that might be causing strange data and noise to come through. thanks for your help though, your code really does help me understand it better.

its completely possible. if you have some led's and resistors laying around you might throw together a quick circuit to check things out. tie select to high, wire ground and +5, then hook the led's up with negative lead on the controller, and positive to +5 volts. since the output goes low when the button is pressed only the led that is hooked up to the button will light up, as opposed to every led lighting except for the button you pressed.

it definitely is static, the LEDS would not light up but i could jiggle the connector and they would light up and blink and do all sorts of things. so the signal obviously isn't good. guess i need larger leads. thanks for your help anyways.

no problem. most old controllers are pretty easy to use, so if you cant get the genesis to work, old nintendo controllers work great. they're essentially just shift registers connected to buttons.

Hi

Can you turn them into usb devices for emulation use ?