PS3 controller doesnt work in GoPigo3

I am using GoPigo3 , PS3 Dualshock controller, Raspberry Pi 3 with Python 2.7 and following the instruction below:

I was able to pair the ps3 dualshock controller using sixpair:
[bluetooth]# devices
Device 00:06:F5:CB:8B:31 PLAYSTATION®3 Controller

while on bluetooth pressing command i can see it is responding however as per the instruction on step 11 to check if it has successfully paired by going to ls /dev/input/js* i get the error “ls: cannot access ‘/dev/input/js*’: No such file or directory”

SInce i thought i am connected i just go ahead and run ps3_gpg_example.py but i get the error “Invalid Joystick device number”. Any suggestion on how to fix this?

Hello from the pygame community. https://www.pygame.org/contribute.html
Initializing
Traceback (most recent call last):
File “ps3_gpg_example.py”, line 37, in
p=ps3() #Create a PS3 object
File “/home/pi/Dexter/GoPiGo3/Software/Python/Examples/PS3_Control/ps3.py”, line 56, in init
ps3.joystick = pygame.joystick.Joystick(0)
pygame.error: Invalid joystick device number

Did you see Connected: yes for your device address in step 7?
Did the trust command (step 8) succeed?
Did you reboot? (Step 9)

When the ls /dev/input/js* failed did you?

Note: if you received
 ls: cannot access /dev/input/js*: No such file or directory
try pairing your controller again by pressing the PS button.

Since you are following a DI article, you might check with support@modrobotics.com to make sure the article is still correct with the latest Raspian kernel update. (Some things broke)

yes i did step 7-9 successfully and yes i encounter that error when checking the /dev/input/ js* i got the same exact error message for PS3 (PS4 controller works until this part though)

for both controller ps3_gpg_example.py will fail with the error message i posted

Just checking: You do not have a PS3 console nearby, or if do it is off, correct?

The fact that you do not see the controller showing up as /dev/input/js0 would seem to be an issue from what I am reading on the Internet.

Have you tried connecting the PS3 controller via USB cable to the Pi? Does the /dev/input/js0 appear when connected via the USB cable?

Another place I read someone remark that you have to first connect the PS3 controller via cable, to reset something in the PS3 controller, then you can disconnect the cable and run the bluetoothctl and sixpair utils.

Once that /dev/input/js0 actually shows up, your program should start finding the joystick.

If you want to test out the joystick (once the /dev/input/js0 shows up), you can add the joystick test program jstest:

sudo apt-get install joystick
...
The following NEW packages will be installed:
  evemu-tools evtest inputattach joystick libevemu3
0 upgraded, 5 newly installed, 0 to remove and 54 not upgraded.
Need to get 113 kB of archives.
After this operation, 393 kB of additional disk space will be used.
Do you want to continue? [Y/n]

enter y or Y and press enter

When it completes (with the PS3 controller connected via USB cable):

jstest /dev/input/js0

should list all the buttons and value configurations.

BUT - it would seem that without the /dev/input/js0 the joystick is not visible to any programs.

Just checking: You do not have a PS3 console nearby, or if do it is off, correct?
ANS: I press PS button to turn on the controller

The fact that you do not see the controller showing up as /dev/input/js0 would seem to be an issue from what I am reading on the Internet.
ANS: I have a PS4 controller and follow the same procedure as in the link below and i can see the PS4 if I check ot via /dev/input/ and infact its js1.

ANother thing i noticed if i ran bluetoothctl, the PS3 will show connected then immediately disconnected. THe light on the PS3 controller continously blinks. WHich i didnt experience when I setup the PS4

Have you tried connecting the PS3 controller via USB cable to the Pi? Does the /dev/input/js0 appear when connected via the USB cable?
ANS: Yes it does get seen as a USB device though

Another place I read someone remark that you have to first connect the PS3 controller via cable, to reset something in the PS3 controller, then you can disconnect the cable and run the bluetoothctl and sixpair utils.
ANS: yes, in the link i gave in step 2 I followed it.THe PS3 controller was plugged in to the robot via USB cable before i run sixpair.THen remove it when i ran bluetoothctl

Once that /dev/input/js0 actually shows up, your program should start finding the joystick.

If you want to test out the joystick (once the /dev/input/js0 shows up), you can add the joystick test program jstest:
ANS: THis i have to try tomorrow once i get in to the office as my robot and PS3 are stored in my locker.

That program is for the GoPiGo original board, have you updated it for the GoPiGo3 that you said you are running?

I updated it for the GoPiGo3 and to Python3 (Python2.7 is being outdated this year), but had to simulate the PS3.

Here is my version (save it as ps3_egpg3_example.py, and run it “python3 ps3_egpg3_example.py”):

#!/usr/bin/env python3
########################################################################
# This example controls the GoPiGo3 and using a PS3 Dualshock 3 controller
#
# http://www.dexterindustries.com/GoPiGo/
# History
# ------------------------------------------------
# Author     	Date      		Comments
# Alan McDonley 10 Feb 20               Adapted for GoPiGo3
# Karan Nayan   11 July 14		Initial Authoring
'''
## License
 GoPiGo3 for the Raspberry Pi: an open source robotics platform for the Raspberry Pi.
 Copyright (C) 2020  Dexter Industries

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
'''
#
# left,right,up,down to control
# cross to stop
# left joy to turn the camera servo
# l2 to increase speed
# r2 to decrease speed
########################################################################
from ps3 import *		#Import the PS3 library
import easygopigo3		#Import the EasyGoPiGo3 library



