Esp32 Usb Keyboard
Early USB keyboards and PS2 keyboards have the same pinout and behavior, so you can use a Pro Mini and the Arduino ps2keyboard demo to read such USB keyboards, either with a passive USB keyboard to PS2 male adapter for less than $1 USD, or via a female USB wired the same. Fancier keyboards don't work as such, at all, hence the possible need for. By default the battery level will be set to 100%, the device name will be ESP32 Bluetooth Keyboard and the manufacturer will be Espressif. Credits to chegewara and the authors of the USB keyboard library as this project is heavily based on their work!
This library allows you to make the ESP32 act as a Bluetooth Keyboard and control what it does.
You might also be interested in:
Features
- Send key strokes
- Send text
- Press/release individual keys
- Media keys are supported
- Read Numlock/Capslock/Scrolllock state
- Set battery level (basically works, but doesn't show up in Android's status bar)
- Compatible with Android
- Compatible with Windows
- Compatible with Linux
- Compatible with MacOS X (not stable, some people have issues, doesn't work with old devices)
- Compatible with iOS (not stable, some people have issues, doesn't work with old devices)
// In order to receive the message, add the ESP32 as a Bluetooth keyboard of your computer // or mobile phone: // // 1. Go to your computers/phones settings // 2. Ensure Bluetooth is turned on // 3. Scan for Bluetooth devices // 4. Connect to the device called 'ESP32 Keyboard' // 5. Open an empty document in a text editor // 6. Press the button attached to the ESP32. ESP32 BLE HID Keyboard With a keyboard, you can control anything, from your phone, iPad, laptop. This will give Arduino the power it needs to control any screen. Advanced Full instructions provided 7,061. See full list on github.com.
Installation
- (Make sure you can use the ESP32 with the Arduino IDE. Instructions can be found here.)
- In the Arduino IDE go to 'Sketch' -> 'Include Library' -> 'Add .ZIP Library...' and select the file you just downloaded.
- You can now go to 'File' -> 'Examples' -> 'ESP32 BLE Keyboard' and select any of the examples to get started.
Example
API docs
The BleKeyboard interface is almost identical to the Keyboard Interface, so you can use documentation right here:https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
Just remember that you have to use bleKeyboard
instead of just Keyboard
and you need these two lines at the top of your script:
OTG Host On ESP32-S2? - ESP32 Forum
In addition to that you can send media keys (which is not possible with the USB keyboard library). Supported are the following:
- KEY_MEDIA_NEXT_TRACK
- KEY_MEDIA_PREVIOUS_TRACK
- KEY_MEDIA_STOP
- KEY_MEDIA_PLAY_PAUSE
- KEY_MEDIA_MUTE
- KEY_MEDIA_VOLUME_UP
- KEY_MEDIA_VOLUME_DOWN
- KEY_MEDIA_WWW_HOME
- KEY_MEDIA_LOCAL_MACHINE_BROWSER // Opens 'My Computer' on Windows
- KEY_MEDIA_CALCULATOR
- KEY_MEDIA_WWW_BOOKMARKS
- KEY_MEDIA_WWW_SEARCH
- KEY_MEDIA_WWW_STOP
- KEY_MEDIA_WWW_BACK
- KEY_MEDIA_CONSUMER_CONTROL_CONFIGURATION // Media Selection
- KEY_MEDIA_EMAIL_READER
There is also Bluetooth specific information that you can set (optional):Instead of BleKeyboard bleKeyboard;
you can do BleKeyboard bleKeyboard('Bluetooth Device Name', 'Bluetooth Device Manufacturer', 100);
.The third parameter is the initial battery level of your device. To adjust the battery level later on you can simply call e.g. bleKeyboard.setBatteryLevel(50)
(set battery level to 50%).By default the battery level will be set to 100%, the device name will be ESP32 Bluetooth Keyboard
and the manufacturer will be Espressif
.
Credits
Esp32 Usb Hid Keyboard
Credits to chegewara and the authors of the USB keyboard library as this project is heavily based on their work! Also, credits to duke2421 who helped a lot with testing, debugging and fixing the device descriptor!