Homepage Forums RetroPie Project Everything else related to the RetroPie Project Using the latest bluez for PS3 bluetooth (how-to)

Tagged: , ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7477
    penguin42
    Participant

    So I was having trouble getting QtSixA to work, and I started looking for alternatives. I noticed that bluez has built-in sixaxis support since 5.12 or so and wanted to try it out. Unfortunately, raspian only comes with bluez 4.99, so I started working out how to install the newer version. I eventually got it working, and with recent kernel updates, it seems to be pretty solid.

    Why use bluez vs qtsixa? A couple reasons:
    – Bluez/kernel PS3 support is being actively developed, while qtsixa was discontinued in 2011 as far as I can tell.
    – qtsixa requires running a command line utility to program the PS3 controller to talk to your bluetooth device. Plugging the controller back into the PS3 resets it, so if you switch it back and forth this can get annoying. Bluez will automatically do this programming in the background when you plug the PS3 controller into your raspberry pi, which is pretty convenient.

    Why not use bluez?
    – It’s not officially supported by raspian, so there may be some compatibility/stability issues
    – Bluez is a bit paranoid about security, and won’t automatically “trust” the PS3 controller until you do a manual pair. But you only have to do this once per controller; it doesn’t get reset if you plug the controller into the PS3.
    – The player # light doesn’t seem to work properly with bluez. They just blink continuously. I think this is fixed with newer kernels but I wasn’t able to test.

    Anyway if you want to try it out, here’s what worked for me:
    (Note, this all assumes that you already have your bluetooth dongle set up and working properly.)

    1) Update packages

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev

    2) Download, & unpackage bluez

    Get the latest from http://www.bluez.org/. As of right now, the latest is 5.19, so:

    wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.19.tar.xz
    tar xJvf bluez-5.19.tar.xz
    cd bluez-5.19

    3) Configure and build bluez

    You need to configure bluez to use the right directories for raspbian, and also enable the sixaxis plugin while disabling systemd

    ./configure --prefix=/usr --mandir=/usr/share/man \
      --sysconfdir=/etc --localstatedir=/var \
      --disable-systemd --enable-sixaxis
    make

    4) Uninstall old bluez and install new

    sudo apt-get remove --purge bluez
    sudo make install
    sudo install -v -dm755 /etc/bluetooth
    sudo install -v -m644 src/main.conf /etc/bluetooth/main.conf

    5) Create init script to start bluetooth daemon on startup

    This part is a little hacky. I modeled it after linux from scratch’s init script http://www.linuxfromscratch.org/blfs/view/svn/introduction/bootscripts.html

    sudo nano /etc/init.d/bluetooth

    Here’s what I ended up with:

    #!/bin/sh
    . /lib/lsb/init-functions
    
    case "${1}" in
       start)
          start-stop-daemon --start --background --exec /usr/libexec/bluetooth/bluetoothd
          ;;
    
       stop)
          start-stop-daemon --stop --background --exec /usr/libexec/bluetooth/bluetoothd
          ;;
    
       restart)
          ${0} stop
          sleep 1
          ${0} start
          ;;
    
       *)
    
          echo "Usage: ${0} {start|stop|restart}"
          exit 1
    
          ;;
    esac
    
    exit 0
    

    And make it start on startup

    sudo update-rc.d bluetooth defaults

    And reboot to try it out!

    sudo reboot

    On reboot, check if the daemon is running with

    ps aux |grep bluetoothd

    and you should see a line pointing to /usr/libexec/bluetooth/bluetoothd

    6) Set ps3 controller as trusted

    First, plug your ps3 controller into the raspi’s USB to program the controller with your bluetooth dongle’s mac address. The bluetooth daemon with the sixaxis plugin should do this automatically. After a second, disconnect the USB.

    However, before you can pair the sixaxis with the raspi for the first time, you have to tell bluez to trust it. If you’re running a GUI with a bluetooth agent, you can use that, but I was doing this all through the command line:

    Make sure your bluetooth dongle is up and running, then:

    sudo bluetoothctl
    agent on
    default-agent

    Now for the moment of truth: press the PS button on your controller. Hopefully it pairs with your bluetooth dongle, and bluetoothctl will ask if you want to allow it. Say yes!

    The quit bluetoothctl:

    exit

    Double check /dev/input too see if you have a joystick device. If so, you’re ready to go!

    7) Fix up device names in retropie configs

    Finaly, check your retropie config files to make sure that the correct description “PLAYSTATION(R)3 Controller” is being used.

    Specifically I had to modify ~/.emulationstation/es_input.cfg to change

    <inputConfig type="joystick" deviceName="Sony PLAYSTATION(R)3 Controller">

    to

    <inputConfig type="joystick" deviceName="PLAYSTATION(R)3 Controller">

    And modify ~/RetroPie/emulators/RetroArch/configs/PS3ControllerBT.cfg to change

    input_device = "Sony Computer Entertainment Wireless Controller"

    to

    input_device = "PLAYSTATION(R)3 Controller"

    But this might all depend on what version of retropie you have and what controllers you’ve used with it so far.

    8) Enjoy!

    Now you can switch your PS3 controller between the retropie and a PS3 willy-nilly. Just plug it into the retropie USB momentarily before attempting to pair it. Sometimes things are still a little wonky, but with the latest raspian kernel update it seems pretty smooth.

    If you want to add another PS3 controller, you have to do step 6 for each one. But only once. I was able to get two controllers working without any trouble.

    One warning: if you ever run the retropie update script, it will probably re-install the old bluez 4.99 for you. In that case you’ll have to do step 4 again.

    EPILOGUE: Getting your bluetooth dongle to start up automatically.

    I’m not sure if this is universal, but my bluetooth dongle didn’t automatically start on startup. I had to manually run sudo hciconfig hci0 up every time I rebooted, which was annoying. I eventually used advice from https://wiki.archlinux.org/index.php/bluetooth and got it to start up automatically by modifying /etc/udev/rules.d/10-local.rules with the following lines:

    # Set bluetooth power up
    ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"

    With all this in place, I can enjoy a “headless” retropie bluetooth experience. Hooray!

    #93304
    m42i
    Participant

    Thank you for this detailed how-to. I changed the following:

    Used /etc/init.d/bluetooth and /etc/defaults/bluetooth from the Debian jessie package:
    https://packages.debian.org/jessie/bluez (the .tar.xz file on the right)

    With DAEMON= in /etc/init.d/bluetooth pointing to /usr/libexec/bluetooth/bluetoothd.

    Added this line to /etc/rc.local:
    hciconfig hci0 up pscan

    When running bluetoothctl I could trust each controller after plugging it into USB without actually pairing it. Though I had to remove all devices at some point and start over. I think it’s important to disconnect one controller before trusting the next one.

    To have the controllers disconnect after 15 minutes of idling I created /etc/bluetooth/input.conf from the Debian package above. But since the axis always send some data it seems it won’t disconnect after all.

    #94210
    crazyduck
    Participant

    Worked for me :) Thank you

    But at Step 6 (trusting)
    After the Controller is connected I had to permanently trust it,
    trust XX:XX:XX:XX:XX
    [XX is your Sixaxis Mac Adress]
    elsewise I could not connect after a reboot.

    I was able to connect all my 4 Sixaxis

    #97496
    Anonymous
    Inactive

    It works almost perfectly. Thanks a lot (before using bluez I went crazy about my controllers…).

    But I have one problem: the daemon wont start automatically. I did everything as described. But when I lokk if its running (after reboot) I get:

    pi 2551 0.0 0.2 4148 1840 pts/0 S+ 15:15 0:00 grep –color=au to bluetoothd

    and its not running.

    What could I do?

    #98686
    snorp
    Participant

    Hi,

    first of all thank you for this great Tutorial.

    But it doesnt work for me :(

    Ive made all Steps till 6. After input

    sudo bluetoothctl
    agent on
    default-agent

    I get only “No agent is registered” …

    Check prozess with
    ps aux |grep bluetoothd

    I get

    pi        2542  0.0  0.2   3552  1660 pts/0    S+   12:55   0:00 grep --color=auto bluetoothd
    

    These are my Steps before using your Tutorial:

    ################################################################################
    Raspbian & Retropie Installation Protocoll
    ################################################################################
    
    1.   DOWNLOAD RASPBIAN IMAGE AND MOUNT IT ON MICROSD
    
    2.   EXPAND FILESYSTEM
         type   'sudo raspi-config'
         select '1 Expand Filesystem'
    
    3.   GET SYSTEM UP TO DATE AND INSTALL RETROPIE
         type   'sudo apt-get update'
         type   'sudo apt-get upgrade'
         type   'sudo apt-get install -y git dialog'
         type   'cd'
         type   'git clone git://github.com/petrockblog/RetroPie-Setup.git'
         type   'cd RetroPie-Setup'
         type   'chmod +x retropie_setup.sh'
         type   'sudo ./retropie_setup.sh'
         select 'U Update RetroPie-Setup script'
         restart SetupScript
         select 'Binaries-based installation'
    
    4.   CONFIGURATE TIMEZONE AND KEYBOARD LAYOUT
         type   'sudo raspi-config'
         select '4 Internationalisation Options'
         select 'I2 Change Timezone' > 'Europe' > 'Berlin' > 'Finish'
         select '4 Internationalisation Options'
         select 'I3 Change Keyboard Layout' > 'Generic 105-key (Intl) PC' > 'Other'
                 > 'German' > 'German' > 'The default for the keyboard layout' >
                 'No compose Key' > 'No'
    
    5.   REMOVE SPLASHSCREENS(1) AND LOGOS(2)
    5.1  type   'cd RetroPie-Setup'
         type   'sudo ./retropie_setup.sh'
         select '3 Setup / Configuration (to be used post install)'
         select '328 Configure Splashscreen'
         select '2 Disable custom splashscreen on boot'
         type   'sudo nano /boot/config.txt'
         add    'disable_splash=1'
    5.2  type   'sudo nano /boot/cmdline.txt'
         add    'logo.nologo'

    Thanks

    #102191
    Anonymous
    Inactive

    G’day and thank you for the nice tutorial.

    I was able to follow it until the start script, which didnt work. However, I could manually start up bluetoothd (I decided to go back to the script later when everything worked).

    However, the next step fails.
    sudo bluetoothctl is not recognized, bluetoothct1 apparently does not exist.
    Any suggestions?

    #102230
    Anonymous
    Inactive

    I am new to retropie. I just installed it and got it up and running on a RP2 a couple of weeks ago. I wish i would have discovered this forum sooner, i was trying to get my DualShock 4 controller working with retropie last week ago. I finally after many trial and errors managed to get it paired using the “jessie” build of BlueZ (5.23 i believe). After getting that up it works perfectly in games, i am having an issue though with the accelerometer. If you launch a game it seems to always get caught up in the runcommand.sh launch script asking you if you want to modify any settings, it does this because the axises detect the slighted movement and it triggers it somehow. Also if you are in the retropie-setup.sh script any movement of the DS4 will knock you out of the script. My question is, is there anyway to disable the accelerometer, or to tell retropie to ignore that axises? or as a nuclear option just disable the runcommand.sh so i do not end up in it every time i launch a game.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.