JorgeP
Posts: 11
Joined: Thu Dec 07, 2017 12:37 am

USB Joystick/Gamepad with Python HowTo - Raspberry Pi 3

Thu Dec 07, 2017 1:06 am

You want to attach a USB Joystick? Attaching a USB Joystick works automatically in the current version of Raspbian, but the default is setup to make it work as a mouse. I don't want to use the Joystick as a mouse so I needed to first disable that feature in the XFCE desktop.

To disable USB joystick as mouse (default in XFCE/Raspbian) edit the following file by opening a shell window and typing(Note this is a system wide edit):

Code: Select all

sudo leafpad /usr/share/X11/xorg.conf.d/50-joystick.conf
make sure the file reads as follows to disable the Joystick as mouse:

Code: Select all

Section "InputClass"
	Identifier "joystick catchall"
	MatchIsJoystick "on"
	MatchDevicePath "/dev/input/event*"
	Driver "joystick"
	Option "StartKeysEnabled" "False"       #Disable mouse
	Option "StartMouseEnabled" "False"      #support
EndSection
its as simple as that to disable the Joystick as a mouse! Now restart your Raspberry for the settings to be applied.

If you want to use the USB Joystick through python without additional software, I found the following script on github that is an example of how to read nearly any setting the joystick/steering wheel could have: https://gist.github.com/rdb/8864666 the script, when run as is, does not close the file pointer as far as I can see so if you kill the script the file pointer may still be open, always close the file pointer when you are done or the world may stop rotating :shock: !

I thought I would post this here to help anyone who may be having trouble disabling the Joystick as a mouse when using it in Python :D

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 18 guests