Go Down

Topic: Arduino Bluetooth HID Mouse (Read 821 times) previous topic - next topic

jasper_z

Hello,

I would like my Arduino Leonardo to work as a Bluetooth HID input device for my Mac using the BlueSMiRF Silver. There is only one button connected to the Arduino, and if this one is pressed I would a mouseclick to happen.

I've already managed to communicate with the Arduino through the Serial Monitor using this code:

Code: [Select]


#include<SoftwareSerial.h>

SoftwareSerial soft(3,2); //3-RX, 2-TX

const byte button=4;

void setup() {
  Serial.begin(115200); // Used for debugging
  soft.begin(115200);   // used for communicating with the RN-41
 
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
}

void loop() {
  if(digitalRead(button) == 0)  // Button switch is pressed
  {
    soft.print(char(5));
    Serial.println("Button Pressed");
    while(digitalRead(button) == 0) // Wait for button to be released
    {
      delay(5);
    }
  }
}



I've set the BlueSMiRF already into HID mode, and it is recognized as a bluetooth keyboard on my Mac
(following the steps in the "pair with Bluetooth Device" section in this tutorial: https://www.kobakant.at/DIY/?p=3310), but I am not sure if my computer still understands that a button is pressed.
Can anyone help me me with this? Do I need to change the firmware somehow? Or turn the Arduino into a RawHID? And if yes how?

I followed for the most part (the coding) this tutorial: https://www.youtube.com/watch?v=UJaqHnPR-XE
But he uses a prefabricated mouse to connect to the Arduino, while I would like to use just a simple button. I'm guessing that's the problem, since the mouse has already the right firmware and HID type to connect to a computer and a button doesn't.

Also I found this guy: https://www.youtube.com/watch?v=wi9akn6tQOY
So I'm sure that it's possible, I just need to figure out the soft- and firmware problem.

I am sorry if I misused the words firmware and HID type, I just got in touch with them today, so I am not very deep in the matter yet.

I hope you can help! :)

PaulS

Code: [Select]
SoftwareSerial soft(3,2); //3-RX, 2-TX

  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);

Why are you f**king with the pins you told SoftwareSerial to use for the soft instance?

Don't you suppose that one of the pins needs to be an output pin?

Why are you using SoftwareSerial when pins 0 and 1 (the Serial1 pins) are not being used?

Code: [Select]
    soft.print(char(5));
Hmmm...

Code: [Select]
    soft.print('5');
makes more sense to me.

The art of getting good answers lies in asking good questions.

Go Up