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.
\\.\USBPcap3USBPcapCMD.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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dualsense_controller-0.1.1.tar.gz.
File metadata
- Download URL: dualsense_controller-0.1.1.tar.gz
- Upload date:
- Size: 49.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.11.6 Linux/6.6.3-1-MANJARO
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77d4eef283fe375796bd3c874af5d56f03de35c86fd23bf85a0c4d65f4976f90
|
|
| MD5 |
6fa91c65a6e6cb2e63b78fc3d6c2e313
|
|
| BLAKE2b-256 |
288818d27a45b63a69241af2143564916790c94696e2b95ce4de7cd50dfba4ef
|
File details
Details for the file dualsense_controller-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dualsense_controller-0.1.1-py3-none-any.whl
- Upload date:
- Size: 66.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.11.6 Linux/6.6.3-1-MANJARO
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83af4460a679b2601bbd46d06f4d3f7404d694cb7318ff6d45c949e92a439272
|
|
| MD5 |
b7d8ea71feec4c0025f333d88eae54d2
|
|
| BLAKE2b-256 |
c51dcba49b97fbcb4e47d17a8a68ae207d8c803611ef41058ef2dbaf10409a96
|