Uno + BlueSmirf RN42 HID module - sending an HID command?

Brand new to the Arduino community. Recently purchased an SMD r3 Uno, and a BlueSmirf RN42 HID shield.

Here's a description of what I want to do...

I want to take an external trigger (button push), have the Arduino identify it, and send a corresponding command to my phone via the RN42 HID module. For now, I just want to issue a command over and over for test purposes.

I have successfully wired the RN42 to the Uno (vcc, gnd, tx, rx).

Pairing the S3 to the RN42 is successful, and I was able to emulate a keyboard and send repeated text using this sample sketch I found online:

void setup() { Serial.begin(115200); } void loop() { Serial.println(“hello world”); delay(1000); // delay one second }

What I would like to do is issue a HID command to the Galaxy, such as play / pause.

I changed the "hello world" to what the hex HID command should be for play / pause, so it looks like this:

void setup() { Serial.begin(115200); } void loop() { Serial.println(“0xFD 0x03 0x03 0x80 0x00”); delay(1000); // delay one second }

Unfortunately, instead of issuing a play / pause command, it simply prints that out as text.

What am I doing wrong? Could someone point me in the right direction?

On a side note - I have zero programming experience (apart from some html back in the day), but I am technical minded and can usually wing whatever I'm trying to accomplish.


Unfortunately, instead of issuing a play / pause command, it simply prints that out as text.

That's what you told it to do. If you want to send that as binary data, send it one value at a time using Serial.write(), or put the values in an array, and send the whole array using Serial.write().

Paul can you go into a little more detail? I tried sending a hex code and it didnt emulate a button push as I expected it to, using Serial.write. Im new as well so I think maybe I dont quite know how to interate your idea.

We want to emulate android functions with external buttons, so the arduino would need to send that button scancode somehow when the button is pressed. Is it as simple as sending the hex string? Is there special formatting?

Paul can you go into a little more detail?

byte cmd[] = {0xFD, 0x03, 0x03, 0x80, 0x00};
Serial.write(cmd, sizeof(cmd));

Im very new to arduino programming so that went a bit over my head, although I understand the idea behind it. If you care to explain a bit more how to customize that function for various keys, Id appreaciate it, but its given me something to look into and Ill read up some on the process and see if I can understand it if you dont want to explain. Thanks a bunch!

Ok so I see what you were getting at there and I tested it out. I sent:

Serial.write (0x007a);

which is the android code for the home button. But it actually shows up as a z because thats the key code for a z on a pc. I have HID codes that I could send but its two hex values and Im not sure how to do that or if it would work. I am getting my codes to show up as keys, I just cant get them to match what says they should be for certain android commands/functions.

I sent:

Perhaps you could try:


Ill give that a try this evening. Thanks for the input!