How to connect a PS3 Sixaxis gamepad to an EV3 brick via Bluetooth

| | ,

In this article I’m sharing step by step instructions for connecting a PS3 gamepad to an EV3 brick over Bluetooth. It includes Python code to control a simple LEGO MINDSTORMS EV3 robot with a tank steering mechanism. The Python code uses the analog sticks as an input and controls motor voltages. There is also MicroPython code.

Setting up the EV3 to run Python

The easiest way to get started is to follow my guide for installing VS Code and creating the MicroPython SD Card image. Do it and come back here, when you’re set up. It takes about 10 minutes if you have an SD card laying around. LEGO Education has released an easy-to-use version of ev3dev with VS Code integration. That’s what we’ll be using.

Connect the PS3 gamepad

I have an original PS3 Sixaxis controller. They are not for sale anymore, but I guess any after market controller will work just as well. They are easy to find second hand or in garage sales too. I have not been able to get the newer PS4 controllers to work.

After market PS3 controller from Amazon

Connecting the PS3 controller is a little tricky. Here are the steps.

Time needed: 5 minutes.

How to connect a PS3 Sixaxis Gamepad to a LEGO EV3 brick.

  1. Boot your LEGO MINDSTORMS EV3 brick in ev3dev

    If you don’t have a Micro SD card to do so, read the guide to running Python on your EV3 brick.

  2. Select ‘Wireless and Networks’.

    Once the brick has booted from the ev3dev image this item will show up in the menu. Use the up and down buttons on the brick to navigate to it. Use the middle button to select.

  3. Select ‘Bluetooth’

    If the EV3 Brick says ‘Bluetooth not available’, reboot the ev3 brick and start at step 2. To reboot repeatedly press the escape button (on the left bottom side of the screen) until a menu with the options ‘restart’, ‘shut down’ and ‘cancel’ appears.

  4. Set ‘Visible’ and ‘Bluetooth’ to ‘on’

    Navigate to the visibility option and use the middle button to switch between on and off. The square should be filled.

  5. Connect your PS3 gamepad with the EV3 brick using your regular EV3 USB cable.

    Use the small connector in the game pad and the big one in the brick. Wait until the lights on the PS3 gamepad are flashing.

  6. DON’T PRESS ANY BUTTONS ON THE GAMEPAD

    Don’t press any buttons on the brick either. This is really important. So don’t try to pair!

  7. Remove the USB Cable

    Just action of plugging the cable in and waiting for the discovery is enough.

  8. Press the center Playstation button on the gamepad

    It’s the button between ‘start’ and ‘select’.

  9. Authorize Service HID

    On the brick, you see a message: ‘Authorize Service HID?’. Choose Accept. You’re done. It’s connected!

  10. When reconnecting the PS3 gamepad later, after reboot, start at step 8.

    The USB cable is not necessery anymore. Do make sure the EV3 brick is visible in Bluetooth.

A simple robot for Gamepad control

Just build a simple robot, slam to large motors on a brick and add a tracking wheel. Make sure the left motor is in port B and the right motor is in port C. Here is a picture of my design.

Simple EV3 robot that is controlled by a PS3 gamepad (controller) using tank-style control.
Simple EV3 robot for controlling with a gamepad

Programming the EV3 in python for remote control

Once you have set up VS Code and the LEGO and ev3dev extensions you can run the code below. Make a new empty project with the EV3 extension if you haven’t yet done so. Remove all of the text from the main.py file and replace it with the program below.

The first line – the shebang – tells the software not to use MicroPython, but Python 3. This is awesome if you want to do Internet of Things, Multithreading and Video stream overlays. Python takes 20 seconds to start however. So for simple robots I advise you to use my MicroPython code for remote control with a PS3 controller. MicroPython starts in mere seconds!

Now pressing F5 on the keyboard runs this code on the brick. Neat, huh? If the gamepad is connected well you should be able to steer your robot around.

If you want to change the control layout, here’s an overview of the different codes you can use. So if you need the left stick wait for event type 3 and event codes 0 and 1.

Video guide for setting up the gamepad with EV3

Previous

Liz4rd – Robot Remix 6

Installation guide: EV3 brick with Python and MicroPython

Next

16 thoughts on “How to connect a PS3 Sixaxis gamepad to an EV3 brick via Bluetooth”

  1. In this code the robot move with the right analogue just , can you give me a code to put the move to Forward and backward with the lift analogue + right and lift withe right analogue ?

  2. in my brick i have 3 motors > 2 large for move and 1 medium .
    and in your code i can just control the large .
    i want to keep this method in control the large motors and I want to control the medium motor by x button . 🙁 i am really tired . because i am try a lot .

  3. Hello sir .
    Thanks a lot about this video, its help me . 😊
    But I want to ask you ..>> how can I control the medium motor by the buttons ?
    Now. With your video I can control the large motor ( move ) by the analog.
    I want control the large with the analog ( I can now ),and the one medium by the buttons .
    Thank you very much for your kindness .

  4. Hello Anton:
    I get errors from using the new EV3DEV stretch image.
    “Unable to import ‘evdev'”,
    “Unable to import ‘ev3dev.auto”
    “Instance of ‘MotorThread’ has no ‘motor’ member”,
    What changes do I need to make from the new language bindings?
    #!/usr/bin/env python3
    from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank
    from ev3dev2.sensor import INPUT_1
    from ev3dev2.sensor.lego import TouchSensor
    from ev3dev2.led import Leds

    • Are you running the code on your computer or on the brick? It should run on the brick. Are you using the sd card image from the link in the article?

  5. I am not using the the Micropython image but the newer EV3DEV.org stretch image. I have been learning the new way of coding the EV3. I think I fixed the motor setup. My problem is how to fix the lines that are connected with this line of code:
    import evdev.auto as ev3
    Which effects lines like line 32:
    devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]

  6. Hello Anton:
    I follewed the step above, but I can’t see Authorize Service HID show up on the brick. And 4 light of my PS3 gamepad were flashing. Does it PS3 gamepad not work?

    • It happens to me too, sometimes. I then wait until the PS3 gamepad stops flashing and I start over. Did you see the video?

  7. Has anybody been able to get this to work with a non-official PS3 gamepad? I don’t see the “Authorize Service HID” line

  8. Yup. Mine’s on order. Thanks for the heads-up. I look forward to controlling mine when the joypad arrives. Thanks for the confirmation, Patrick

Leave a Comment