user2140890
user2140890

Reputation: 1

rn-42 bluesmirf HID not sending scancodes?

I am trying to use an arduino with a bluetooth HID module (bluesmirf) to control the volume on my Galaxy tab. I have the arduino setup so that i push a small button that is wired in, and it sends ascii text to the tablet just like a keyboard would, and this works fine. I wanted to create a custom keyboard layout file for this "bluetooth keyboard" so that when the tablet receives a keypress from the arduino over bluetooth, it would control the appropriate item, like the volume, mute, etc. However, when using keytest to capture the incoming button press from the bluetooth module, the scancode is always 0. Keytest is reading the key right and shows it as keycode_a (for example) when an A is sent, but the scancode for that key is always 0 instead of a unique identifier. Oddly enough, the carriage return that the arduino automatically puts at the end of the serial.println command (command that I am using to send the button presses over bluetooth) shows up correctly as ENTER and DOES have a scancode.

I dont get it. I must be doing something wrong but I am still new/learning so I must be missing it. I cant setup a custom keyboard layout to do what I want without having a scancode coming in for the tablet to see.

I can post my arduino code if necessary. Any and all help is greatly appreciated. I am so close to accomplishing what I need and its driving me insane.

EDIT - CODE BELOW:

// test code for sending keystrokes from arduino
// to computer via HID bluetooth module
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
// initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
// begin serial communication at 115200 baud rate 
  Serial.begin(115200);
}
void loop() {
// read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH,
  //the LED turns on, and the line is printed via bluetooth.
  if (buttonState == HIGH) {   
    digitalWrite(ledPin, HIGH); // turn LED on:
    Serial.println("A"); // write the line via bluetooth
    delay(1000); // delay one second 
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  } 

}

So in the code above, Serial.println ("A"); sends to the tablet and I can see an A printed in a text editor. The tablet sees that an A was pressed in the keytest app, but it shows the scancode as a 0. Every character sent shows as 0 for some reason, except the automatic carriage return that the sketch throws in after the Serial.println. I even tried using Serial.print instead since that doesnt throw in a carriage return, and I get the same scancode 0 with that too.

Upvotes: 0

Views: 1094

Answers (1)

Dhananjai Bajpai
Dhananjai Bajpai

Reputation: 1

Instead of sending it from Arduino, first try it via Cool-Term, with 3ms inter character and 3ms inter packet delay. In line ending just use 0D instead of 0D 0A Mind you before sending anything, your BlueSMiRF should be in the HID mode, I cant see that part in the code posted above. For HID mode you should do following from cool term $$$ (CR) S~,6 (CR) R,1 (CR) $$$ Now the red led should be blinking very fast, connect your phone and from cool term send A (carriage return) you should be receiving it directly on your phone.

Enjoy!

Upvotes: 0

Related Questions