Multi-console gamepad driver for GPIO


243 posts   Page 5 of 10   1, 2, 3, 4, 5, 6, 7, 8 ... 10
by 020110348 » Fri Mar 22, 2013 5:16 pm
Can you add support for Genesis Controllers? Reading about them seems like the coding would be fairly easy, but they would use 7 pins each.
Code: Select all
Pin    Name (Select=GND)    Name (Select=+5V)
1       Up                   Up
2       Down                 Down
3       Gnd                  Left
4       Gnd                  Right
5       +5VDC               +5VDC
6       Button A             Button B
7       Select               Select
8       Ground               Ground
9       Start                Button C
Posts: 18
Joined: Thu Mar 21, 2013 12:07 pm
by marqs » Sat Mar 23, 2013 5:03 pm
020110348 wrote:Can you add support for Genesis Controllers? Reading about them seems like the coding would be fairly easy, but they would use 7 pins each.
I could adapt db9 driver to Pi, which would add support for various Atari, Commodore, Amiga and Sega joysticks/gamepads. I don't have any Genesis pads at hand for testing, but since the interface is so simple (compared to e.g. N64), there's not much which could go wrong. The only potential issue I see is 3.3V compatibility of the 74157 multiplexer chip inside Genesis controller.

I'm quite busy with other projects & work right now, but I'll try to put up a testable version soon.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by smshiera » Mon Mar 25, 2013 5:16 pm
I have some remaining arcade joysticks and buttons(made usb things longtime ago),

Can I make a gpio joystick?
Posts: 37
Joined: Fri Feb 22, 2013 6:59 am
by marqs » Mon Mar 25, 2013 11:42 pm
smshiera wrote:I have some remaining arcade joysticks and buttons(made usb things longtime ago),

Can I make a gpio joystick?
Sure. You'd probably use 6 or more buttons? The db9 driver I'm planning would support 1-2 multisystem joysticks with up to 3 buttons (max. 7 GPIO pins per joystick), though it would be easy to add support for a single arcade stick with up to 10 buttons. There may already be some user-space drivers for this kind of project, so you could check those too. However, I think it'd better to use multiplexer chips inside an arcade stick (as in Sega pads), so that several sticks could be connected to the limited amount of GPIO pins in PI.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by smshiera » Tue Mar 26, 2013 7:53 am
marqs wrote: use 6 or more buttons? The db9 driver I'm planning would support 1-2 multisystem joysticks with up to 3 buttons (max. 7 GPIO pins per joystick), though it would be easy to add support for a single arcade stick with up to 10 buttons.


many VS games need 4 buttons,
so i think max. 8 GPIO pins per joystick is better?
i cant find other drivers for this kind of project with my bad English。。
Posts: 37
Joined: Fri Feb 22, 2013 6:59 am
by marqs » Tue Mar 26, 2013 11:39 pm
I put together a first version of the db9 driver, which now supports 1-2 multisystem joysticks or genesis pads. However, some multisystem joysticks and genesis pads use TTL chips, which most likely won't work with 3.3V, so level shifting will be needed.

I've only tested the driver with simple switches since I don't currently have any multisystem/genesis pads - in case anyone is interested trying out the driver, please PM me and I'll send it with instuctions. I'll make the driver publicly available once it has been tested more extensively with different configurations. Support for Saturn pads (as in the original db9) will also be included in the next version. They use 74HC chips, which should work fine at 3.3V.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by 020110348 » Wed Mar 27, 2013 5:44 pm
Ok ive been playing with this for a while now. 2 nes controllers using PAD3+4, but i cant get PAD1+2 to work. i use the same wiring the same controllers except i move the data from GPIO7 to GPIO 0/1 and nothing. I have a rev1 board.
what can i do? Ive tested that the pins still output correctly, i havent tested input yet, but i dont think thats the problem.
Posts: 18
Joined: Thu Mar 21, 2013 12:07 pm
by marqs » Wed Mar 27, 2013 11:36 pm
020110348 wrote:Ok ive been playing with this for a while now. 2 nes controllers using PAD3+4, but i cant get PAD1+2 to work. i use the same wiring the same controllers except i move the data from GPIO7 to GPIO 0/1 and nothing. I have a rev1 board.
what can i do? Ive tested that the pins still output correctly, i havent tested input yet, but i dont think thats the problem.

