Python Forum
Gamepad vibration in raspberry pi with Python don't work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gamepad vibration in raspberry pi with Python don't work
#1
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,180 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Coding for Python and Raspberry pi beast 3 39,487 Sep-21-2021, 09:56 PM
Last Post: beast
  python 3 raspberry pi 4 dual control motor programming problem yome 0 1,938 Mar-21-2021, 05:17 PM
Last Post: yome
  Embedded python fails to compile on Raspberry Pi tryfon 2 3,400 Dec-22-2020, 02:06 PM
Last Post: tryfon
  Uploading files to NAS from Raspberry PI using python zazas321 0 2,424 Sep-07-2020, 09:02 AM
Last Post: zazas321
  Port my python program to Raspberry pi seamlessly Hassibayub 1 1,898 Jun-29-2020, 12:58 PM
Last Post: snippsat
  Raspberry Pi Python Rest Post madaxe 0 1,329 Nov-01-2019, 07:30 PM
Last Post: madaxe
  A question about python in Raspberry Psycopast 3 2,309 Aug-14-2019, 06:36 PM
Last Post: buran
  Raspberry - Python 3.7 - Installation trouble madjo1983 2 3,030 Jul-07-2019, 02:06 AM
Last Post: DeaD_EyE
  Install Python on Raspberry Pi 3 B+ loren41 4 4,370 May-03-2019, 03:13 PM
Last Post: loren41

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020