Skip to content

codeadamca/ev3-python-ps4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

python-connect-ps4

Using Python to connect to a PS4 and a map of all identified events.

This code was written to connect a LEGO EV3 Brick to a PS4 controller. The EV3 is running ev3dev and running a version of Python called Pybricks. However, the code reacting to the PS4 controller events and the mapping of different buttons should apply to any Python/PS4 project.

This code assumes that the PS4 controller has already been paired.

Event Files

When the PS4 is paried with the device it creates three event files. These files are updated when the PS4 controller experiecnes an event (such as a button press).

Using a terminal check out the contents of the /dev/input folder before and after you pair the Bluetooth device. You should notice three new event files. On my device these files where:

  • /dev/input/event2 (touchpad events)
  • /dev/input/event3 (controller movement, like tilting, etc...)
  • /dev/input/event4 (buttons, sticks, etc...)

Each event provides five values, but we only need the event ID, code, and value. Here is a list of all events I could find:

Button and Stick Events

For me button and stick events were found in /dev/input/event4. If you're working on a PS4 project, these are probably the events you're looking for.

EventIDCodePossible ValuesDescription
X Button1304
Circle Button1305
Triangle Burron1307
Square Button13080 or 10 Released/1 Pressed
Share Button13140 or 10 Released/1 Pressed
Options Button13150 or 10 Released/1 Pressed
PS Button13160 or 10 Released/1 Pressed
Left Stick Push13170 or 10 Released/1 Pressed
Right Stick Push13180 or 10 Released/1 Pressed
L113100 or 10 Released/1 Pressed
R113110 or 10 Released/1 Pressed
L213120 or 10 Released/1 Pressed
R213130 or 10 Released/1 Pressed
-------------- Event 3: LEFT HORIZONTAL AXIS - 0 - 0 (top) to 255 (bottom) LEFT VERT AXIS - 1 - 0 (top) to 255 (bottom) L2 AXIS - 2 - 0 (released) to 255 (pushed) RIGHT HORIZONTAL AXIS - 3 - 0 (top) to 255 (bottom) RIGHT VERT AXIS - 4 - 0 (top) to 255 (bottom) R2 AXIS - 5 - 0 (released) to 255 (pushed) DIR HORIZONTAL - 16 - 1 (left), 0 (released), -1 (right) DIR HORIZONTAL - 17 - 1 (left), 0 (released), -1 (right)

About

Using Python to connect the LEGO EV3 brick to a PS4 controller.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages