Arduino Nano 33 BLE Sense HID

Arduino Nano 33 BLE sense website states that the device is HID compatible can somebody help me as I want to make It give A keyboard output.

Start here: Keyboard - Arduino Reference

See also File > Examples > 09.USB > Keyboard in the IDE.

It gives error code on compiling the code:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano 33 BLE"

In file included from C:\Program Files (x86)\Arduino\examples\09.USB\Keyboard\KeyboardMessage\KeyboardMessage.ino:23:0:

C:\Program Files (x86)\Arduino\libraries\Keyboard\src/Keyboard.h:25:10: fatal error: HID.h: No such file or directory

#include "HID.h"

^~~~~~~

compilation terminated.

exit status 1

Error compiling for board Arduino Nano 33 BLE.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Unfortunately, the Keyboard library is not compatible with the Nano 33 BLE. The Nano 33 BLE’s boards platform comes with its own “USBHID” library that uses the Mbed OS HID functionality, which results in a different API from the standard official Arduino Keyboard library.

There is an example program in the library source code:

#include "mbed.h"
#include "USBKeyboard.h"

USBKeyboard key;

int main(void)
{
  while (1) {
      key.printf("Hello World\r\n");
      wait(1);
  }
}

I had to use delay() instead of wait() to get it to compile:

#include "mbed.h"
#include "USBKeyboard.h"

USBKeyboard key;

int main(void)
{
  while (1) {
    key.printf("Hello World\r\n");
    delay(1000);
  }
}

I haven’t had a lot of success with trying to make it more “Arduino”.

IMPORTANT: this sketch will cause your Nano 33 BLE to no longer have a port, meaning you can’t upload to it. The solution is to press and release the reset button on the Nano 33 BLE twice quickly. After that, you should see the “L” LED pulsing to indicate it’s in bootloader mode. If you don’t see the LED pulsing, try the double reset again until you get the timing right. Once the board is in bootloader mode, you will see a port and be able to upload again. Note that the port number may change when it’s in bootloader mode, so make sure to select the correct port from the Arduino IDE’s Tools > Port menu before uploading.

How to add a button input so that when a button is pressed it will print specific character ?

Filling in the code suggested by @pert, If you want it to look more like Arduino code, you can proceed as follows:

#include "mbed.h"
#include "USBKeyboard.h"

USBKeyboard key;

void setup() {
    key.printf("Hello World\r\n");
}

void loop() {
  
}


int main(void)
{
  delay(100); // for the keyboard to have time to be recognised
  
  setup();

  while(1) loop();
}

Furthermore, if you want to make use of buttons to tackle this issue, I recommend using a button enabled library like e.g. EduIntro that makes it super simple to attach and use buttons. See the following example, it is self explanatory.

#include "mbed.h"
#include "USBKeyboard.h"
#include <EduIntro.h>

USBKeyboard key;

Button button(D4); // add a button on D4, using internal pull-up

void setup() {
    
}

void loop() {
  if (button.pressed()) key.printf("Hello World\r\n");
}


int main(void)
{
  delay(100); // for the keyboard to have time to be recognised
  
  setup();

  while(1) loop();
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.