Marv007
Posts: 9
Joined: Sat May 03, 2014 7:24 pm

Re: Multi-console gamepad driver for GPIO

Wed May 14, 2014 7:43 pm

theDavis wrote:Hey Marv,

Could you post an explanation/simple diagram of how you connected those two chips? I'm wondering if the flakiness of some of my 3rd party controllers is due to using 3.3v logic rather than 5v. I'm fairly new to the hardware level (software guy), and think I get the general idea from the datasheets, but just want to make sure I'm getting it.

Thanks!
Hi theDavis. Of course I'll post the diagram. Does this make sense:

Code: Select all

          VCC - DIR  01     20 VCC - 3.3V P1
    CON1 DATA -  AO  02  7  19 OE  - GND P6
                     03  4  18 B0  - GPIO0 P3
                     04  L  17
                     05  V  16
                     06  C  15
                     07  2  14
                     08  4  13
                     09  5  12
       P6 GND - GND  10     11



       P6 GND - 1OE  01     20 VCC - 5V P2
   P19 GPIO10 - 1A0  02  7  19
                     03  4  18 1Y0 - CLK CON
   P23 GPIO11 - 1A1  04  H  17
                     05  C  16 1Y1 - LCH CON
                     06  T  15
                     07  2  14
                     08  4  13
                     09  4  12
       P6 GND - GND  10     11



       P6 GND - GND  .
                CLK  .  N  . 5V - 5V P2
                LCH  .  E  .
               DATA  .  S  .
With Pxx I mean a pin number on the Pi. It's based on Rev 1

theDavis
Posts: 5
Joined: Fri Aug 17, 2012 6:21 pm

Re: Multi-console gamepad driver for GPIO

Wed May 14, 2014 11:58 pm

Marv007 wrote:
Hi theDavis. Of course I'll post the diagram. Does this make sense:

Code: Select all

          VCC - DIR  01     20 VCC - 3.3V P1
    CON1 DATA -  AO  02  7  19 OE  - GND P6
                     03  4  18 B0  - GPIO0 P3
                     04  L  17
                     05  V  16
                     06  C  15
                     07  2  14
                     08  4  13
                     09  5  12
       P6 GND - GND  10     11



       P6 GND - 1OE  01     20 VCC - 5V P2
   P19 GPIO10 - 1A0  02  7  19
                     03  4  18 1Y0 - CLK CON
   P23 GPIO11 - 1A1  04  H  17
                     05  C  16 1Y1 - LCH CON
                     06  T  15
                     07  2  14
                     08  4  13
                     09  4  12
       P6 GND - GND  10     11



       P6 GND - GND  .
                CLK  .  N  . 5V - 5V P2
                LCH  .  E  .
               DATA  .  S  .
With Pxx I mean a pin number on the Pi. It's based on Rev 1
That's perfect, thanks!

User avatar
DigitalLumberjack
Posts: 336
Joined: Thu May 22, 2014 8:55 am
Location: France
Contact: Website

Re: Multi-console gamepad driver for GPIO

Thu May 22, 2014 9:35 am

Hello, i'm currently trying to connect my nes pad ton my raspberry pi REV 2.

I installed gamecon module and it loads without problem.

I first connected data wired on GPIO 2 (GPIO0 for rev1) and GPIO3 (GPIO1 for rev1). I could not receive any data from the controller with jstest.

Then i connected my data wire on GPIO4 and loaded the driver as follow :

Code: Select all

sudo modprobe gamecon_gpio_rpi map=0,0,2
and running the jstest program show something interesting :

No button pressed :
Axes: 0: 0 1: 0 Buttons: 0:off 1:off 2:off 3:off

A button pressed :
Axes: 0: 0 1: 0 Buttons: 0:on 1:on 2:on 3:on

I saw that when no button is pressed the controller send 8 bits set to 1


So the state when no button is pressed is 1,1,1,1,1,1,1,1

I tried to see in SNESDev sources the way to read data on pin and made a few printf to see what is happening when i press a button.