# simulate the controller
class sim_ps3():
	up = False
	left = False
	right = False
	down = False
	cross = False
	l2 = False
	r2 = False
	a_joystick_left_x = 0
	sim_press = 0

	def __init__(self):
		print("init sim PS3")

	def update(self):
		print("sim_ps3.update()")
		self.sim_press += 1
		self.sim_press = self.sim_press % 5  # legal values 0, 1, 2, 3, 4
		print("sim_press: {}".format(self.sim_press))
		time.sleep(1)
		if self.sim_press == 1:
			self.up = True
			self.cross = False
		elif self.sim_press == 2:
			self.up = False
			self.cross = True
		elif self.sim_press == 3:
			self.down = True
			self.cross = False
		elif self.sim_press == 4:
			self.down  = False
			self.cross = True
		else:
			self.up = False
			self.down = False
			self.cross = False


print("Initializing")
p=ps3()		#Create a PS3 object
# p=sim_ps3()		#Create a simulated PS3 object
egpg = easygopigo3.EasyGoPiGo3(use_mutex=True)

print("Done")


s=150	#Initialize
run=1   # set to 1 to move bot, set to 0 to test joystick
flag=0
while True:
	if run:
		egpg.set_speed(s)	#Update the speed
	p.update()			#Read the ps3 values
	if p.up:			#If UP is pressed move forward
		if run:
			egpg.forward()
		print("f")
	elif p.left:		#If LEFT is pressed turn left
		if run:
			egpg.left()
			flag=1
		print("l")
	elif p.right:		#If RIGHT is pressed move right
		if run:
			egpg.right()
			flag=1
		print("r")
	elif p.down:		#If DOWN is pressed go back
		if run:
			egpg.backward()
		print("b")
	elif p.cross:		#If CROSS is pressed stop
		if run:
			egpg.stop()
		print("s")
	else:
		if flag:		#If LEFT or RIGHT key was last pressed start moving forward again 
			egpg.forward()
			flag=0
	if p.l2:			#Increase the speed if L2 is pressed
		print(s)
		s+=2
		if s>255:
			s=255
	if p.r2:			#Decrease the speed if R2 is pressed
		print(s)
		s-=2
		if s<0:
			s=0
	x=(p.a_joystick_left_x+1)*90
	print(int(x))
	if run:
		servo(int(x))	#Turn servo a/c to left joy movement
	time.sleep(.01)
1 Like

Installing joystick shows its already updated on raspberry. But still if we run that jstest command it would throw the same error (No such file or Directory) . THe PS3 works fine though in a PC or in the actual console so i dont know why in our Raspberry OS it doesnt pair properly

Pairing a PS4 controller have no issues though i could see it when i run jstest. I tried your updated script on a PS4 controller but it was showing error about the buttons. I think the mapping of the buttons in the python script is only compatible with PS3 and not PS4.

Superb progress - good job.

Yes the PS4 controller returns different values from what I read on the Internet. Suggest that you:

  1. cp ps3.py ps4.py
  2. nano ps4.py (use cntrl-W to change all occurrences of ps3 to ps4, and then ctrl-X, y to save and exit)
  3. compare outputs of jstest for ps3 and ps4 controllers to find the values for left, right, up, down …
  4. modify the needed values in the ps4.py
  5. cp ps3_egpg3_example.py ps4_egpg3_example.py
  6. nano ps4_egpg3_example.py (change all occurrences of ps3 to ps4)

And then post your ps4.py and ps4_egpg3_example.py code for everyone’s benefit!

I noticed the servo commands also needed to be updated for GoPiGo3, so here is my latest version:

I followed the part of renaming all instances of ps3 to ps4 on both scripts to a new file however when i run ps4_egpg3_example.py i get the error below. But since your step3 I cannot do it as running jstest on ps3 doesnt work still. THis was one of my original issues thus i went on using ps4. This error seems to be differnt mapping assigned on the PS4 button but if i cannot pair my PS3 i dont have any to compared with.

pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Initializing
Done
Traceback (most recent call last):
File “ps4_egpg3_example.py”, line 94, in
p.update() #Read the ps4 values
File “/home/pi/Dexter/GoPiGo3/Software/Python/Examples/PS3_Control/ps4.py”, line 82, in update
self.a_right =button_analog[9]
IndexError: list index out of range

You need to work on figuring out what needs to change in your ps4.py file, by putting some print statements to see what values are coming through for ps4.numbuttons, ps4.numaxes, ps4.joystick_count.

Also will need to look on the internet for the values of PS4 that correspond to the values of PS3, to enable you to remap the #Read analog values and #Read digital values section.

That is my guess - you are going to have to dig into it - no one can do it for you, sad to say.

I also was able to pair, connect, trust a PS3 DualShock 3 controller but unsuccessful at having /dev/input/js0 appear (using Bluetooth).

There are reports it has to do with conflict with WiFi, so it may not be solvable.

End of my investigation.

truly appreciate all the suggestions you gave, I am working on the mapping of the buttons at least I think we are headed to the right direction.

1 Like