Reputation: 1
i'm creating a bluetooth HID gamepad with a arduino leonardo and the RN 42 HID module.
I can actually use the module to iterate a keyboard or a mouse but i didn't understand how to
send the right scan codes to iterate a gamepad or a joystick.
In the user's guide of the module they said that the raw report had to be sent like that:
0xFD,0x06,Buttons 0-7,Buttons 8-15,X1,Y1,X2,Y2
Any idea on how to set the report?
Upvotes: 0
Views: 3322
Reputation: 1056
First, you have to init a SoftwareSerial
instance.
Then you have to enter Command Mode of the RN-42 module with a sequence of $$$, set up the HID joystick mode (SH, 0240) and name the device (SN, ...), set the baud rate (SU, ...), etc.
After the successful initialization of the module, you can send HID joystick reports as follows:
SoftwareSerial bluetooth(bluetoothRX, bluetoothTX);
//...
// 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)
Please note that the buttons are controlled via binary values.
Upvotes: 2