Home > Arduino, Bluetooth, TKJ Electronics, USB > Bluetooth HID devices now supported by the USB Host library

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:

BTHID bthid(&Btd, PAIR, "0000");

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:

BTHID bthid(&Btd);

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.

Simply uncomment:


In BTHID.cpp to see the incoming data and then modify the parser for your needs – the standard parser can be found in hidboot.cpp.

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.

Categories: Arduino, Bluetooth, TKJ Electronics, USB Tags:
  1. September 30th, 2015 at 14:01 | #1

    @MartinJ. Brockhus
    Hmm it is properly a conflict somewhere in your code. Can you share it somewhere? Then I will take a look.

  2. April 5th, 2016 at 04:03 | #2

    i need help setting up the wiiupro. not sure why but i cannot seem to get this thing working

  3. April 14th, 2016 at 23:10 | #3

    Please read the following section of the readme: https://github.com/felis/USB_Host_Shield_2.0#wii-library.

  4. Uddhav
    May 3rd, 2016 at 17:05 | #4

    Can you please help on specific pairing of controllers….like I have 2 PS4 controllers and two host shield with bluetooth dongles.
    How to connect specific PS4 to specific arduino . not to other one…is there anything related to setting address of bluetooth..

  5. May 6th, 2016 at 15:57 | #5

    Just pair one of them at a time and then when you press the PS button it will pair with the last device.

  6. joeyjojo
    May 12th, 2016 at 03:16 | #6

    Thanks for this library. I can get my bt joystick to connect and when I enable PRINTREPORT I can see the data in the serial monitor. My question is how do I plug this data back into my script? This is the output when I press up on the joystick L2CAP Interrupt: A1 03 B3 00 00 00 . How can I use this to turn on an LED. Sorry I am new to all this.

  7. May 14th, 2016 at 18:23 | #7

    You will need to modify the parsers to your need: https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/Bluetooth/BTHID.

    However it looks like it is sending the data using report 0x03, so you will need to add it manually here: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTHID.cpp#L188-L209.

  8. joeyjojo
    May 17th, 2016 at 14:58 | #8

    @Kristian Sloth Lauszus
    Ok. I have modified the report to 0x03 and now the serial monitor data for dpad up is. The output for any presses is about the same.

    L2CAP Interrupt: A1 03 B3 00 00 00 LeftCtrl changed
    LeftShift changed
    RightCtrl changed
    RightShift changed
    RightGUI changed

  9. joe
    May 23rd, 2016 at 03:07 | #9

    i got it working now, thanks!

  10. Andreas
    June 20th, 2016 at 18:40 | #10

    I try to conncet to Adafruit Bluetooth EZ Key device (HID keybord simmulator). Pairing works and I can see received keys.

    But at normal connect (after BTHID bthid(&Btd)) I get only errors when I swith the HID device on after “Wait For Incomming Connection Request. The error is “Connection Failed: 06” repeated many times.

    Any idea on how to solve this?

  11. Andreas
    June 22nd, 2016 at 07:11 | #11

    For a remote control project I want to use the Adafruit EZ Key BTHID Keybord Simmulator (https://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard). It pairs successfully and I can see the keys. But after normal reconnect (with BTHID bthid(&Btd)
    I get only repeating errors. Either “Connection Failed: 06” or “Connection Failed: 10”.

    Any idea how to connect sucessfully?

  12. June 24th, 2016 at 09:06 | #12

    Good to hear you got it working 🙂

    Sorry, but I haven’t experienced that before.

  13. Oleg_Todosko
    April 14th, 2017 at 10:17 | #13

    Tell me please.
    There is here such joystick:
    But this joystick BLE!
    Can I connect it using USB Bluetooth dongle + USB Host Shield?
    Under Windows, this joystick is recognized as a keyboard.
    And even configured in the program “InputMapper”. A stick is just 4 buttons.
    Thank you in advance

Comment pages
1 2 4183
  1. No trackbacks yet.