I can see that when i pull the A button on the controller, the 8 bits read on the controller change to 1,0,0,0,0,0,0,0.

I cant find a way to correct this by myself.

I tried to read values from the controller from wiringpi with this program :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <wiringPi.h>
#include <piNes.h>

int main(){
	int joystick, buttons;
	if (wiringPiSetupGpio () < 0)
	{
		fprintf (stderr, "Can't setup GPIO: %s\n", strerror (errno)) ;
		exit (1) ;
	}

	if ((joystick = setupNesJoystick (4, 11, 10)) == -1)
	{
		fprintf (stderr, "Unable to setup joystick\n") ;
		return 1 ;
	}
	
	while(1){
		printf("reading joystick\n");
		buttons = readNesJoystick (joystick) ;
		
		printf("result : %d\n", buttons);
		sleep(1);
	}
	if ((buttons & NES_UP) != 0){
		printf("up pressed");
	}
	printf("exiting\n");
	return 0;
}

And all works fine, i have a different value for each button pressed on the controller.

Someone have an idea ?

Thank you.

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Thu May 22, 2014 3:50 pm

The difference between GPIO2/GPIO3 and other GPIOs is pullup strength, but it should not affect the operation.

If you look at the raw output from GPIO, '1' means a button is up and '0' down (=pressed).

So you did not get correct readings with either gamecon or Snesdev, but wiringPi was OK? With a quick look, the only relevant difference I noticed is the delay they use (e.g. PULSE_TIME in piNes.c). Gamecon uses 6us while wiringPi 25us. BTW, which supply (3.3V or 5V) did you use for the controller?
DigitalLumberjack wrote:Hello, i'm currently trying to connect my nes pad ton my raspberry pi REV 2.

I installed gamecon module and it loads without problem.

I first connected data wired on GPIO 2 (GPIO0 for rev1) and GPIO3 (GPIO1 for rev1). I could not receive any data from the controller with jstest.

Then i connected my data wire on GPIO4 and loaded the driver as follow :

Code: Select all

sudo modprobe gamecon_gpio_rpi map=0,0,2
and running the jstest program show something interesting :

No button pressed :
Axes: 0: 0 1: 0 Buttons: 0:off 1:off 2:off 3:off

A button pressed :
Axes: 0: 0 1: 0 Buttons: 0:on 1:on 2:on 3:on

I saw that when no button is pressed the controller send 8 bits set to 1


So the state when no button is pressed is 1,1,1,1,1,1,1,1

I tried to see in SNESDev sources the way to read data on pin and made a few printf to see what is happening when i press a button.

I can see that when i pull the A button on the controller, the 8 bits read on the controller change to 1,0,0,0,0,0,0,0.

I cant find a way to correct this by myself.

I tried to read values from the controller from wiringpi with this program :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <wiringPi.h>
#include <piNes.h>

int main(){
	int joystick, buttons;
	if (wiringPiSetupGpio () < 0)
	{
		fprintf (stderr, "Can't setup GPIO: %s\n", strerror (errno)) ;
		exit (1) ;
	}

	if ((joystick = setupNesJoystick (4, 11, 10)) == -1)
	{
		fprintf (stderr, "Unable to setup joystick\n") ;
		return 1 ;
	}
	
	while(1){
		printf("reading joystick\n");
		buttons = readNesJoystick (joystick) ;
		
		printf("result : %d\n", buttons);
		sleep(1);
	}
	if ((buttons & NES_UP) != 0){
		printf("up pressed");
	}
	printf("exiting\n");
	return 0;
}

And all works fine, i have a different value for each button pressed on the controller.

Someone have an idea ?

Thank you.

User avatar
DigitalLumberjack
Posts: 336
Joined: Thu May 22, 2014 8:55 am
Location: France
Contact: Website

Re: Multi-console gamepad driver for GPIO

Tue May 27, 2014 6:18 pm

Hello marqs thank you for your answer.
I use the 3.3V as power wire.

I made it work since my last post ! With all test i made i exchanged clock and latch on my solderings. I soldered again all wire and it works now !

Thank you !

