Bluetooth HID devices now supported by the USB Host library
I am glad to announce that Bluetooth HID devices are now supported by the USB Host library. The library already supports PS3 and Wiimote controllers, but now it also supports more general devices, like Bluetooth keyboard and mice.
An example is available at the following link: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/BTHID/BTHID.ino.
First time you run the code, you will have to pair with your device, this is done by creating the instance like so:
You can of course set the pin to anything you like.
Now you should enable discovery of your device and it should automatically detect any mouse or keyboard present and then connect to them. On Bluetooth mice there is no need to enter any pin, but on a keyboard you should enter the pin on the keyboard and then afterwards press enter.
So in this example you should press 0 four times on the keyboard and then press enter afterwards.
After you have paired with the device, you can simply create the instance like so:
When you press any button on your device it will automatically connect to the last paired device i.e. your Arduino.
By default it uses the “Boot Protocol Mode”, but since only basic functionality is available in “Boot Protocol Mode”, I have made it easy to change it.
Simply call this in your setup:
Since it do not read the HID descriptor of your device, you might find that some of the buttons etc. might not work on your device. Unfortunately you will have to modify the parser, but it should not be that difficult.
I have currently tested the code with a PS3 keyboard (see image below) and it works perfectly fine, but I had to change it to use “Report Protocol Mode” as described above. A nice thing about the PS3 keyboard is that it features both a keyboard and a mouse, as the keyboard is touch sensitive and can therefore be used as a trackpad.
Furthermore I have tested it with my Apple Wireless Keyboard, Apple Wireless Trackpad and an old Bluetooth mouse from Microsoft that I have and all of them worked fine as well.
This is all for now. Fell free to leave a comment below if you have any questions or problems with a specific device.