Delay between consecutive BLE HID Mouse commands?

Hi Team,

Target: I would like to implement HID mouse use case, which means i need to send the mouse movement information to Mobile phone/PC/Tablet through Bluetooth in Adafruit Feather M0 BLE board.

Problem: i have to send the command either "AT+BLEHIDMOUSEMOVE" or "AT+BLEHIDMOUSEBUTTON" continuously in 30ms time frame based on user input. is it possible to send the command consecutively in 30ms time frame? what is minimum delay required between consecutive command?

Appreciate your feedback.

what is minimum delay required between consecutive command?

0.00000000000000001 nanoseconds or less.

Thanks Paul for your reply.

How much time it takes to process the above commands (AT+BLEHIDMOUSEMOVE" or "AT+BLEHIDMOUSEBUTTON).
it takes around 200 to 250ms. is it so?
not sure, whats the problem.

Please refer the loop function code here as below,


void loop(void)
{

digitalWrite(13, HIGH);
if ( ble.sendCommandCheckOK(F(“AT+BleHidMouseButton=L,click”)) )
{
Serial.println( F(“AT+BleHidMouseButton=L,click is success”) );
// delay a bit
delay(250);

}
else
{
// Failed, probably pairing is not complete yet
Serial.println( F(“Please make sure Bluefruit is paired and try again”) );
}
digitalWrite(13, LOW);
}


This code does not work without the delay routine (delay(250);).
I am new to Arduino BLE and it will be great if you help here.
Please refer the attachment for over all source.

hidmouse.ino (6.52 KB)

BluefruitConfig.h (2.59 KB)

it takes around 200 to 250ms. is it so?

It must be. I read it on the internet.

How are you determining that "it" takes 200 to 250 milliseconds to "process" the command?

How did you measure that? How did you define "process" the command? What is "it" that is processing the command?

You need to understand that the Arduino is sending a command to some other hardware, telling it to do something. You need to understand that that hardware takes time to receive the command, parse it, take some action, and return some reply.

You need to understand that the action probably involves sending some data over the air, to some other device, and that that device may need to pass the data along to some other device, and return a reply.

You need, also, to understand that ALL of the communications, between the Arduino and the bluetooth shield, between the bluetooth devices, and between the bluetooth device on the other end and whatever it is connected to, are ALL asynchronous.

That is, nothing in the sending of the command by the Arduino to using the data on the PC/Android/whatever blocks until the data is consumed.

So, it is up to you (or any library you use) to allow for sufficient time to pass to allow for the data to be consumed, or to use some mechanism to enforce synchronization.

The use of delay() in the examples is a way to avoid needing to wait exactly long enough to get a reply.

Good to hear.

I am sending the mouse click command to Android mobile phone which is connected via blue tooth with Adafruit feather M0 BLE.

Measurement method: hope you can see in my code that, there is a GPIO pin number "13" is made HIGH to LOW before and after the command.

Yes, you are right. Am not sure that the time taken is for process by Blue tooth module or Android mobile phone takes to process and reply back. it could be in Android side.

i have verified in two android phone (Nexus 5 and Moto G) and both has same behavior. i.e, i need to include the delay routine of 250ms, other wise the successive commands are getting failed around 200-250ms or always throws an error for the command which takes around 8-10ms.

Meanwhile, do see any problem on my source code (even in the setup function)?

Also, Do you know any setting which cause such delay in android/windows/iOS side? Any doc which explains the sequence of behavior to process the Blue tooth HID command in Android side?

Hi Paul, Come with an small updates.

Understood that, the function "ble.waitForOK()" takes time to receive the response.

I would like to send either AT+BLEHIDMOUSEMOVE" or "AT+BLEHIDMOUSEBUTTON for every 30ms and

how can we achieve this?

Appreciate your feedback.