I am trying to make a "keyboard" with my Arduino Mini Pro and a RN-42 HID Bluetooth module. I can connect to it with my MacBook and it shows up as a Bluetooth keyboard. Also, I can press buttons and it sends commands.
Perfect right?
Unfortunately not... I don't know how to code the bytes I need to send to the module to tell it key presses and key releases. I have been reading through every Bluetooth RN-42 manual I can get my hands on, but I don't completely understand what I should be sending to the Bluetooth module. I have been searching using Google Search the past few weeks too, and I can not find any C code that would help me. As far as I know USB keypresses are sent as arrays of hex. Is this right? If so, how would I code that?
I have written a arduino library silverball that supports the RN42 and the HID protocols for keyboards and mice. I have a sample application that shows how to send HID raw reports through the BT module. Mine was designed to use to play game from a custom controller.
As was stated before you need to set your BT module into HID mode (send the command S~,6
from a serial connection or set GPIO11
high on starting the module). The module should be set to a keyboard HID from the factory by default but to set it to a keyboard send the command SH,0200
to the BT module and this will set it to keyboard mode.
After that you will need to simple send RAW reports to the BT and they will be formatted like this:
RN42 HID raw report format:
|start(1 byte)|length(1 byte)|descriptor(1 byte)|data(length - 1 [for the descriptor])
Keyboard Example:
|0xFD|9|1|modifier|0x00|code 1|code 2|code 3|code 4|code 5|code 6
Keyboard modifier bits (sent as one byte)
bit 7 |bit 6 |bit 5 |bit 4 |bit 3 |bit 2 |bit 1 |bit 0
rt GUI |rt alt |rt shift |rt ctrl|lt GUI |lt alt |lt shift |lt ctrl
My code can be found on github - use it for whatever you like!