Use either pygame or pyUSB to read inputs from a PS4 dualshock 4 controller through USB connection
Author: Chi-Feng Pai ([email protected]) Platform: Win10 Python version: 3.6 Main imports: pygame (for joystic, button, and hat inputs) or pyusb+libusb (for gyroscope, accelerator, touch pad inputs)
Quick start:
- pip install pygame
- pip install pyusb
- pip install libusb
- Modify path to libusb-1.0.dll for backend in the example (e.g. C:\Users\Anaconda3\Lib\site-packages\libusb_platform_windows\x86\libusb-1.0.dll)
- Run the example to get readouts from your dualshock 4 controller
References:
- pygame: http://blog.mclemon.io/python-using-a-dualshock-4-with-pygame (Note that the gyroscope and accelerometer won't work if you follow the steps in this reference)
- pyUSB backend issue: https://c5techblog.wordpress.com/2016/09/05/tutorial-setup-pyusb-under-windows/
- Detailed mapping of readouts from dualshock 4: http://www.psdevwiki.com/ps4/DS4-USB
- Other useful resources: https://github.com/seidtgeist/node-ds4 and https://github.com/senceryazici/ps4controller/blob/master/ps4.py