I'm building a robot using a Raspberrypi and I want to control it with a Dualshock 4 PS4 Controller. After looking for a way to connect the controller with the Pi, i found a package for linux that you can install using apt install joystick
. Then, you can use the jstest command (jstest /dev/input/js0
) to list all buttons and joystick angles. But how do I get those values with a Python script or something? Or is there any way to read /dev/input/js0 like a normal file?
Well I tried to read /dev/input/js0 like any other file (using the cat command), and than this happened:
root@raspberrypi:~# cd /dev/input
root@raspberrypi:/dev/input# cat js0
?6??6??6??6??6??6??6??6??6?6? ?6?
?6?
?6?
?6??6??6???6??6??6???6??6?
There were only numbers and question marks on my screen. I guess that you can't handle with such device files (or whatever it is) like with usual files on your computer. Is there any other way to read the input from this file? Or do I need to do something using the joystick package? Is there maybe even a way running jstest
with Python and then recieving back the printed overview?
Thanks for answers!