Rasperry pi bluetooth keyboard: Difference between revisions

From Appelwiki
No edit summary
No edit summary
Line 1: Line 1:
== My setup ==
== Hardware setup ==
I wanted to use a Motorola bluetooth keyboard/mouse set on the Raspberry.
----
Because a lot of older information is available I tried to merge all information into a new howto
I verified this setup on  2012-09-18-wheezy-raspbian.img with a Sitecom CN500 dongle and a Motorola keyboard kit.
----
== Install the needed software ==
== Install the needed software ==
Please note that the bluez-compat was not used in this howto.
pi@raspberrypi ~ $ sudo -s
root@raspberrypi:/home/pi# apt-get install bluez python-gobject


$ sudo -s
== check hardware ==
# apt-get install bluez  python-dbus python-gobject 
 
== scan and pair ==
Check for bluetooth dongles
Check for bluetooth dongles
  # hcitool dev
  root@raspberrypi:/home/pi# hcitool dev
  Devices:
  Devices:
         '''hci0'''    00:10:60:A3:5A:AA
         '''hci0'''    00:10:60:A3:5A:AA
Scan for devices
Your bluetooth dongle should be visible. Otherwise you should check the driver or the [[RPi_VerifiedPeripherals|USB Bluetooth adapters]] page.
  # hcitool scan
 
== scan and pair ==
Scan for devices, you should remember the bluetooth address
  root@raspberrypi:/home/pi# hcitool scan
  Scanning ...
  Scanning ...
         '''00:0F:F6:82:D1:BB'''      Motorola Bluetooth Wireless Keyboard
         '''00:0F:F6:82:D1:BB'''      Motorola Bluetooth Wireless Keyboard
Now pair the keyboard with the pin. for example 0000.
Now pair the keyboard with the pin. for example 0000.
  echo "'''0000'''"|bluez-simple-agent '''hci0 00:0F:F6:82:D1:BB'''
  root@raspberrypi:/home/pi# echo '''0000'''|bluez-simple-agent '''hci0 00:0F:F6:82:D1:BB'''
To test the keyboard, manually connect it.
RequestPinCode (/org/bluez/3964/hci0/dev_00_0F_F6_82_D1_BB)
  hidd --connect 00:0F:F6:82:D1:BB
Enter PIN Code: Release
Check the keyboard on the console.
New device (/org/bluez/3964/hci0/dev_00_0F_F6_82_D1_BB)
== Trust the device ==
The Raspberry should trust the keyboard so it connects after every reboot.
  root@raspberrypi:/home/pi# bluez-test-device trusted 00:0F:F6:82:D1:BB yes
== Test the device as an input ==
root@raspberrypi:/home/pi# bluez-test-input connect 00:0F:F6:82:D1:BB
After a reboot the keyboard should still connect. It's possibe a keystroke is needed to connect. Connection can take a few seconds.


== Autoconnect ==
root@raspberrypi:/home/pi# hcitool con
Now to make it connect after every reboot.  
Connections:
  # cd /sys/class/bluetooth
        < ACL 00:0F:F6:82:D1:BB handle 41 state 1 lm MASTER AUTH ENCRYPT
# ls
== Debugging ==
    hci0  '''hci0:41'''
If the device isn't working the debugging tool hcidump can help.
# cd hci0\:41
  # apt-get install bluez-hcidump
  # ls
 
  0005:'''22B8:093D'''.0002 device   input1 subsystem uevent
If the connection is ok but the device does not respond as an input you can check the real vendor and model:
  address              features power   type
 
In the above directory the identifier contains the vendor and model. The 0005 is the bluetooth class.
root@raspberrypi:/home/pi# ls /sys/class/bluetooth/hci0\:*/
  0005:'''22B8:093D'''.0004  address device  features input3 power subsystem  type uevent
<pre>
ID_VENDOR 22B8
ID_VENDOR 22B8
ID_MODEL  093D
ID_MODEL  093D
In case of multiple devices you can check the address file.
</pre>
On newer bluetooth implementations the udev system is used to connect hid devices.
Append the following line to the (non-existing) file /lib/udev/rules.d/62-bluez-hid2hci.rules


  ACTION=="add", ENV{ID_VENDOR}=="'''22b8'''", ENV{ID_MODEL}=="'''093d'''" RUN+="/usr/sbin/hid2hci --method '''logitech-hid''' -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"
