Esp32 Usb Keyboard Emulator

0 views
Skip to first unread message

Toney Talbot

unread,
Aug 3, 2024, 5:13:42 PM8/3/24
to pasinocon

There is support for USB HID with the newer ESP32-S2 and ESP32-S3 microcontrollers. The ESP32 Arduino boards platform comes with a library named "USB" that includes examples for emulating a mouse and keyboard similar to what you can do with the Leonardo board:

Does it have to be specific the esp32 or can it be another board like rpi pico? There are tutoeials out there how you can programm it with arduino IDE like the esp32. For HID's its the way better uC to use.

This firmware is aimed to lock and unlock an iPad, but you can change the On / off setting in the firmware to whatever you want.
it uses a Space to unlock and CTRL+CMD+h to lock. (make sure automatic lock is turned of if you want Homey to control the locking and unlocking).

Have you also installed all these libraries?
GitHub athombv/com.athom.homeyduinoHomeyduino is an Homey app which allows you to easily connect your own Arduino projects to homey - athombv/com.athom.homeyduino

I am attempting to get this to work. Thusfar I am able to upload wifi sketch to the esp32 and get an ipadress. I am also able to inlcude the device on Homey. And then it gets messy. I cant get the esp32 to connect to the ipad using BLE because I cant wrap my head around the coding. I always sucked at coding. Is somebody willing to help out a script-kiddy?

Why cannot somebody just make an Homey app? Put the code in an app and then connect homey to the computer as a keyboard (without an arduino) and the Homey runs the commands and the text. Isnt that possibble?

I am attempting to get this to work. Thusfar I am able to upload wifi sketch to the esp32 and get an ipadress. I am also able to inlcude the device on Homey and restonroof. And then it gets messy. I cant get the esp32 to connect to the ipad using BLE because I cant wrap my head around the coding. I always sucked at coding. Is somebody willing to help out a script-kiddy?

To use our old Ipad Air as a digital photo frame, it would be nice to have it on when motion is detected and go to sleep after a while without any motions. It seems the device you made should be able to do this. Does the ESP32 module you bought has a built in motion/proximity sensor?
Where in NL or BE are you living? If your device would be able to make this work, I would be really interested!
Thanks

Some updates on the project that has been mostly dead for a few years.

The mini keyboard
More or less as originally planned, but I printed the keycaps in resin at JLCPCB. Filled in the engravings with gouache water-based paint, wiped off the excess and fixed it with a transparent acrylic spray. The legends look legendary, especially for their tiny size.

The switches are the same as originally planned, SKPMAME010. They feel squishy but for a little toy keyboard they are very nice, they even have pretty decent travel. There is some binding between the caps, but I'm sure it can be sorted out by filing the edges.

The computer
part of it is giving me more trouble. I was having high expectations from the kit commonly named

5.0inch ESP32-8048S050, it's available in China for around $35. I liked it because it uses a very nice 800x480 LCD panel that can do 50Hz, which is very desirable for v06c, and ESP32-S3, which has its own LCD panel controller which is flexible enough to do just what I need. It also has most things already in place so I don't have to bother with my own board, rare connectors, SD card slot.. It's all assembled here in one very pretty package, which I can only recommend -- just probably not yet for the purpose of Vector-06c emulation.

The reality of using it is a bit harsh. While I was able to make it scale v06c picture at 50Hz using crude integer nearest-neighbour interpolation, I've been struggling to make v06c emulator work at the required pace. Vector-06c has a programmable palette, which makes it finicky to emulate and these details consume CPU cycles in the main emulation loop. They also don't let the scaler use the bitplane buffer directly, so I can't offload the palette work to the scaler core without losing compatibility with various raster and multicolour effects.

Pictured above, it is running Vector-06c emulation at 50Hz though so there is some promise. There's no I/O and no sound. I can push it to 53Hz. That's some headroom, but not enough to squeeze in 8253 timer/counter. ESP32 was shown to be a good emulation platform previously, but with v06c it could be that it has met its match and we need more power.

Speaking of more power, there is an interesting bit of kit called Tang Nano 9K FPGA Development Board GOWIN GW1NR-9 RISC-V HDMI -- it's an FPGA of strange Gowin variety with its strange set of tools, which makes me reluctant to try it. But it seems to have all the oomph needed to run vector06cc (my Vector-06c FPGA emulation project). What makes it really attractive is that it also has a 50-pin RGB panel connector and even ships with a display. Definitely something to keep an eye on.