What a good feeling to play all my childhood games, on a nes, with nes controllers :D

Marv007
Posts: 9
Joined: Sat May 03, 2014 7:24 pm

Re: Multi-console gamepad driver for GPIO

Thu May 29, 2014 8:04 pm

Marv007 wrote:That totally did the trick! It's working perfectly now! Thanks! I was able to get the chips very quickly at my local electronics store and tried them this evening. I connected 2 controllers and they work totally fine simultaneously. I'm going to get 4 snes connectors as well to see if that works. Thanks again!

FYI I used a 74LVC245 and a 74HCT244
I have not yet connected 4 snes controllers at the same time but I did connect 2 nes + 2 snes controllers and they work fine according to jstest. I tried some games and I got mixed results. Chip 'n Dale for nes works fine. Mario Kart for snes works fine. Bomberman 2 for snes can only recognise the first two controllers. But that is of course due to the limited functionality of the emulator I used, is doesn't support multitap. Micro Machines (1 and 2) for snes do not recognise the 2nd, 3rd or 4th controller at all, which is kinda weird.

I've been googling the last few days to see if someone else fixed this problem but I couldn't find a fix. I tried some settings myself but couldn't get 4p to work. Pocket SNES probably has no support for multitap whatsoever. Snes9x-rpi does not support it either. Both of them seem to be abandoned.

So your driver works perfectly fine but the emulators are a bit lacking. Oh well, 2p is working at least.

LifeAsASuffix
Posts: 11
Joined: Mon Jan 07, 2013 1:10 am

Re: Multi-console gamepad driver for GPIO

Fri Jun 27, 2014 1:52 am

im having an odd issue with the GPIO driver on boot. I've tried everything i can think of to track down and remedy the issue.. So far I've reinstalled the RetroPie script, installed the whole system from scratch, installed the gamecon driver from the retropie script, and manually. When i reboot the system the driver does not seem to load. I'm booting to emulationstation, where the controllers are not recognized. I can exit emulation and type "sudo modprobe gamecon_gpio_rpi map=0,0,0,0,7,7" and everything works until i reboot again.
anyone have any ideas? I'm stumped.
Thanks
-Ed

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Fri Jun 27, 2014 5:51 am

LifeAsASuffix wrote:im having an odd issue with the GPIO driver on boot. I've tried everything i can think of to track down and remedy the issue.. So far I've reinstalled the RetroPie script, installed the whole system from scratch, installed the gamecon driver from the retropie script, and manually. When i reboot the system the driver does not seem to load. I'm booting to emulationstation, where the controllers are not recognized. I can exit emulation and type "sudo modprobe gamecon_gpio_rpi map=0,0,0,0,7,7" and everything works until i reboot again.
anyone have any ideas? I'm stumped.
Thanks
-Ed
Did you add the corresponding line (gamecon_gpio_rpi map=0,0,0,0,7,7) to /etc/modules? Modprobe-command only loads the driver for the running kernel. This info seems to be missing on wikipage, I'll add it there shortly.

LifeAsASuffix
Posts: 11
Joined: Mon Jan 07, 2013 1:10 am

Re: Multi-console gamepad driver for GPIO

Fri Jun 27, 2014 11:31 pm

marqs wrote: Did you add the corresponding line (gamecon_gpio_rpi map=0,0,0,0,7,7) to /etc/modules? Modprobe-command only loads the driver for the running kernel. This info seems to be missing on wikipage, I'll add it there shortly.
You are amazing! I knew it was something simple I was missing. Thanks that fixed my issue!

joostvanpoppel
Posts: 24
Joined: Mon Jan 27, 2014 2:26 pm

Re: Multi-console gamepad driver for GPIO

Tue Jul 01, 2014 2:24 pm

Download link in first post seems to be broken, what is the link to use?

thanks,
Joost

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Tue Jul 01, 2014 5:51 pm

joostvanpoppel wrote:Download link in first post seems to be broken, what is the link to use?

thanks,
Joost
The driver is nowadays part of RetroPie-project, and you can install it by selecting the corresponding option in RetroPie-Setup
-script.

