MichaelAlanBaker / esp32-bt2ps2

Use a Bluetooth or BLE keyboard with your machine with a PS/2 port

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESP32 Bluetooth/BLE to PS/2 keyboard adapter

Project to adapt a Bluetooth or BLE keyboard to use on a computer with a compatible PS/2 keyboard connector, wirelessly. Note that big DIN 5 pin connectors and Mini-DINs (the violet ones) are equally supported.

YouTube demo: https://youtu.be/2PVjWfAAJFE

Electrical connections

DIN and Mini-DIN connectors have similar pinout but in different arrangements.

Please use a multimeter and online info to make your cable. Beware of voltage present on the port, you can short and fry things!

Connections:

ESP32 pin PS/2 pin example color
23 or any DATA orange
22 or any CLK white
GND GND black
Vin +5v red

You can change the DATA and CLK pins to whatever suits your fancy using these lines in the .ino file:

const int CLK_PIN = 22;
const int DATA_PIN = 23;

Note: Pin 12 & 13 are ideal to solder a connector so you can use Vin, GND, 13 and 12 all in a row (ESP32 DevKit rev 1 boards). BEWARE that pin 12 is a strapping pin on the ESP32 and the module will FAIL to boot due to high signals from the PS/2 port. You can remove the strapping function of pin 12 by blowing an eFuse on your board. Use the following command:

python espefuse.py --port COM4 set_flash_voltage 3.3V

There is no need to connect the 5 volts from the port if you wish to power the board over USB. For debugging I recommend you leave it disconnected, as you can end up back-feeding 5 volts back to the PS/2 port, bad things can happen. Once all is working and you don't want to debug anymore, the 5 volts from the port are enough to power the board over the Vin (regulated) pin, making this a pretty neat standalone device!

Note: ESP32 is unofficially 5V tolerant, so you can directly connect PS/2 pins to the board, that's my setup on my rev v1 board and I had no problems. However, it is ideal to use a logic level converter like this:

Building and flashing

Project works as-is under Arduino IDE. You need to have the latest Arduino Core for ESP32 installed. Refer to the following link for instructions, I recommend the manual installation:

You can easily port it back to ESP32-IDF if you want. Just make the changes from the setup() and loop() functions to the structure IDF uses as entry point and format it accordingly. All or at least most of the header files should just work fine.

Once succesfully built and flashed, you're ready to rock! (your BLE keyboard on an ancient computer, that is).

Usage and debugging

Once powered up and first of all, the code will create and init an esp32_ps2dev::PS2Keyboard object, so it can start to talk to the computer as soon as possible. This is critical because during boot the BIOS can send different commands to the module to test the presence of the keyboard.

After PS/2 init, the module scans for nearby Bluetooth and BLE devices. If the last bonded keyboard is in range, it will try to connect to it using the keys stored on the NVS flash, so no pairing is needed for every connection. If it doesn't detect a previously bonded device, it will try to connect to the nearest keyboard in pairing mode. If both processes fail, it will wait one second and scan again until it finds anything.

Once connected you can start using your keyboard, blue LED should be on.

You can hot-disconnect the keyboard. The module will detect the disconnection and repeatedly try to reconnect, so it will be back online as soon as the keyboard gets up again. This is critical for keyboards that go to sleep and disconnect, or if you swap between computers using a multi-connection keyboard.

Please note that pairing is only done after power up. If you wish to pair a new device, please reset the module with the reset button or power off and on the computer (not just reset it, because we need a power cycle). Note that if a previously paired device is on and in range, it will always connect to it first.

In case something doesn't work, you'll need to debug.

If the blue light on the module lights up and your keyboard connects, but it doesn't work, then you'll need to enable debugging in the esp32-ps2dev.cpp file using #DEFINE _ESP32_PS2DEV_DEBUG_ Serial. Check for "PS/2 command received" messages and see where it hangs, or what the BIOS doesn't like.

TODO

  • Test on many keyboards.
  • Improve stability.
  • Clean up the code.
  • Test against various hosts.
  • Add mouse support.

Reference

History

Using code and hard work from these folks:

About

Use a Bluetooth or BLE keyboard with your machine with a PS/2 port

License:MIT License


Languages

Language:C++ 100.0%