Using Keyboard / Mouse functionality on Nano BLE Sense

The product description for the Nano BLE Sense says that it is capable of acting as a keyboard or mouse, but I am unable to find any libraries that will compile for it. The official Mouse and Keyboard libraries are dependent on HID.h, which the compiler refuses to use with this board.

Just wondering if I'm missing something, or if anyone has any tips on how to code for keyboard and mouse output the old-fashioned way.

If it's of any relevance, all I'm trying to do is use the board as a gyroscope mouse.

Arduino nRF528x Boards (Mbed OS) does come with the bundled USBHID library, which provides keyboard and mouse emulation:

Unfortunately, it doesn't come with example sketches, and is not as "Arduino-y" as I'd like. There are example programs provided in the comments of the source code. Here's the one for mouse emulation:

#include "mbed.h"
#include "USBMouse.h"

USBMouse mouse;

int main(void)
{
  while (1)
  {
    mouse.move(20, 0);
    wait(0.5);
  }
}

Note that this program will cause your Nano 33 BLE Sense to no longer show up in the Arduino IDE's Tools > Port menu, so you won't be able to upload to it. The solution is to quickly press and release the reset button on the Nano 33 BLE Sense board twice. After that you should see the onboard LED pulsing and the Nano 33 BLE Sense will show up in the Arduino IDE's Tools > Port menu.

Documentation on Mbed OS's USBMouse class:
https://os.mbed.com/docs/mbed-os/v5.15/apis/usbmouse.html

Thanks for the information! This is a big help. So far my project still isn't doing what I want it to do, but at least it's compiling now, so I'll play around with the code some and see if I can get it working.

You're welcome. I'm glad if I was able to be of assistance.

If you get stuck, feel free to ask on the forum. We're always happy to provide assistance.

Enjoy!
Per

As I'm working through this I'm realizing there is a lot about coding that I don't understand. I gather that with the mouse libraries in use, the board won't show up in ports anymore so I can't use serial monitor to debug the code, but I'm finding that even commenting out everything to do with the mouse, still doesn't work. for some reason, I cannot get a port to run Serial Monitor with this:

#include "Arduino_LSM9DS1.h"  //Library for IMU support

void setup(){
  IMU.begin();
  Serial.begin(9600);
}

void loop(){
  main();
}

int main(void)
{

  float gx, gy, gz;

  int16_t xx;
  int16_t yy;
  int16_t zz;
 

  while (1)
  {
      
 if (IMU.gyroscopeAvailable()) {
        IMU.readGyroscope(gx, gy, gz);     

        //We want to add our gyroscope readings together with previous 
        //readings to get our position
        //and also to convert from float to int data types.
        xx = (xx + gx);
        //yy = (yy + gy);
        zz = (xx + gz);
}
        Serial.print(xx);
        Serial.print('\t');
        Serial.print(yy);
        Serial.print('\t');
        Serial.println(zz);
        
        Serial.print(gx);
        Serial.print('\t');
        Serial.print(gy);
        Serial.print('\t');
        Serial.println(gz);
        
  }
}

While I can get a port for the serial monitor with this:

#include "Arduino_LSM9DS1.h" //Library for IMU features

float x, y, z;  //Variables to catch readings from gyroscope

int16_t xx;
int16_t yy;
int16_t zz;

void setup() {
  IMU.begin();
  Serial.begin(9600);
  pinMode(3, INPUT_PULLUP);
 
}

void loop() {
  
  if (IMU.gyroscopeAvailable()) {
        IMU.readGyroscope(x, y, z);
       
        xx = (xx + round(x));
        yy = (yy + round(y));
        zz = (zz + round(z));
        Serial.print(xx);
        Serial.print('\t');
        Serial.print(yy);
        Serial.print('\t');
        Serial.println(zz);
        
        Serial.print(x);
        Serial.print('\t');
        Serial.print(y);
        Serial.print('\t');
        Serial.println(z);

  }
}

Any idea what's breaking the code? The example sketches in the mbed documentation use the prior format, and I can't get the mouse function to work in the latter, which means radically changing my code to try and see what my variable readings are to troubleshoot the issue.

This is the code that I've got so far for my IMU mouse. It will run, but it doesn't respond to gyroscope motions and instead all it does is drift choppily in a diagonal line from the bottom right to top left of my screen. As per the prior post, getting my gyroscope readings with this code is problematic, but when I do get gyroscope readings (using the latter example code above), they look pretty normal. I don't know if this code is processing the data weirdly, or if there's a conflict between the IMU and the mouse library or something... Honestly I'm at my wit's end right now.

#include "Arduino_LSM9DS1.h"  //Library for IMU support
#include "mbed.h"
#include "USBMouse.h"

//setup mouse to be absolute
USBMouse mouse(true, ABS_MOUSE);

int main(void)
{

  float gx, gy, gz;

  int16_t xx;
  int16_t yy;
  int16_t zz;
  IMU.begin();
  printf("Booted\r\n");

  while (1)
  {
      
 if (IMU.gyroscopeAvailable()) {
        IMU.readGyroscope(gx, gy, gz);     

        //We want to add our gyroscope readings together with previous 
        //readings to get our position
        //and also to convert from float to int data types.
        xx = (xx + gx);
        //yy = (yy + gy);
        zz = (xx + gz);
}

       mouse.move(xx, zz);
  }
}

Hey, I got one to work, but only with Linux and android (BLEMouse or BLEHID, not this one per se), but I can’t get it to work with windows. In fact, I can’t even find anything online on how to get it to work with windows.
Any clues appreciated I’m at my wit’s end here.

usbMousEv2.ino (5.11 KB)