Controllers Bluetooth - jalopezsuarez/piback GitHub Wiki
Controllers Bluetooth
Dependences Libraries
» First you need to get yourself a USB Bluetooth dongle for the Raspberry Pi and you will need a USB mini cable, the same type you use to charge the PS3 controller.
sudo apt-get -y install libusb-dev joystick python-pygame
sudo apt-get -y install bluetooth libbluetooth3 libusb-dev
Enable bluetooth services and add the default user to the bluetooth group:
sudo systemctl enable bluetooth.service
sudo usermod -G bluetooth -a pi
Enable/Disable Pi3 onboard Blueetoth
Raspberry Pi3 has an onboard Bluetooth 4.0 controller. This Bluetooth can be used for remote controllers or you can use a external USB Dongle 4.0 or 2.0 depending of the remote controller needs.
To enable or disable locate and edit the Raspberry Pi3 boot initialisation file:
vi /boot/config.txt
Add comment or remove this parameter settings:
# Enable/Disable onboard Pi3 Bluetooth
dtoverlay=pi3-disable-bt
Testing Controller (Mapping Codes)
Once you have logged back in press the PS button to test the connection. The LEDs should briefly flash, then just one LED should remain lit. You can then use the following command to list the connected joysticks:
ls /dev/input/js*
At least one should be shown, probably /dev/input/js0
. Finally you can test the controller is working using the device name from the last command with jstest:
jstest /dev/input/js0
The numbers shown should change as you move the joysticks around, if so everything is working properly.
NES 8Bitdo FC30 GamePad Bluetooth
Joystick Mode
8bitdoNES controller appears to prefer to start with START + R (Right Shoulder) pressed to get into joystick mode.
» Once the controller is fully configured and paired with our Raspberry Pi3. We need to be aware to boot first the Raspberry Pi3 before turn on the controller in "joystick/joypad/gamepad" mode.
» IMPORTANT (previous paired controllers) If the controller had been previously paired with another device, you might need to press the reset button: Hold down the Select button for 7 seconds to reset the Bluetooth pairings for the controller. (The instructions don't tell you to do this, but my Update button was grayed out until I did this step.). Re-pair using Start+R
.
System Mapping Setup
This mapping is necessary for some applications to detect the controller. Not for all applications, but SDL Library applications like EmulationStation need this file to link with the remote controller automatically.
pi@raspberrypi:# cd /etc/udev/rules.d
pi@raspberrypi:# sudo wget https://raw.githubusercontent.com/paalfe/mixedcontent/master/udev_rules.d/99-8bitdo-bluetooth-controllers.rules
# If applications do NOT detect the 8Bitdo controller when connected via Bluetooth and won't even recognize manual binding,
# fix this by adding these udev rules to force detection - https://github.com/paalfe/mixedcontent/blob/master/udev_rules.d/99-8bitdo-bluetooth-controllers.rules.
# Add the udev rules file to "/etc/udev/rules.d/99-8bitdo-bluetooth-controllers.rules" and reboot.
# Forum thread: http://libretro.com/forums/showthread.php?t=3649
# Useful reading: https://hg.libsdl.org/SDL/file/704a0bfecf75/README-linux.txt
# 8Bitdo FC30 1P GamePad Bluetooth mode(START) mode(START+R)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo FC30 GamePad", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo FC30 2P GamePad Bluetooth mode(START)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo FC30 II", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo FC30 2P GamePad Bluetooth mode(START+R)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo FC30 II Joystick", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo SFC30 GamePad Bluetooth mode(START)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo SFC30 GamePad", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo SFC30 GamePad Bluetooth mode(START+R)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo SFC30 GamePad Joystick", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo NES30 GamePad Bluetooth mode(START)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo NES30 GamePad", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo NES30 GamePad Bluetooth mode(START+R)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo NES30 GamePad Joystick", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo SNES30 GamePad Bluetooth mode(START)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo SNES30 GamePad", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo SNES30 GamePad Bluetooth mode(START+R)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo SNES30 GamePad Joystick", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo FC30 Pro GamePad Bluetooth mode(POWER) mode(POWER+R1)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo FC30 Pro", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo NES30 Pro GamePad Bluetooth mode(POWER)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo NES30 Pro", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo NES30 Pro GamePad Bluetooth mode(POWER+R1)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo NES30 Pro Joystick", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo FC30 Arcade Joystick Bluetooth mode(HOME)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo Joy", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
# 8Bitdo Zero GamePad Bluetooth mode(START) mode(START+R)
SUBSYSTEM=="input", ATTRS{name}=="8Bitdo Zero GamePad", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"
Bluetooth Pairing/Connection Service
Enabling bluetooth. Check that the bluetooth service is active:
systemctl status bluetooth
bluetooth.service - Bluetooth service
Loaded: loaded (/usr/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2015-04-07 19:37:50 UTC; 1s ago
Main PID: 489 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─489 /usr/lib/bluetooth/bluetoothd
If you get this message:
bluetooth.service - Bluetooth service
Loaded: loaded (/usr/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Condition: start condition failed at Tue 2015-04-07 19:35:48 UTC; 1min 59s ago
ConditionPathExists=/storage/.cache/services/bluez.conf was not met
Try to manually enable and start bluetooth service:
systemctl enable bluetooth
systemctl start bluetooth
Check again if the service is active. (with the commands from above) If bluetooth is still inactive you have to create the config file, and restart the service:
touch /storage/.cache/services/bluez.conf
systemctl start bluetooth
Bluetooth Pairing/Connection Setup
Launch bluetoothctl
A bluetooth prompt will appear. Type the following:
agent on
default-agent
power on
discoverable on
pairable on
scan on
Power on your 8Bitdo Controller in Mode (START+R). You will see output in your terminal similar to this:
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:48:30:22 Discovering: yes
[NEW] Device 88:F7:20:69:9E:F4 8Bitdo NES30 Pro
To authorize the 8Bitdo controller copy the device address (e.g. 88:F7:20:69:9E:F4) and type the following:
pair <device_addr>
trust <device_addr>
connect <device_addr>
Common Bluetooth Pairing Issues
- Make sure the battery on the controller is decently charged.
- If the controller had been previously paired with another device, you might need to press the reset button: Hold down the Select button for 7 seconds to reset the Bluetooth pairings for the controller. (The instructions don't tell you to do this, but my Update button was grayed out until I did this step.). Re-pair using
Start+R
. - If the controller is not reconnecting after a reboot/shutdown it usually means the pairing didn’t stick. Try to manually pair the controller with the following command:
Controller Mapping Buttons
8Bitdo NES30 Mapping buttons
8Bitdo SNES30 Mapping buttons
PS3 Controller Play Station
PS3 needs an Bluetooth USB 2.0 Dongle (with Cambridge chip) to work. So you need to attach one to Raspberry Pi3.
Sources / Repositories
mkdir /vemu/controller
cd /vemu/controller
System Setup
Next we need to tell the PS3 controller it is meant to be connecting to the Raspberry Pi. Plug the controller into the Raspberry Pi with the USB cable and the Bluetooth dongle if you have not already. We will also restart the Raspberry Pi to ensure the Bluetooth service is running:
Now disconnect the controller from the USB cable. Next we start the Bluetooth configuration tool and set the dongle so it can be seen by the controller. Disconnect your controller from the USB port, and run the ‘bluetoothctl’ command as a regular user (you don’t need to be root for this):
sudo bluetoothctl
agent on
discoverable on
[bluetooth]# scan on
Discovery started
[CHG] Controller A4:5E:60:CA:D1:F8 Discovering: yes
[NEW] Device 00:06:F5:B2:3F:30 PLAYSTATION(R)3 Controller
Now re-connect your controller with the mini-USB cable. You should see messages in the terminal indicating that something has connected (but don’t worry if you don’t, as long as something useful appears in the next step!)
Type devices in the terminal. You will see a list of possible devices, including at least your SixAxis controller. You need to take note of the MAC address of the controller for the next step:
[bluetooth]# devices
Device 60:38:0E:CC:OC:E3 PLAYSTATION(R)3 Controller
trust 38:C0:96:5C:C6:60
[CHG] Device 38:C0:96:5C:C6:60 Trusted: yes
Changing 38:C0:96:5C:C6:60 trust succeeded
Finally exit the Bluetooth configuration tool and restart the Raspberry Pi.
quit
sudo reboot
This will persist across reboots, so from now on you can just connect by pressing the PS button on the controller. Pressing and holding this button will shut the controller down - at the moment there’s no timeout so be sure to turn the controller off when you’re not going to be using it for a while.
Controller Mapping Buttons
Mapping buttons