0% found this document useful (0 votes)
123 views13 pages

Connecting A PS5 Controller With RaspberryPi Via Bluetooth - by Shyam Padia - Me

This document provides a step-by-step guide on how to connect a PS5 DualSense controller to a Raspberry Pi via Bluetooth and utilize the pydualsense library to read controller inputs in Python. It includes necessary prerequisites, installation instructions, and example code for handling various controller events. The guide concludes by encouraging users to explore additional functionalities offered by the pydualsense library.

Uploaded by

antonio.sastre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views13 pages

Connecting A PS5 Controller With RaspberryPi Via Bluetooth - by Shyam Padia - Me

This document provides a step-by-step guide on how to connect a PS5 DualSense controller to a Raspberry Pi via Bluetooth and utilize the pydualsense library to read controller inputs in Python. It includes necessary prerequisites, installation instructions, and example code for handling various controller events. The guide concludes by encouraging users to explore additional functionalities offered by the pydualsense library.

Uploaded by

antonio.sastre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Open in app

This member-only story is on us. Upgrade to access all of Medium.

Member-only story

Connecting a PS5 Controller with


RaspberryPi via Bluetooth
Shyam Padia · Follow
3 min read · Dec 5, 2023

Listen Share More

Photo by Kamil S on Unsplash


Setting up a PS5 controller on a Raspberry Pi is surprisingly quite simple and easy
to control.

This guide will teach you how to connect a PS5 controller to a Raspberry Pi via
bluetooth and install pydualsense to read the controller inputs in python which
supports gyroscopes and touchpad input as well.

Things you will need


Raspberry Pi 4 or higher with SSH setup

PS5 Dual sense controller

Note: Raspberry Pi 3 could work but i haven’t tested it

Connecting the Dual Sense Controller


Turn on your Raspberry Pi and SSH into it

sudo apt update


sudo apt upgrade
sudo apt install joystick

Press and hold the PS button and Share button at the same time until the light bar
begins to flash, this should put the controller in pairing mode

Connect the controller to bluetooth via the GUI. Alternatively, you can also use
bluetoothctl if you face issues.

Open the Bluetooth settings on your raspberry pi and connect with Dual Sense
Wireless Controller and Pair with it
Verify that the controller is registered as a input device with ls /dev/input

You should see 4 events(event0, event1, event2, event3) and 2 js(js0, js1)

inputs as your options

Install pydualsense
You can now start the installation for pydualsense and start reading the inputs
from the controller. You can also refer to pydualsense-documentation for
additional details

sudo apt install wget

mkdir ps5_controller
cd ps5_controller

wget https://github.com/flok/pydualsense/blob/master/70-ps5-controller.rules

Add a udev rule to allow user to access controller without requiring root access

sudo cp 70-ps5-controller.rules /etc/udev/rules.d


sudo udevadm control --reload-rules
sudo udevadm trigger

Install pydualsense

sudo apt install libhidapi-dev

pip3 install pydualsense

Create a new python file called controller_test.py

from pydualsense import *

def cross_down(state):
dualsense.light.setColorI(255,0,0) # set touchpad color to red
print(f'cross {state}')

def circle_down(state):
dualsense.light.setColorI(0,255,0) # set touchpad color to green
print(f'circle {state}')
def dpad_down(state):
dualsense.light.setColorI(0,0,255) # set touchpad color to blue
print(f'dpad {state}')

def l2_down(state):
print(f'l2 {state}')

def joystick(stateX, stateY):


print(f'lj {stateX} {stateY}')

# find device and initialize


dualsense = pydualsense()
dualsense.init()

# add events handler functions


dualsense.cross_pressed += cross_down
dualsense.circle_pressed += circle_down
dualsense.dpad_down += dpad_down
dualsense.left_joystick_changed += joystick
dualsense.l2_changed += l2_down

# read controller state until R1 is pressed


while not dualsense.state.R1:
...

# close device
dualsense.close()

Run the python file and test different inputs and verify their output

Circle press (True, False)

Cross press (True, False)

DPad down press (True, False)

L2 Trigger press (value)

R1 Trigger press (Shutdown the program)


Congratulations, you have successfully connected a DualSense controller with
RaspberryPi and Python!

Refer to pydualsense-documentation for additional functionality such as Adaptive


Triggers, TouchPad, Microphone and Gyroscope controls.

Credits to the developers of pydualsense for making this amazing interface


possible.
References

pydualsense 0.6.1 documentation


pydualsense is a Python library that helps you interact with your PlayStation 5 DualSense
controller. It reads the…
flok.github.io

GitHub - flok/pydualsense: control your dualsense controller


with python
control your dualsense controller with python. Contribute to
flok/pydualsense development by creating an account on…
github.com

Raspberry Pi Playstation 5 Robotics

Follow

Written by Shyam Padia


41 Followers · 150 Following

A tech enthusiast, entrepreneur and an independent reasearcher.

No responses yet
No responses yet

To respond to this story,


Open in app
get the free Medium app.
More from Shyam Padia

Shyam Padia

How to install CPU binaries and Models for Tensorflow on Mac OS


Installing Tensorflow

Feb 12, 2018 129

See all from Shyam Padia

Recommended from Medium


Harendra

How I Am Using a Lifetime 100% Free Server


Get a server with 24 GB RAM + 4 CPU + 200 GB Storage + Always Free

Oct 26 7.9K 122

[Lucian]

How to build a cool and powerful mini PC


The perfect RPI4 + SSD
The perfect RPI4 + SSD

Dec 2 50 1

Lists

Staff picks
790 stories · 1519 saves

In DataDrivenInvestor by Austin Starks

I used OpenAI’s o1 model to develop a trading strategy. It is


DESTROYING the market
It literally took one try. I was shocked.

Sep 15 7.4K 178


In Modernizing Maintenance by Stylianos Chiotis

MQTT or OPC UA | My Roadmap to IIoT Communication Protocols


Through the eyes of a Mechanical Maintenance Engineer

Aug 19 1

In Stackademic by Crafting-Code

I Stopped Using Kubernetes. Our DevOps Team Is Happier Than Ever


Why Letting Go of Kubernetes Worked for Us

Nov 19 4.5K 131


Tom Wilson

Connect to a headless Raspberry Pi using Bluetooth


One of the challenges in deploying a headless Raspberry Pi based solution is configuring it
into a client’s network without access to the…

Jun 22 249 2

See more recommendations

You might also like