How can I emulate a joystick using a python script?
-
@luizoti How exactly would I emulate a joystick? It seems to need a joystick already plugged in...
-
@Bluebotlabs How exactly does this control work? I probably didn't understand.
-
@luizoti Ok, so I'm building a nintendo switch, I have two arduino's, one is connected to main one via RF which is connected to the Pi via bluetooth, they both have nintendo switch joysticks in them and will be able to send whatever data they have to to the pi, I need to figure out how I can configure ES to use the controllers, e.g: via a Python script interacting with the controlers and emulating a joystick
-
Well, if I understand your control connects, but it is not seen as a control, I have already programmed a usb control with arduino, and ES recognized it normally, I believe that via BT it is possible, I did not need any python script.
The library I used at the time, I remember allowing programming joystick axes.
About py-udev, remember that it reads the events of the device and you can create a new device based on it, joystick becomes a control for example.
-
@luizoti I do not beleive you can emulate a joystick over bluetooth
Does anybody know how to use python-uinput?
-
@Bluebotlabs said in How can I emulate a joystick using a python script?:
@luizoti I do not beleive you can emulate a joystick over bluetooth
Of course you can, there's lots of projects using an inexpensive BLE HID chip to add wireless connectivity to classic controllers (SNES/Megadrive/etc.).
EDIT: here is one - https://mitxela.com/projects/bluetooth_hid_gamepad.
-
@Bluebotlabs Exactly as mitu said, it is possible, python-uinput would be useless (probably) if your control is not recognized as a control or at least a keyboard, the BLE HID project, seems something much easier to apply.
-
@luizoti However, the BLE HID project is out of the question for me due to reasons regarding budget, availability, size and others. I have tested python-uinput and pygame appears to detect it,
I shall do some further experimentation and update you on the resultpython-uinput did not work, I'm going to try using evdev, does anybody know how I can emulate a joystick using it?
-
@Bluebotlabs said in How can I emulate a joystick using a python script?:
python-uinput did not work, I'm going to try using evdev, does anybody know how I can emulate a joystick using it?
It's actually
python-uinput
that should be used to create an input device, theevdev
part it's used to read from the existing event sources (emph. mine):The evdev interface serves the purpose of passing events generated in the kernel directly to userspace through character devices that are typically located in /dev/input/.
This package also comes with bindings to uinput, the userspace input subsystem. Uinput allows userspace programs to create and handle input devices that can inject events directly into the input subsystem.
-
@mitu I made a mistake in my testing, I beleive python-uinput my work
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.