In docs

In projects

In news

In other pages

Bluetooth PS3 gamepad in Python

The cool thing about the PS3 gamepad is that it’s a normal Bluetooth device and
connects directly to the EV3. You can easily run programs in Brickman and use
the gamepad without another computer or laptop.

What you need

A PS3 gamepad (also known as Sixaxis controller or Dualshock 3)

A USB mini-B to USB A cable (like the one that comes with the EV3)

A working ssh and internet connection to the EV3 (or other ev3dev device)

ev3-ev3dev-jessie-2016-12-21.img or later

Connection

The PS3 pairing process in Brickman is a little strange, but works fine. Stick
exactly to these steps:

On the EV3 brick go to ‘Wireless and Networks’ > ‘Bluetooth’

Make sure Bluetooth is Powered and the brick is Visible.

Connect the gamepad via a mini USB cable to the EV3. I used the large USB
port next to the microSD slot.

Under Devices a ‘PLAYSTATION(R) 3 controller’ should show up. But don’t pair!

Remove the USB cable again.

Press the PS3 button on the gamepad.

The brick now asks “Authorize service HID?” Press “Accept”

You’re done! Whenever you press the PS3 button on the gamepad now, it will try
to connect to the EV3 brick. Nice!

If Brickman doesn’t work or if you don’t have a display, like on a BrickPi,
bluetoothctl is the way to go. The Gentoo Linux guys wrote a nice tutorial.

Running motors with a PS3 sixaxis controller

Now on to Python. In python we need the evdev module (without a 3) to read gamepad
events. Here’s a quick program that will take the right stick Y axis and use it
to set the speed of a motor in port A. Note that motor control is in a separate
thread. That’s because controlling the motors is much slower than reading the
gamepad. Multithreading synchronizes both.