How to connect USB keyboard to ESP32?
How to connect USB keyboard to ESP32?
I have a ESP32 module with OLED display.
I want to connect USB keyboard to ESP32 and use MicroPyhon repl with that display and keyboard.
How can USB keyboard be connected to ESP32 module and utilized?
I want to connect USB keyboard to ESP32 and use MicroPyhon repl with that display and keyboard.
How can USB keyboard be connected to ESP32 module and utilized?
-
- Posts: 9761
- Joined: Thu Nov 26, 2015 4:08 am
Re: How to connect USB keyboard to ESP32?
That's somewhat more difficult than you may think, as the ESP32 does not have any USB hardware. (The USB port on your devboard is provided via a hardware USB-to-serial-port chip.) Using an USB keyboard would either mean using an external USB host chip (like the MAX3421) and implementing the stack to use this in software, or hoping the keyboard still supports PS/2 signaling and bitbanging that protocol.
Re: How to connect USB keyboard to ESP32?
Thanks for confirming that adding keyboard is not easy.the Pi ZeroW
I do have some 4x4 matrix keyboards, and found MicroPython code to deal with:
https://github.com/BrendanSimon/micropy ... ter/keypad
The problem for my application is that the MicroPython I have flashed on my ESP32 (with telnet and ftp server running) does not allow to "import websocket_client" which I need:
viewtopic.php?t=3476
I am using Arduinos, Raspberry PIs and ESPs, even ESP-01s recently:
https://twitter.com/HermannSW/status/10 ... 4718894082
So for using my wireless keyboard with USB dongle
https://twitter.com/HermannSW/status/10 ... 1288014849
I will simply switch to Pi ZeroW. The python on that allows for "import websocket_client", and I have 320x240 displays with self made (superglued) connectors that work fine with Pi ZeroW
https://www.raspberrypi.org/forums/view ... 8#p1214626
and give me 40x15 console:
With the keyboard and webrepl_client.py
https://forum.micropython.org/viewtopic ... 865#p29865
the Pi ZeroW will connect to ESP-01s attached to flying drone and allow to remote control servo bomb drop mechanism with MicroPython on the ESP-01s..
I do have some 4x4 matrix keyboards, and found MicroPython code to deal with:
https://github.com/BrendanSimon/micropy ... ter/keypad
The problem for my application is that the MicroPython I have flashed on my ESP32 (with telnet and ftp server running) does not allow to "import websocket_client" which I need:
viewtopic.php?t=3476
I am using Arduinos, Raspberry PIs and ESPs, even ESP-01s recently:
https://twitter.com/HermannSW/status/10 ... 4718894082
So for using my wireless keyboard with USB dongle
https://twitter.com/HermannSW/status/10 ... 1288014849
I will simply switch to Pi ZeroW. The python on that allows for "import websocket_client", and I have 320x240 displays with self made (superglued) connectors that work fine with Pi ZeroW
https://www.raspberrypi.org/forums/view ... 8#p1214626
and give me 40x15 console:
With the keyboard and webrepl_client.py
https://forum.micropython.org/viewtopic ... 865#p29865
the Pi ZeroW will connect to ESP-01s attached to flying drone and allow to remote control servo bomb drop mechanism with MicroPython on the ESP-01s..
Re: How to connect USB keyboard to ESP32?
Because you can't connect USB keyboard that doesn't mean you can't use keyboard at all. You can use 4x4 matrix keypad or even ble keyboard.
Re: How to connect USB keyboard to ESP32?
True.chegewara wrote:Because you can't connect USB keyboard that doesn't mean you can't use keyboard at all.
I thought about that, and using its "#" key as "E" and "*" key as "F" I could enter one ASCII character for ESP32 MicroPython console with two key presses hexadecimally. But that keyboard input is cumbersome.You can use 4x4 matrix keypad
That sounds interesting. But my searches showed that ble keyboard support for ESP32 is in development and not ready. Do you have link showing working ble keyboard solution for ESP32?or even ble keyboard.
I just completed my 1st mobile Pi ZeroW with 40x15 console and wireless keyboard. I will use that for running remote MicroPython shell on ESP-01s attached to flying drone:
Re: How to connect USB keyboard to ESP32?
This should be pretty solid ble keyboard solution:
https://github.com/asterics/esp32_mouse_keyboard
You can also with minimal amount of code write ble hid keyboard/mouse app for esp32 in arduino-ide.
But if you are looking for hid host code then i dont know any. I had to write my own but its commercial app and cant share it.
Can you confirm it is ble keyboard on that picture?
https://github.com/asterics/esp32_mouse_keyboard
You can also with minimal amount of code write ble hid keyboard/mouse app for esp32 in arduino-ide.
But if you are looking for hid host code then i dont know any. I had to write my own but its commercial app and cant share it.
Can you confirm it is ble keyboard on that picture?
Re: How to connect USB keyboard to ESP32?
> Can you confirm it is ble keyboard on that picture?
>
It is not, it has USB dongle, so it is a USB keyboard.
I was fine with no keyboard for ESP32.
Until I just now was able to use boochow's gist for 128x64 Oled console and redirecting MicroPython REPL to it.
https://forum.micropython.org/viewtopic ... 699#p30697
Just cool:
Perhaps now its time to think again on a (wireless) keyboard for ESP32+Oled ...
This is from matching "screen" session:
>
It is not, it has USB dongle, so it is a USB keyboard.
I was fine with no keyboard for ESP32.
Until I just now was able to use boochow's gist for 128x64 Oled console and redirecting MicroPython REPL to it.
https://forum.micropython.org/viewtopic ... 699#p30697
Just cool:
Perhaps now its time to think again on a (wireless) keyboard for ESP32+Oled ...
This is from matching "screen" session:
Code: Select all
...
>>> import sys
>>> sys.implementation
(name='micropython', version=(1, 9, 4))
>>> 5**4**3
542101086242752217003726400434970855712890625
>>>
Re: How to connect USB keyboard to ESP32?
I found a way to use wireless USB keyboard with ESP32, just use Arduino Due with its USBHost library:
https://www.arduino.cc/en/Reference/USBHost
I ordered two <4$ "USB host mini shield" for Arduino Pro Minis I have for much smaller (and cheaper) form factor:
https://www.aliexpress.com/wholesale?Se ... ini+shield
Just connecting the Due to ESP32 UART is next step, if that works Pro Mini USB host mini form factor is the way to go.
This is interesting post on USB hosts shield:
https://www.circuitsathome.com/usb-host ... re-manual/
https://www.arduino.cc/en/Reference/USBHost
I ordered two <4$ "USB host mini shield" for Arduino Pro Minis I have for much smaller (and cheaper) form factor:
https://www.aliexpress.com/wholesale?Se ... ini+shield
Just connecting the Due to ESP32 UART is next step, if that works Pro Mini USB host mini form factor is the way to go.
This is interesting post on USB hosts shield:
https://www.circuitsathome.com/usb-host ... re-manual/
Re: How to connect USB keyboard to ESP32?
It is so simple to drive ESP32 (MicroPython) from Arduino Due.
Due has 4 hardware serial interfaces, I used Serial1 and connected Pin 18 TX1 to ESP32 RX (and GND/3V).
This sketch just triggers several MicroPython calculations:
This is the youtube video demonstrating sketch:
https://www.youtube.com/watch?v=uNrtUPG ... e=youtu.be
Next step:
Combine Arduino USBHost library KeyboardController sketch with Serial1 code to use wireless USB keyboard connetced to native Due MicroUSB port for ESP32 MicroPython REPL input.
P.S
This is bottom part of ESP32 MicroPython boot.py, responsible for redirection of REPL output to Oled:
Due has 4 hardware serial interfaces, I used Serial1 and connected Pin 18 TX1 to ESP32 RX (and GND/3V).
This sketch just triggers several MicroPython calculations:
Code: Select all
void setup() {
int a,b,c;
Serial1.begin(115200);
for(a=2; a<=5; ++a)
for(b=2; b<=4; ++b)
for(c=2; c<=3; ++c) {
Serial1.print(a);
Serial1.print("**");
Serial1.print(b);
Serial1.print("**");
Serial1.println(c);
}
delay(1000);
}
void loop() {
}
https://www.youtube.com/watch?v=uNrtUPG ... e=youtu.be
Next step:
Combine Arduino USBHost library KeyboardController sketch with Serial1 code to use wireless USB keyboard connetced to native Due MicroUSB port for ESP32 MicroPython REPL input.
P.S
This is bottom part of ESP32 MicroPython boot.py, responsible for redirection of REPL output to Oled:
Code: Select all
...
import machine, ssd1306, os
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
from fbconsole import FBConsole
scr = FBConsole(oled)
os.dupterm(scr)
Re: How to connect USB keyboard to ESP32?
It works!
This is video of wireless USB keyboard connected to native Arduino Due port, its key presses being forwarded to ESP32 MicroPython REPL with Oled display. The video shows all, but the Oled display cannot be seen detailed enough. The sketch does use Arduino USBHost library KeyboardController, handles normal keys as well as CTRL keys, and return key. Does not handle up/down/left/right keys (OEM codes 82/81/80/79) yet. But CTRL-P goes back in REPL command history like up key, and CTRL-H does as backspace key should do:
This is the video taken:
https://www.youtube.com/watch?v=aK93u34 ... e=youtu.be
The whole setup does neither work when powered from laptop USB, nor when powered from 5V 1A mains adapter. In video I used official Raspberry mains adapter with 5.1V 2.5A.
Time to get the setup smaller when Arduino Pro mini USB host shield will arrive, with Arduino Pro mini.
Later it is time to find out how the Pro mini drives the mini USB host shield, and try to use that shield directly with ESP32:
This is video of wireless USB keyboard connected to native Arduino Due port, its key presses being forwarded to ESP32 MicroPython REPL with Oled display. The video shows all, but the Oled display cannot be seen detailed enough. The sketch does use Arduino USBHost library KeyboardController, handles normal keys as well as CTRL keys, and return key. Does not handle up/down/left/right keys (OEM codes 82/81/80/79) yet. But CTRL-P goes back in REPL command history like up key, and CTRL-H does as backspace key should do:
Code: Select all
#include <KeyboardController.h>
USBHost usb;
KeyboardController keyboard(usb);
void keyPressed() {
int mod = keyboard.getModifiers();
char ch = keyboard.getKey();
if (ch == 0x13) { // Return
ch = 0x0D;
}
if (mod & (LeftCtrl|RightCtrl)) {
ch &= 0x1F;
}
Serial1.write(ch);
}
void keyReleased() {
}
void setup() {
Serial1.begin(115200);
delay(200);
}
void loop() {
usb.Task();
}
https://www.youtube.com/watch?v=aK93u34 ... e=youtu.be
The whole setup does neither work when powered from laptop USB, nor when powered from 5V 1A mains adapter. In video I used official Raspberry mains adapter with 5.1V 2.5A.
Time to get the setup smaller when Arduino Pro mini USB host shield will arrive, with Arduino Pro mini.
Later it is time to find out how the Pro mini drives the mini USB host shield, and try to use that shield directly with ESP32:
- first with Pro mini USB host shield sketch running on ESP32 flashed with Arduino IDE
- later (hopefully) directly with MicroPython(!)
Who is online
Users browsing this forum: ESP_Sprite and 88 guests