In May 2020 a client of mine (I am a freelance programmer) asked me to evaluate an ESP32 microcontroller he wanted to use in his product; he was already using a PSOC for Bluetooth communication and now he needed WiFi and more power.

Then I tried the VGA demos, first with digital RGB color (1 bit per R/G/B color component), connecting directly the R pin to the R pin of the DSUB15, the G to the G, the B to the B, HSync to HSync and VSync to VSync.

Then, I decided to make my own Spectrum emulator (my childhood computer, and the one responsible of what kind of work do I do now). But jumping into development, I did some research, and found the Rampa emulator ( -ESPectrum), a working emulator. I flashed it and loaded Manic Miner and it worked perfectly. I had no way to control it, but the Manic Miner has a demo mode which shows all the screens and I loved seeing them on the VGA monitor.

In July 2020 I managed to make the necessary modifications so that the emulator would use the Wii Remote as an input device. To do this I added, next to each game (ManicMiner.sna), a text file (ManicMiner.txt) containing the mapping of the Wiimote buttons to specific keys, with a mapping file for each game. The wiimote has a crosshair and 7 usable buttons, so it was relatively easy to run a lot of games.

I started to make my changes in the emulator, at first minor things like the font (I programmed a converter to convert a PNG with a character set I downloaded), and began modifying things in the menu.

The next thing was to finally test the PS/2 keyboard. I had a couple of old PS/2 keyboards sitting around my house, and I made a bi-directional logic level converter with MOSFET transistors on a prototype board (actually it takes 2, one for the clock signal and one for the data).

The emulator was functional, but it was mounted on a prototype board with all the cables hanging down and the components exposed, so I thought to go back to the foundations (the Spectrum) and mount the whole computer inside the keyboard. I searched the internet for mini-size PS/2 keyboards and found one (the Periboard 409 mini) which I thought, based on the photos, that would fit the ESP32 and the wiring inside. I ordered it and received it in a few days.

Investigating a bit more I discovered that during startup of a PS/2 keyboard, the keyboard controller send an initialization sequence, and the Rampa emulator module PS2KBD does not. I found a library (PS2KeyAdvanced by Paul Carpenter) that did, and integrated it into the emulator. I only use it to initialize the keyboard, but using it I can get my Periboard to work.

As for the VGA, I decided to go simple, and not use R/2R DACs, and simply connect 6 cables from the ESP to the female VGA: R, G, B, HSync, VSync and ground. I glued some cable ties to the base of the keyboard with superglue, and secured the female VGA connector with cable ties and superglue.

The last thing was to mount a double bi-directional logic level converter on a miniature board, which I did not get to the first attempt, the first board did not work, but I got it to the second attempt. I cut the cable from the PS/2 keyboard, peeled it, and soldered it to the converter board, and it worked.

I already had my ESPectrum well finished, with all its wiring hidden inside a mini keyboard, with only three connectors: VGA for video output, 3.5 jack for audio output, and USB-B for power and programming. It was a great satisfaction to contemplate my finished work.

So I got to work on the firmware of the emulator, and added the functionality of saving and loading snapshots at any time, to save the game before entering that difficult screen of Jet Set Willy, and if I fell into an infinite loop of deaths, load game.

The TTGO has a D/A converter with 2 bits per color component (RRGGBB), so I integrated a new version of the Bitluni library, for use the VGA6Bit mode, with which I got the BRIGHT attribute back from the spectrum.

In November 2020 I was investigating a detail that I did not like about the emulator: timing. In some games, the timing was roughly correct. But Manic Miner (my favorite Spectrum game, by the way), was running too fast on the ESPectrum emulator.

In other games it is not so noticeable, but Manic Miner achieves its flicker-free graphics by drawing the level and the characters in an off-screen buffer which resides in the first 16Kb of RAM, and then copies it to the screen with the LDIR instruction. This instruction undergoes many wait cycles when the source and destination buffers are in the first 16Kb of RAM.

So I correctly implemented the waiting cycles for the LDIR, LDDR, CPIR and CPDR instructions, not for other instructions, since the rules for the waiting cycles must be implemented for each instruction, and I was satisfied that Manic Miner would run at the correct speed.

With so much game testing, I wanted to play it again and I began practicing until I was able to finish the 20 levels without infinite lives or snapshots. I recorded a video of the feat, performed on a Spectrum 48K with rubber keys, connected to a CRT TV, and loading the game from cassette.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages