# Implementing a Bluetooth HID device

I built a speed detector (of a rotating wheel) based on PIC32. For now I'm sending the speed to the PC through UART, but I'd like to be sending it through Bluetooth as a HID device because I'd like to use OS' drivers.

I've been googling for quite some time now and I've learnt a few things about Bluetooth and HID. So I will probably buy Microchip's RN42 (formerly Roving Networks) which supports HID profile. However I'd still need some advice, I do know it can be done (example), but I just don't know how to go about it.
For example how would I create my own descriptor to send to host? Or do I use an existing one? A descriptor has to be sent when connecting HID device to host, right?

I also read something about raw mode. Is HID in raw mode what I'm looking for?

If memory serves me right, the RN42 only allows you to use their defined HID descriptors. This would force you into using the keyboard, mouse, joystick, etc. The example that you linked to uses the Bluegiga WT12. The WT12 actually allows you to define your own HID descriptor. You could do a vendor specific report and define how the OS interprets the data being sent from your device. Keep in mind that using something like the scroll of the mouse profile will cause the OS to scroll wherever your mouse is focused at the time the data is sent.

You should be able to find other examples of the WT12 online. They might not be for PIC, but they should give you a general idea of how to use them. The WT12 using Bluegiga's iWRAP protocol.

You can also do HID over GATT which is for Bluetooth Low Energy. Something like the BT121 module could do that. Bluegiga has an HID example for BGScript, which is like programming in basic, or you have the option to do it over serial communications.

• Thank you very much. I did notice that the WT12 is used in the project I linked, but didn't know what you said about the RN42. So what if I use the joystick profile and choose a button that doesn't trigger any actions unless in game? I do realize that would be a poor solution... I will look into the WT12. What is the advantage of HID over GATT (besides low energy consumption)? Is there any other HID capable modules? I found only the first two. – Luka Sep 16 '15 at 22:09

Check the Roving Networks HID Users Manual. There are several existing profiles such as Mouse, Keyboard or Joystick. The best Human Interface Device Profile depends on your application case. If you would like to map your sensor values to a scroll behavior, a mouse profile with a mouse scroll variable would be a good decision. Please note that these values are relative. A joystick profile, for example, provides absolute values on the axis. If you would implement your own HID profile you should go more in detail and it is a little more complex.

The folowing example gives you starting point for a simple joystick profile with an Arduino:

// Command Mode
// --------------
bluetooth.begin(9600);
delay(50);
bluetooth.print("\$");
delay(50);
bluetooth.print("SN,HIDJoystick\r\n");
delay(50);
bluetooth.print(" SU,57\r\n");
delay(50);
bluetooth.print("S~,6\r\n");
delay(600);
bluetooth.print("SH,0240\r\n");
delay(200);
bluetooth.print("R,1\r\n");
delay(400);

// HID Joystick Report
// --------------
bluetooth.write((byte)0xFD); //Start HID Report
bluetooth.write((byte)0x6);  //Length byte

// 1. X/Y-Axis
bluetooth.write(45);  //First X coordinate
bluetooth.write(-33); //First Y coordinate

// 2. X/Y-Axis
bluetooth.write(45);  //Second X coordinate
bluetooth.write(-33); //Second Y coordinate

// Buttons
bluetooth.write(B10000001); // Second Byte (Buttons 1-8)
bluetooth.write(B10000000); // Second Byte (Buttons 9-16)

• Thank you for your answer, I did vote it up, however it will be seen when I reach enough rep points. The code will definitely come in handy when I begin. But I chose Jeremiah's answer as it is more specific and informative. – Luka Sep 16 '15 at 21:54