16

I am using a Raspberry Pi Zero with a Iot pHat and was able to ssh into the Pi using a USB cable using this tutorial. I then set up my home WiFi with the pHat. Then I powered up the Pi with a separate power source. I could then ssh into the Pi wirelessly through my home network.

Finally to my question. I would like to connect the Pi to a wireless keyboard. I am trying to use the bluetoothctl tool to connect it. When running scan on, the Pi recognizes the keyboard, but when pairing, it won't pair. Here is the terminal session:

[CHG] Device 0C:4D:12:11:01:E4 Name: Bluetooth Keyboard
[CHG] Device 0C:4D:12:11:01:E4 Alias: Bluetooth Keyboard
[bluetooth]# pair 0C:4D:12:11:01:E4
Attempting to pair with 0C:4D:12:11:01:E4
[CHG] Device 0C:4D:12:11:01:E4 Connected: yes
[CHG] Device 0C:4D:12:11:01:E4 Connected: no
[CHG] Device 0C:4D:12:11:01:E4 Connected: yes
[CHG] Device 0C:4D:12:11:01:E4 Connected: no
[CHG] Device 0C:4D:12:11:01:E4 Connected: yes
[CHG] Device 0C:4D:12:11:01:E4 Connected: no
[CHG] Device 0C:4D:12:11:01:E4 Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device 0C:4D:12:11:01:E4 Connected: no

As you can see it seems like it connects and disconnects repeatedly.

8

try these steps;

  • put the keyboard into pair mode (k380 you would hold the bt key you want to assign the device too)
  • at pi console, run bluetoothctl
  • type power on
  • type agent on
  • type pair 0C:4D:12:11:01:E4
  • type the pair code into the keyboard as prompted
  • type connect 0C:4D:12:11:01:E4
  • type trust 0C:4D:12:11:01:E4
  • type agent off
  • type quit

hopefully you should have a bt keyboard connected. you may have to do additional work to ensure the BT will power on and pair on restart of the device.

you require to enable the agent so that keyboard can do the pair code thingy. some keyboards may vary.

hope this helps.

4
  • 3
    Doesn't work for me. The first time I set Bluetooth up, my phone connected using these steps without any problem. But as soon as I restarted the Pi, my phone refused to connect—and it looks like it misreads my Pi's device class too. No idea what's going on :/ – jimjamslam Aug 12 '17 at 5:18
  • 18
    [bluetooth]# connect XX:XX:XX:XX:XX:XX Attempting to connect to XX:XX:XX:XX:XX:XX Failed to connect: org.bluez.Error.Failed [CHG] Device XX:XX:XX:XX:XX:XX Connected: yes [CHG] Device XX:XX:XX:XX:XX:XX Connected: no [CHG] Device XX:XX:XX:XX:XX:XX Connected: yes [CHG] Device XX:XX:XX:XX:XX:XX Connected: no – jimjamslam Aug 12 '17 at 5:20
  • If connection fails after trusting - connect again to pi and it'll work. – Rodislav Moldovan Oct 12 '20 at 17:57
  • @rensa I have a similiar issue. It resloved after pactl load-module module-bluetooth-discover, which may need askubuntu.com/a/1121417/669610 – new2cpp Mar 21 at 16:02
0

I was running this on arch, but was having similar errors. For me the problem was not trusting the device before connecting:

[bluetooth]# scan on
Discovery started
[CHG] Controller 00:25:56:CD:5B:63 Discovering: yes
[NEW] Device 34:88:5D:D5:3E:C0 Keyboard K380
[bluetooth]# pair 34:88:5D:D5:3E:C0
Attempting to pair with 34:88:5D:D5:3E:C0
[CHG] Device 34:88:5D:D5:3E:C0 Connected: yes
[agent] Passkey: 740377
[agent] Passkey: 740377
[agent] Passkey: 740377
[agent] Passkey: 740377
[agent] Passkey: 740377
[agent] Passkey: 740377
[agent] Passkey: 740377
[Keyboard K380]# connect 34:88:5D:D5:3E:C0
Attempting to connect to 34:88:5D:D5:3E:C0
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device 34:88:5D:D5:3E:C0 ServicesResolved: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device 34:88:5D:D5:3E:C0 ServicesResolved: no
[CHG] Device 34:88:5D:D5:3E:C0 Connected: no
[bluetooth]# trust 34:88:5D:D5:3E:C0
[CHG] Device 34:88:5D:D5:3E:C0 Trusted: yes
Changing 34:88:5D:D5:3E:C0 trust succeeded
[bluetooth]# connect 34:88:5D:D5:3E:C0
Attempting to connect to 34:88:5D:D5:3E:C0
[CHG] Device 34:88:5D:D5:3E:C0 Connected: yes
[CHG] Device 34:88:5D:D5:3E:C0 Modalias: usb:v046DpB342d4201
[CHG] Device 34:88:5D:D5:3E:C0 UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device 34:88:5D:D5:3E:C0 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device 34:88:5D:D5:3E:C0 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 34:88:5D:D5:3E:C0 ServicesResolved: yes
[CHG] Device 34:88:5D:D5:3E:C0 Paired: yes
Connection successful
[Keyboard K380]#

Not the answer you're looking for? Browse other questions tagged or ask your own question.