Use DualSense Controller with Python.
Project description
DualSense™ controller for Python
Use the Sony DualSense™ controller (PlayStation 5 controller) with Python (3.10+) in Windows or Linux (Kernel 5.12+)
Contents
Tested with
Windows:
- Windows 10 Pro (TODO)
Linux:
- Manjaro Linux (6.1.38-1-MANJARO (64-bit)), Python 3.11.x
- Ubuntu 22.04 Linux 64-bit, Python 3.10.x
Requirements
- Linux
- Python 3.10+
- hidapi
Installation
Some preparations have to be done before depending on your operating system:
Prerequisites for Linux
HIDAPI on Linux
You need HIDAPI library installed on your system.
For example on Ubuntu install it via:
sudo apt install libhidapi-dev
udev rules
For use the controller in Python without root privileges add the udev rule.
sudo cp res/70-dualsense.rules /etc/udev/rules.d
or create a file /etd/udev/rules.d/70-dualsense.rules
with following content.
# USB
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ce6", MODE="0666"
# Bluetooth
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", KERNELS=="0005:054C:0CE6.*", MODE="0666"
Then u have to activate the rule.
sudo udevadm control --reload-rules
sudo udevadm trigger
Prerequisites for Windows
Just download the latest release of HIDAPI.
Unzip the release zip file und then place the according hidapi.dll
in your Workspace (i.e. C:\Windows\System32
)
folder.
(from x64
folder for 64-bit Windows or from x86
folder for 32-bit Windows)
Install the library
You can now go ahead and use the library within your projects. Add either via pip
pip install --upgrade dualsense-controller
or when you prefer Python Poetry as Packaging and Dependency Management solution, then add via
poetry add dualsense-controller
Usage
The detailed usage documentation is work in progress. Please take a look to the example files here:
/src/examples/example.py
/src/examples/example_trigger.py
/src/examples/contextmanager_usage_example.py
Development
...
USB Sniffing on Windows with Wireshark/TShark and USBPcap
Wireshark with USBPcap install is required. Ensure that your Wireshark and USBPcapCMD binaries are in the Windows Path variable.
- find controller in USB tree to detect Root Device, i.e.
\\.\USBPcap3
USBPcapCMD.exe
- Run Capture in Wireshark for that device, start an app which permanently sends Data to controller like nondebug Dualsense Explorer (Chrome browser required)
- In Wireshark find Destination Number for appropriate device (out) i.e.
3.8.3
- Run script:
python tools_dev/shark/shark.py USBPcap3 3.8.3
The output should look like:
02 ff f7 00 00 00 00 00 00 00 10 26 90 a0 ff 00 00 00 00 00 00 00 26 90 a0 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 02 00 00 ff ff ff
operating_mode: 02
flags_physics: ff
flags_controls: f7
motor_right: 00
motor_left: 00
microphone_led: 00
microphone_mute: 10
right_trigger: 26 90 a0 ff 00 00 00 00
left_trigger: 26 90 a0 ff 00 00 00 00
led_options: 00
lightbar_pulse_options: 02
player_leds_brightness: 00
player_leds_enable: 00
color: ff ff ff
Protocol
For communication between PC and controller there is a byte-based protocol, which has been deciphered to a large extent. The meaning of individual bytes and byte sequences in both direction - from and to the controller - is documented in the files docs/dualsense-controller.ods and README_PROTOCOL.md
Sources
This project's was heavily inspired by the following projects. A lot of implementation details were borrowed and know-how were extracted from them.
- pydualsense
- DualSense explorer tool
- ds5ctl
- PS5 Library of USB_Host_Shield_2.0
- DualSense on Windows [API]
Libs
Trademarks Notes
"PlayStation", "PlayStation Family Mark", "PS5 logo", "PS5", "DualSense" and "DUALSHOCK" are registered trademarks or trademarks of Sony Interactive Entertainment Inc. "SONY" is a registered trademark of Sony Corporation. The authors are not affiliated in any kind with Sony Interactive Entertainment Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dualsense_controller-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d800ee63846a96f73f085bc285aebb0522552138fba34e4fe7d78362745fc03b |
|
MD5 | 9a20cd46cd66683b301ab59cf3e434c4 |
|
BLAKE2b-256 | 025172db8571e832bb3fd686bc966af7b98194e032a751304c3bf6e7e3f1fbc5 |
Hashes for dualsense_controller-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a390daf18f609b218e4c7ef5017a94dcea1eaab3e2a121f8fa3d9f9716d8a1c8 |
|
MD5 | 2a41545435cf3fb66c0486568b31d5c6 |
|
BLAKE2b-256 | 8b161d7df2b91a5d1a1739ca517efb5598cc029dd8f146b14ab7e3cf62f71ca2 |