Seeduino Femto M0 Keyboard.h makes code fail?

Hi,



The Seeduino Micro https://www.amazon.com/gp/product/B081SZHJVS/ (also known as the Femto M0) has a SAMD21G18 and so should work with keyboard emulation, right?

“SAMD micro based boards” <LINK_TEXT text=“https://www.arduino.cc/reference/en/lan … /keyboard/”>https://www.arduino.cc/reference/en/language/functions/usb/keyboard/</LINK_TEXT>

Does anyone have ideas on why the following code fails?

The Flash process completes, but the serial port (attached via usb) does not respond (no serial.print) and there is no new keyboard attached to the usb…

It works when tested with a Leonardo… (the serial usb reads and then the usb keyboard emulator repeats…)

[code]#include “Keyboard.h”
char incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
}

void loop() {
Keyboard.begin();
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
Keyboard.write(incomingByte);
Keyboard.end();

}
}[/code]

Thanks,



F

Hi,



Did you use Hardware Serial Pins to connected to USB to Serial Adapter?

On the other SAMD21 board I had to use SerialUSB rather than simply Serial in my code. Not sure whether it plays nice with USB HID.

[code]

SerialUSB.begin(115200);
while(!SerialUSB);
}

void loop() {

if (SerialUSB.available() > 0) {
char InChar = SerialUSB.read();

[/code]