andreatax
Posts: 18
Joined: Wed Jun 25, 2014 10:24 pm

Re: Multi-console gamepad driver for GPIO

Fri Jul 04, 2014 10:24 pm

marqs wrote:
joostvanpoppel wrote:Download link in first post seems to be broken, what is the link to use?

thanks,
Joost
The driver is nowadays part of RetroPie-project, and you can install it by selecting the corresponding option in RetroPie-Setup
-script.
I couldn't find it no more, was this cancelled from retropie 2.1?

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Sat Jul 05, 2014 7:22 am

andreatax wrote:
marqs wrote:
joostvanpoppel wrote:Download link in first post seems to be broken, what is the link to use?

thanks,
Joost
The driver is nowadays part of RetroPie-project, and you can install it by selecting the corresponding option in RetroPie-Setup
-script.
I couldn't find it no more, was this cancelled from retropie 2.1?
Apparently, RetroPie is currently under reorganization and that option seems to be missing now. I assume it will be added back shortly - meanwhile you can install the drivers manually as follows:

Code: Select all

wget http://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/linux-headers-`uname -r`_`uname -r`-2_armhf.deb
wget http://www.niksula.hut.fi/~mhiienka/Rpi/gamecon-gpio-rpi-dkms_0.9_all.deb
wget http://www.niksula.hut.fi/~mhiienka/Rpi/db9-gpio-rpi-dkms_0.7_all.deb
dpkg -i linux-headers-`uname -r`_`uname -r`-2_armhf.deb
dpkg -i gamecon-gpio-rpi-dkms_0.9_all.deb
dpkg -i db9-gpio-rpi-dkms_0.7_all.deb

andreatax
Posts: 18
Joined: Wed Jun 25, 2014 10:24 pm

Re: Multi-console gamepad driver for GPIO

Sat Jul 05, 2014 4:48 pm

Thank you,

now I tried
modprobe gamecon_gpio_rpi map=0,0,7,7,0,0 psx_delay=14

with ps2 controller but jstest give me no response, no button or axis works...

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Sat Jul 05, 2014 4:50 pm

andreatax wrote:Thank you,

now I tried
modprobe gamecon_gpio_rpi map=0,0,7,7,0,0 psx_delay=14

with ps2 controller but jstest give me no response, no button or axis works...
Try setting psx_delay to 25 or above. Is that controller official or 3rd-party? I also forgot to mention that gcc-4.7 should be installed before the drivers (normally done by RetroPie).

andreatax
Posts: 18
Joined: Wed Jun 25, 2014 10:24 pm

Re: Multi-console gamepad driver for GPIO

Sat Jul 05, 2014 5:02 pm

Thank for quick reply :)

It's an original Ps2 controller scph 10010

Gcc-4.7 already installed and I tried with delay 30 or more but doesnt work

EDIT: DATA pin was connected with GPIO3 but if i do:
tail /var/log/kern.log

I see : psx controller as devices/virtual/input/input3
psx conrtoller data pin connected to gpio4

same thins with input4 connected to gpio7


Do I connected data pin wrongly?

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Sat Jul 05, 2014 5:30 pm

andreatax wrote:Thank for quick reply :)

It's an original Ps2 controller scph 10010

Gcc-4.7 already installed and I tried with delay 30 or more but doesnt work
Hmm, I've heard a few similar reports so there's probably some issue in the driver code. I try to acquire one of those models and check if I can reproduce the issue.

andreatax
Posts: 18
Joined: Wed Jun 25, 2014 10:24 pm

Re: Multi-console gamepad driver for GPIO

Sun Jul 06, 2014 7:54 am

Thanks but DATA psx pin where should goes ?

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Sun Jul 06, 2014 12:24 pm

andreatax wrote:Thanks but DATA psx pin where should goes ?
Depends on how you have configured the driver. If you loaded it with gamecon_gpio_rpi map=0,0,7,7,0,0, you must connect the data pin of your first controller to GPIO4, and the second to GPIO7 as kernel log suggests (the wording is a bit misleading, it should say that 'gpio4 configured for psx controller data pin' etc.). The driver README (/usr/share/doc/gamecon_gpio_rpi/README.gz) has more details on the configuration options.

andreatax
Posts: 18
Joined: Wed Jun 25, 2014 10:24 pm

Re: Multi-console gamepad driver for GPIO

Sun Jul 06, 2014 2:34 pm

Thank you so much, now works with jstest !

Was a problem about PINs because on gamecon_gpio wiki there was an old revision of the PIN to GPIO

Another question
How to make controller works from boot?
Because now I need to write command everytime...

marqs
Posts: 207
Joined: Sat Jun 09, 2012 11:34 am

Re: Multi-console gamepad driver for GPIO

Sun Jul 06, 2014 3:45 pm

andreatax wrote:Thank you so much, now works with jstest !

Was a problem about PINs because on gamecon_gpio wiki there was an old revision of the PIN to GPIO

Another question
How to make controller works from boot?
Because now I need to write command everytime...
Ok, good to hear it wasn't a driver issue after all. The wikipage under RetroPie project doesn't have a direct PIN->GPIO map as there are several configuration possibilities (there's only a general pinout image plus a remark on different RPi revisions) - did you mean some other wikipage?

In order to load the driver at bootup, you can add the corresponding line (e.g. gamecon_gpio_rpi map=0,0,7,7) to /etc/modules .

andreatax
Posts: 18
Joined: Wed Jun 25, 2014 10:24 pm

Re: Multi-console gamepad driver for GPIO

Mon Jul 07, 2014 8:22 am

Thank You, now all works Pretty well!

For the wiki, i was referring to retropie official wiki.. There is a picture of rpi pins But with another GPIO configuration.. There is a NOTE warning this that I didnt Read :-)

jon-whit
Posts: 7
Joined: Sun Oct 12, 2014 8:37 pm

Re: Multi-console gamepad driver for GPIO

Sun Oct 12, 2014 8:51 pm

I'm really loving all of this community support for old school gaming :D . I really want to start to contribute back to the community. First things first though. I'm having issues getting my SNES controller working. I went through the install process with the retropie_setup.sh script. I enabled the SNESDev on boot and SNESDev keyboard mapping. I have female pins that I have crimped onto the ends of the controllers output wires, and I have connected them as follows:

Vcc -> Pin 2 (5v)
GND -> Pin 6
Data -> GPIO22 (Pin 15)
Latch -> GPIO23 (Pin 16)
CLK -> GPIO24(Pin 18)

When I run ES it recognizes my keyboard, but it doesn't recognize the game controller. I guess I don't understand what I am doing wrong. I'd be willing to add more documentation clarity for the various revision, it seems like this is missing from the setup process.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10938
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Multi-console gamepad driver for GPIO

Sun Oct 12, 2014 9:05 pm

You shouldn't power the controller with 5V, as the chip in the controller will then also output a 5V data signal, which in time will damage the PI! The GPIO's are NOT 5V compatible.

Also, when powered with 5V the chip may not respond to the 3.3V control signals, as it needs "high" signals of at least 70% of VDD, which for VDD=5V is 3.5V, which explains why it doesn't work too.

The 74HC4021 chip inside the controller works fine with voltages as low as 3.0Volt.

Image

jon-whit
Posts: 7
Joined: Sun Oct 12, 2014 8:37 pm

Re: Multi-console gamepad driver for GPIO

Sun Oct 12, 2014 9:27 pm

mahjongg wrote:You shouldn't power the controller with 5V, as the chip in the controller will then also output a 5V data signal, which in time will damage the PI! The GPIO's are NOT 5V compatible.

Also, when powered with 5V the chip may not respond to the 3.3V control signals, as it needs "high" signals of at least 70% of VDD, which for VDD=5V is 3.5V, which explains why it doesn't work too.

The 74HC4021 chip inside the controller works fine with voltages as low as 3.0Volt.

Image
Great info. Thanks! I have also tried 3.3V input supply, and I have the same issue.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 7 guests