To add an unknown device to udev edit the (non-existing) file /lib/udev/rules.d/62-bluez-hid2hci.rules and append the following line. logitech-hid can also be dell or csr
  ACTION=="add", ENV{ID_VENDOR}=="'''22b8'''", ENV{ID_MODEL}=="'''093d'''" RUN+="/lib/udev/hid2hci --method '''logitech-hid''' -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"


I don't know why a trusts file is needed. In several other examples it's used and without it sometimes failed.
#hcitool dev
  Devices:
        hci0    '''00:10:60:A3:5A:AA'''


edit /var/lib/bluetooth/"00:10:60:A3:5A:AA"/trusts
== Mouse ==
00:0F:F6:82:D1:BB [all]
The mouse uses the same procedure as the keyboard. Only the bluetooth address changes.
 
To test the mouse on the console you can use the dreaded gpm
after a reboot the keyboard should connect. I have to tap a key on mine to make it connect. Connection takes a few seconds.
  # apt-get install gpm


== Debugging ==
If the device isn't working the debugging tool hcidump can help.
# apt-get install bluez-hcidump
== Mouse ==
The mouse uses the same procedure as the keyboard. Only the vendor/model changes.
ACTION=="add", ENV{ID_VENDOR}=="22b8", ENV{ID_MODEL}=="093e" RUN+="/usr/sbin/hid2hci --method logitech-hid -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"


to test the mouse on the console you can use the dreaded gpm
{{Template:Raspberry Pi}}
  # apt-get install gpm
[[Category:RaspberryPi]]

Revision as of 19:41, 9 October 2012

Hardware setup


I verified this setup on 2012-09-18-wheezy-raspbian.img with a Sitecom CN500 dongle and a Motorola keyboard kit.


Install the needed software

Please note that the bluez-compat was not used in this howto.

pi@raspberrypi ~ $ sudo -s
root@raspberrypi:/home/pi# apt-get install bluez python-gobject

check hardware

Check for bluetooth dongles

root@raspberrypi:/home/pi# hcitool dev
Devices:
       hci0    00:10:60:A3:5A:AA

Your bluetooth dongle should be visible. Otherwise you should check the driver or the USB Bluetooth adapters page.

scan and pair

Scan for devices, you should remember the bluetooth address

root@raspberrypi:/home/pi# hcitool scan
Scanning ...
       00:0F:F6:82:D1:BB       Motorola Bluetooth Wireless Keyboard

Now pair the keyboard with the pin. for example 0000.

root@raspberrypi:/home/pi# echo 0000|bluez-simple-agent hci0 00:0F:F6:82:D1:BB
RequestPinCode (/org/bluez/3964/hci0/dev_00_0F_F6_82_D1_BB)
Enter PIN Code: Release
New device (/org/bluez/3964/hci0/dev_00_0F_F6_82_D1_BB)

Trust the device

The Raspberry should trust the keyboard so it connects after every reboot.

root@raspberrypi:/home/pi# bluez-test-device trusted 00:0F:F6:82:D1:BB yes

Test the device as an input

root@raspberrypi:/home/pi# bluez-test-input connect 00:0F:F6:82:D1:BB

After a reboot the keyboard should still connect. It's possibe a keystroke is needed to connect. Connection can take a few seconds.

root@raspberrypi:/home/pi# hcitool con
Connections:
       < ACL 00:0F:F6:82:D1:BB handle 41 state 1 lm MASTER AUTH ENCRYPT

Debugging

If the device isn't working the debugging tool hcidump can help.

# apt-get install bluez-hcidump

If the connection is ok but the device does not respond as an input you can check the real vendor and model:

root@raspberrypi:/home/pi# ls /sys/class/bluetooth/hci0\:*/
0005:22B8:093D.0004  address  device  features  input3  power  subsystem  type  uevent
ID_VENDOR 22B8
ID_MODEL  093D

To add an unknown device to udev edit the (non-existing) file /lib/udev/rules.d/62-bluez-hid2hci.rules and append the following line. logitech-hid can also be dell or csr

ACTION=="add", ENV{ID_VENDOR}=="22b8", ENV{ID_MODEL}=="093d" RUN+="/lib/udev/hid2hci --method logitech-hid -v $env{ID_VENDOR} -p $env{ID_MODEL} --mode hid"


Mouse

The mouse uses the same procedure as the keyboard. Only the bluetooth address changes. To test the mouse on the console you can use the dreaded gpm

 # apt-get install gpm


Template:Raspberry Pi