Python Forum
Gamepad vibration in raspberry pi with Python don't work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Gamepad vibration in raspberry pi with Python don't work (/thread-16632.html)



Gamepad vibration in raspberry pi with Python don't work - sleepwalk - Mar-07-2019

Before starting the post, thanks in advance for your time! Smile

I'm new with Python although I have some experience with C++, php, arduino...
And I'm trying to start a project with raspberry pi and Python, and I got stuck before the start Tongue .

I want to manage a gamepad through Python, I'm using an original PS3 USB gamepad and a third party Xbox360 gamepad, I only use one at time but I test both in order to avoid any compatibility problem.
The fact is I don't have any problem to read any button or axis using EVDEV or INPUTS modules in Python BUT, I can't make the vibration work.
I tried the examples that EVDEV and INPUTS modules have in their documentation, and the EVDEV vibration example doesn't give me any error or feedback (simple doesn't work) and INPUTS with this example:

"""Simple example showing how to get the gamepad to vibrate."""

from __future__ import print_function
import time

import inputs


def main(gamepad=None):
    """Vibrate the gamepad."""
    if not gamepad:
        gamepad = inputs.devices.gamepads[0]

    # Vibrate left
    gamepad.set_vibration(1, 0, 1000)

    time.sleep(2)

    # Vibrate right
    gamepad.set_vibration(0, 1, 1000)
    time.sleep(2)

    # Vibrate Both
    gamepad.set_vibration(1, 1, 2000)
    time.sleep(2)


if __name__ == "__main__":
    main()
Give me this error:
Error:
pi@raspberrypi:~/Desktop $ python3 vibrate_example.py Traceback (most recent call last): File "vibrate_example.py", line 29, in <module> main() File "vibrate_example.py", line 15, in main gamepad.set_vibration(1, 0, 1000) File "/usr/local/lib/python3.5/dist-packages/inputs.py", line 2983, in set_vibration self._set_vibration_nix(left_motor, right_motor, duration) File "/usr/local/lib/python3.5/dist-packages/inputs.py", line 2969, in _set_vibration_nix code = self.__get_vibration_code(left_motor, right_motor, duration) File "/usr/local/lib/python3.5/dist-packages/inputs.py", line 2963, in __get_vibration_code buf_conts = ioctl(self._write_device, 1076905344, inner_event) OSError: [Errno 14] Bad address pi@raspberrypi:~/Desktop $


I'm under Raspbian 9.8 (Release date: 2018-11-13 Kernel version: 4.14) up to date, and Python 3.5.3.
Raspberry pi 2B+.
Under Raspbian I can read buttons with "jstest-gtk" software and make the gamepads vibration work with command "fftest". So I suppose that drivers can manage the feature.

I tried Python 3.7.2 and 2.7 with the same result.
I tried Ubuntu Mate and Python 3.6? and 2.7 with the same result.

But under my PC with Windows 7 it works, same example, same lines (Python 3.7), and also with Ubuntu 18.04 (Python 3.6).

I can't find any information about this problem on the web and I really want to use raspberry pi hardware, so I'm stuck and I can't see what's the problem that don't allow Python to access to gamepads vibration sectors in raspberry.
I suppose that maybe is a hardware/drivers change respect other architectures... or maybe I'm a really big noob and I'm missing something obvious Tongue

Any help will be appreciated even any encouragement :P Thanks!