Are you sure that you have loaded the module with correct parameters (map=2,2) and that I2C is not in use by any module? The only difference with GPIO0&1 pins is that they have on-board pullup resistors, whereas other pins are configured to use on-chip pullups.

BTW, I'm not using those pins (or GPIO21) with the db9 driver, since their IDs differ between revisions and cause incompatibilities. That leaves 14 usable pins on main GPIO connector, which sets the limit of 7 pins per pad.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Fri Apr 05, 2013 4:11 pm
So I setup my NES controller according to this:

https://github.com/petrockblog/RetroPie ... ontrollers

and I loaded the gamecon_gpio module using map=0,0,0,2 for my NES controller. The data pin is on Pin 26 and my clock and latch are on 19 and 23 respectively. When I run jstest, it doesn't detect keypresses at all.

What are some things I may be doing wrong?
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sat Apr 06, 2013 8:27 am
godzirra wrote:So I setup my NES controller according to this:

https://github.com/petrockblog/RetroPie ... ontrollers

and I loaded the gamecon_gpio module using map=0,0,0,2 for my NES controller. The data pin is on Pin 26 and my clock and latch are on 19 and 23 respectively. When I run jstest, it doesn't detect keypresses at all.

What are some things I may be doing wrong?
You probably have one of those NES controllers that operate only at 5V, so you need to use 5V as the supply pin AND put a level shifter or clamp between NES pad data out pin and GPIO 26. A level shifter IC like 74LVC245 is preferable if you are planning to use multiple NES pads, otherwise you can build a simple clamp with a 3.3V zener diode and ~500ohm resistor.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sat Apr 06, 2013 6:02 pm
You probably have one of those NES controllers that operate only at 5V, so you need to use 5V as the supply pin AND put a level shifter or clamp between NES pad data out pin and GPIO 26. A level shifter IC like 74LVC245 is preferable if you are planning to use multiple NES pads, otherwise you can build a simple clamp with a 3.3V zener diode and ~500ohm resistor.


Thanks for the info! I do plan on having two NES pads. I'm unclear how the clamps work with the zener diode though based on that schematic. Does my data pin get split, going to a zener diode which goes to ground as well as going to a resistor -> 5v power?

Edit: I can get a zener diode now, so I'd like to go that route to start with so I can just get SOMETHING working. I'm ordering the 74LVC245 chip now but it will be a few days.
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sat Apr 06, 2013 8:48 pm
godzirra wrote:
You probably have one of those NES controllers that operate only at 5V, so you need to use 5V as the supply pin AND put a level shifter or clamp between NES pad data out pin and GPIO 26. A level shifter IC like 74LVC245 is preferable if you are planning to use multiple NES pads, otherwise you can build a simple clamp with a 3.3V zener diode and ~500ohm resistor.


Thanks for the info! I do plan on having two NES pads. I'm unclear how the clamps work with the zener diode though based on that schematic. Does my data pin get split, going to a zener diode which goes to ground as well as going to a resistor -> 5v power?

Edit: I can get a zener diode now, so I'd like to go that route to start with so I can just get SOMETHING working. I'm ordering the 74LVC245 chip now but it will be a few days.
Referring to that schematic, nes pad data_out is the "5V_logic_out", Rpi GPIO pin is "3V_logic_in" and all grounds are wired together. 5V GPIO pin is only connected to the power pin of nes pad.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sat Apr 06, 2013 9:00 pm
Referring to that schematic, nes pad data_out is the "5V_logic_out", Rpi GPIO pin is "3V_logic_in" and all grounds are wired together. 5V GPIO pin is only connected to the power pin of nes pad.


Thanks, this helps a ton. Do the grounds not need to also go to one of the GPIO ground pins?
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sat Apr 06, 2013 9:12 pm
godzirra wrote:
Referring to that schematic, nes pad data_out is the "5V_logic_out", Rpi GPIO pin is "3V_logic_in" and all grounds are wired together. 5V GPIO pin is only connected to the power pin of nes pad.


