0

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!

  • Doesn't the library joystick have a manual that explains how to handle the received data? https://pythonhosted.org/joystick/joystick.html – Sembei Norimaki Apr 02 '23 at 19:06
  • The joystick program you are mentioning is not designed for python. I found one in pypi.org named joystick-controller. – user3435121 Apr 02 '23 at 22:24
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Сергей Кох Apr 03 '23 at 05:21
  • see https://stackoverflow.com/q/16032982/10622916 – Bodo Apr 03 '23 at 08:49
  • `/dev/input/js0` is a joydev device. Joydev is the legacy joystick interface and doesn't work as well with modern gamepads. New apps should prefer evdev. You can read evdev inputs with python-evdev: https://python-evdev.readthedocs.io/en/latest/ – nondebug Apr 03 '23 at 20:21

0 Answers0