USBHID Keyboard Issues

Hey,
I am very new to Arduino and programming microcontrollers in general. I was hoping to get insight into a problem I recently had with the USB HID library. I loaded up the example provided which was:

#include "PluggableUSBHID.h"
#include "USBKeyboard.h"

USBKeyboard Keyboard;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  Keyboard.printf("Hello world\n\r");
}

This worked just fine, but I only wanted it to write out the string once so I modified it so it was this.

#include "PluggableUSBHID.h"
#include "USBKeyboard.h"

USBKeyboard Keyboard;

void setup() {
  Keyboard.printf("Hello world\n\r");
}

void loop() {
  // put your main code here, to run repeatedly:

}

The setup meant it should only run once, but the string wasn't written at all. Also, if I changed it so that I had a variable in the loop that only allowed the prinf() statement to run once, it also did not write it out.

I have tried a variety of different ways around, and none seemed to have worked. Could anyone help me with running the Keyboard.printf() only once?

Thanks in advance.

Hello, where is the "hello world" message supposed to be printed?

Looks like you need to call the function

keyboard.begin()

which I cannot see in your program.

The Keyboard.begin() doesn't exist in the library I'm using. I'm forced to use the PluggableUSB Library because I'm using a raspi pico.

If you search the forum for #include "PluggableUSBHID.h, you might find something that explains the behaviour.

image

I'm not familiar with the Pico but there are some issues reported when using it as a keyboard.

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