title | description | tags | author | ||||
---|---|---|---|---|---|---|---|
Arduino UNO R4 WiFi USB HID |
Learn how to use the UNO R4 WiFi as a mouse/keyboard. |
|
Karl Söderby |
In this tutorial you will learn how to emulate a mouse/keyboard using an Arduino UNO R4 WiFi board with the Keyboard and Mouse APIs.
This feature can be used to create game controllers, keyboard extensions or other HID devices.
The goals of this tutorials are:
- Learn how to emulate a keyboard (keypresses),
- learn how to emulate a mouse (x,y coordinates).
- Arduino IDE (online or offline)
- Arduino UNO R4 WiFi
- Arduino Renesas Core
Human interface devices (HID) are devices designed for humans (keyboards, mice, game controllers etc.), that frequently sends data over USB to a computer. When you press a key on a keyboard, you send data to a computer, which reads it and in turn activates the corresponding key.
The UNO R4 WiFi has built-in support for HID, a feature found on most modern day development boards, but not on previous UNO revisions.
To turn your board into an HID, you can use the keyboard/mouse API that is built in to the core. You can visit the documentation for this API in the language reference at:
As a consequence of the multi-processor design of the UNO R4 WiFi board, uploads may fail with a "No device found on ...
" error when the board is running a sketch that uses the HID capabilities.
For this reason, you should use the following procedure to upload under these conditions:
1. Press and release the button marked "RESET" on the board quickly twice. The LED marked "L" on the board should now be pulsing.
2. Select the port of the board from the menu in Arduino IDE. The port might have changed after the previous step, so make sure to verify that it is selected.
3. Upload your sketch as usual.
To use keyboard functionalities, we need to include the library at the top of our sketch. The Keyboard class contains several methods that are useful to emulate a keyboard.
#include <Keyboard.h>
Keyboard.method()
To emulate a keyboard, we can use the press()
and releaseAll()
methods. This will emulate a keypress, as well as releasing the keypress. The following example prints a "w" every second.
#include <Keyboard.h>
void setup() {
Keyboard.begin();
delay(1000);
}
void loop() {
Keyboard.press('w');
delay(100);
Keyboard.releaseAll();
delay(1000);
}
To see more examples, please refer to links below:
- Keyboard and Mouse Control Tutorial
- Keyboard Reprogram Tutorial
- Keyboard Serial Tutorial
- Keyboard Logout Tutorial
- Keyboard Message Tutorial
To use mouse functionalities, we need to include the library at the top of our sketch. The Mouse class contains several methods that are useful to emulate a mouse.
#include <Mouse.h>
Mouse.method();
The following example moves both axis of mouse just slightly (10 points), back and forth.
#include <Mouse.h>
void setup() {
Mouse.begin();
delay(1000);
}
void loop() {
Mouse.move(10,10);
delay(1000);
Mouse.move(-10,-10);
delay(1000);
}
To see more examples, please refer to links below:
In this tutorial, we have demonstrated some basic HID usage with the UNO R4 WiFi. To view the full API, please refer to the following APIs:
In there, you will find a detailed reference along with some good examples to get you started with HID features.