Thanks, this helps a ton. Do the grounds not need to also go to one of the GPIO ground pins?
Yes, ground of nes pad, zener diode anode and GPIO ground pin should be all together.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sat Apr 06, 2013 10:11 pm
marqs wrote:Yes, ground of nes pad, zener diode anode and GPIO ground pin should be all together.


Do the stats on the zener diode matter? I'm heading to Radioshack to pick one up for instant gratification as I don't apparently have any, and I was curious if I should get a specific rating? i.e. 3v 0.5W, 24v 5w, etc.
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sat Apr 06, 2013 10:36 pm
godzirra wrote:
marqs wrote:Yes, ground of nes pad, zener diode anode and GPIO ground pin should be all together.


Do the stats on the zener diode matter? I'm heading to Radioshack to pick one up for instant gratification as I don't apparently have any, and I was curious if I should get a specific rating? i.e. 3v 0.5W, 24v 5w, etc.
It must be a 3.3v zener (3.0v and 3.6v should be fine too if 3.3v isn't available). Wattage is not that important since only a small current passes through it (e.g. 0.5W is fine).
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sun Apr 07, 2013 7:58 pm
marqs wrote:It must be a 3.3v zener (3.0v and 3.6v should be fine too if 3.3v isn't available). Wattage is not that important since only a small current passes through it (e.g. 0.5W is fine).


Okay, I picked up a 3.3v 0.5w zener diode from Fry's and wired it up (I thought?) correctly. I'm still getting nothing. Here's a picture of my setup (Click).

The red wire is power, the yellow wire on the left is clock, the blue is latch, the green is data and the yellow on the right is ground. The resistor is 470 ohms (I didn't have a 500).

I reloaded the module doing this:

sudo rmmod gamecon_gpio_rpi
sudo modprobe gamecon_gpio_rpi map=0,0,0,2

Then I test using this:

jstest /dev/input/js0

The docs say it should be jsX where X is the pad you're on, but I don't have any devices other than js0, and nothing happens when I push the buttons on the NES controller so far. What am I doing wrong here?
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sun Apr 07, 2013 8:26 pm
godzirra wrote:
marqs wrote:It must be a 3.3v zener (3.0v and 3.6v should be fine too if 3.3v isn't available). Wattage is not that important since only a small current passes through it (e.g. 0.5W is fine).


Okay, I picked up a 3.3v 0.5w zener diode from Fry's and wired it up (I thought?) correctly. I'm still getting nothing. Here's a picture of my setup (Click).

The red wire is power, the yellow wire on the left is clock, the blue is latch, the green is data and the yellow on the right is ground. The resistor is 470 ohms (I didn't have a 500).

I reloaded the module doing this:

sudo rmmod gamecon_gpio_rpi
sudo modprobe gamecon_gpio_rpi map=0,0,0,2

Then I test using this:

jstest /dev/input/js0

The docs say it should be jsX where X is the pad you're on, but I don't have any devices other than js0, and nothing happens when I push the buttons on the NES controller so far. What am I doing wrong here?
From you pic it looks like the anode of the diode is connected to 5v instead of gnd.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sun Apr 07, 2013 8:28 pm
marqs wrote:
godzirra wrote:
marqs wrote:It must be a 3.3v zener (3.0v and 3.6v should be fine too if 3.3v isn't available). Wattage is not that important since only a small current passes through it (e.g. 0.5W is fine).


Okay, I picked up a 3.3v 0.5w zener diode from Fry's and wired it up (I thought?) correctly. I'm still getting nothing. Here's a picture of my setup (Click).

The red wire is power, the yellow wire on the left is clock, the blue is latch, the green is data and the yellow on the right is ground. The resistor is 470 ohms (I didn't have a 500).

I reloaded the module doing this:

sudo rmmod gamecon_gpio_rpi
sudo modprobe gamecon_gpio_rpi map=0,0,0,2

Then I test using this:

jstest /dev/input/js0

The docs say it should be jsX where X is the pad you're on, but I don't have any devices other than js0, and nothing happens when I push the buttons on the NES controller so far. What am I doing wrong here?
From you pic it looks like the anode of the diode is connected to 5v instead of gnd.


ARgh, you're right. I moved it over to ground now, but I still get nothing on jstest.
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sun Apr 07, 2013 8:38 pm
godzirra wrote:ARgh, you're right. I moved it over to ground now, but I still get nothing on jstest.
I hope that didn't do any damage. Could you temporarily disconnect the ribbon cable from GPIO connector and connect GPIO7 to GPIO gnd pin? jstest should now report all buttons as 'on'.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sun Apr 07, 2013 8:55 pm
marqs wrote:
godzirra wrote:ARgh, you're right. I moved it over to ground now, but I still get nothing on jstest.
I hope that didn't do any damage. Could you temporarily disconnect the ribbon cable from GPIO connector and connect GPIO7 to GPIO gnd pin? jstest should now report all buttons as 'on'.



I connected pin 26 (GPIO 7) to pin 25 (GPIO gnd) but jstest showed nothing when I ran it on /dev/input/js0

That was after loading the module like this:

sudo modprobe gamecon_gpio_rpi map=0,0,0,2
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sun Apr 07, 2013 9:05 pm
godzirra wrote:
marqs wrote:
godzirra wrote:ARgh, you're right. I moved it over to ground now, but I still get nothing on jstest.
I hope that didn't do any damage. Could you temporarily disconnect the ribbon cable from GPIO connector and connect GPIO7 to GPIO gnd pin? jstest should now report all buttons as 'on'.



I connected pin 26 (GPIO 7) to pin 25 (GPIO gnd) but jstest showed nothing when I ran it on /dev/input/js0

That was after loading the module like this:

sudo modprobe gamecon_gpio_rpi map=0,0,0,2
What do you mean by nothing? It should
give the following output when the input pin is connected to gnd:
Code: Select all
root@raspberrypi:/home/pi# jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (NES pad) has 2 axes (X, Y)
and 4 buttons (BtnX, BtnY, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0 Buttons:  0:on   1:on   2:on   3:on
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sun Apr 07, 2013 9:07 pm
marqs wrote:What do you mean by nothing? It should
give the following output when the input pin is connected to gnd:
Code: Select all
root@raspberrypi:/home/pi# jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (NES pad) has 2 axes (X, Y)
and 4 buttons (BtnX, BtnY, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0 Buttons:  0:on   1:on   2:on   3:on


My mistake. I expected it to show a new line, not rewrite the current line. I do in fact get that when I connect those pins. Sorry.

I also double checked with the cable plugged back in, I still don't get any output on the NES controller.
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm
by marqs » Sun Apr 07, 2013 9:18 pm
godzirra wrote:My mistake. I expected it to show a new line, not rewrite the current line. I do in fact get that when I connect those pins. Sorry.
Ok, good. That means that the pin is still functional if the buttons are reported as 'on'. Now the question is that why the actual pad does not work with the setup - are all buttons 'off' when you try with the pad? That suggests that there's some wire disconnected, but you're probably double checked all the connections - is that green connector from the NES control port?
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by godzirra » Sun Apr 07, 2013 9:22 pm
marqs wrote:
godzirra wrote:My mistake. I expected it to show a new line, not rewrite the current line. I do in fact get that when I connect those pins. Sorry.
Ok, good. That means that the pin is still functional if the buttons are reported as 'on'. Now the question is that why the actual pad does not work with the setup - are all buttons 'off' when you try with the pad? That suggests that there's some wire disconnected, but you're probably double checked all the connections - is that green connector from the NES control port?


Yeah, the green connector is from the NES control port. I hooked it back up to the NES to verify that it and the controllers work as well. I'm trying to avoid chopping the end off the connector, but that' the last thing I can think of is that I'm not getting a good connection shoving the wires in there...

Unless there's something else I wired up wrong. I'm kind of at a loss now... The wires shoved in there seem like they should be making a good connection.
Posts: 14
Joined: Wed Mar 13, 2013 3:23 pm