STM32's I got didn't actually have BT. After adding a BT module, then I only have 9 GPIO pins left, and I need 10. Could probably work around that, but then I don't think the pins are 5v tolerant anyway. Could work around that also, but more parts/components to deal with.
So next I tried an ESP32. Will add a photo and exact specs later - but it does have BT (and WiFi). Setting up VScode (and ESP-IDF, target ESP32 USB BRIDGE) was new to me, but online tutorials did work - got the sample blink program working (have to remember to hold the tiny FLASH button when I issue a flash upload). Then I expanded the blink sample to test/verify which GPIO pins I could access from the code (i.e. set "PIN 0", use the o-scope to find which pin that was blinking, repeat for "PIN 1", "PIN 2", etc... i.e. didn't want to assume the labels on the board corresponded to the pin numbers used in this code library).
Next, I came across Guy Turcotte bt-keyboard on github... (last updated early 2022, so pretty fresh)
Contribute to turgu1/bt-keyboard development by creating an account on GitHub.
github.com
And, that worked "out of the box" ! In terms of: I was able to connect the BT keyboard, type stuff, and it shows up on the serial monitor connected to the ESP32. Cool, the device was receiving BT signals and relaying them back over the serial connections. Next step is then to merge the KBD5110 Arduino code, still working on that. But once done, it should mean: severe the serial IO, and can just use BT connection to command the 5110 keyboard. And this device can piggy-back on the A1 board pins, or be inline with the keyboard connector pins -- eitherway, the case can be shut and nobody need be aware it's there. Just charge up the BT keyboard, bring it near the 5110, and type your stuff. Now might need to find a BT keyboard that has programmable macro support!
Below is a summary of the changes to the Arduino original code, to adapt to this ESP32 ESP-IDF development environment. Ran out of time to actually run it yet, hopefully next weekend can do.
I haven't yet figured out the UART/serial equivalent on the ESP32 -- it looks like it might be pre-configured where std::in and std_out are latched to the COM-port? Because in the "sdkconfig" file, it has these settings...
...
CONFIG_ESP_CONSOLE_UART_DEFAULT=
y
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
# CONFIG_ESP_CONSOLE_NONE is not set
CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y // <-- prob i should change to NO
CONFIG_ESP_CONSOLE_UART_NUM=0
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 // <-- I noticed the FLASH speed is at something like 400K - 500K
(...not sure where PARITY NONE and STOP BIT 1 is set... maybe it's implied defaults)
Also,
still not 100% sure if this ESP32 is 5v pin tolerant? But I did order 3 of them just in case I burn one out. (with the USB tethered in, I've seen a few 3.3V pins on power up, but not yet a 5v pin -- and I haven't yet tried applying 5v to the Vin pin; that's probably the next thing to try, unplug the USB, stick 5v on Vin and see what happens by probing each of the pins)
And for this code, not sure if there is something I'm overlooking in regards to pullup/pulldown defaults on the board? (in contrast to any Arduino defaults)
Code:
Draft of changes to adapt the KDB5110 from Arduino sketch to STM32 C code...
// verified ESP32 board label Arduino pin#
#define PIN_KBD_P 21 // D21 2
#define PIN_KBD_7 19 // D19 3
#define PIN_KBD_6 18 // D18 4
#define PIN_KBD_5 5 // D5 5
#define PIN_KBD_4 17 // TX2 6
#define PIN_KBD_3 16 // RX2 7
#define PIN_KBD_2 4 // D4 8
#define PIN_KBD_1 2 // D2 (tied to blue LED) 9
#define PIN_KBD_0 15 // D15 10
#define PIN_KBD_STROBE 0 // D0 11
// NOTE: If need more pins, or different pins, then there is also GPIO D25,D26,D27,D14,D12,D13 on the other side of the board. (for example, if using the blue LED pin ends up causing an issue)
MAIN:
// INIT/SETUP
gpio_reset_pin(PIN_KBD_P); // (probably not needed, but seemed appropriate)
(same for PIN 0 to 7, and STROBE pin)
gpio_set_direction(PIN_KBD_P, GPIO_MODE_INPUT); // Arduino: pinMode(PIN_KBD_P, INPUT);
(same for PIN 0 to 7, and STROBE pin)
gpio_set_level(PIN_KBD_P, LOW); // Arduino: digitalWrite(PIN_KBD_P, LOW);
(same for PIN 0 to 7, and STROBE pin)
while (1) // LOOP
{
out_parity = FALSE; // assume EVEN parity
...logic to check inputs and decide GPIO state of bits 0-7
(Arduino code used serial IO; STM32 will use BT... but will figure out the STM32's equivalent to serial IO to duplicate for testing)
if ODD parity, set out_parity = TRUE
if a valid IBM5110_kbd_code_was_decided {
if (out_parity == FALSE) gpio_set_direction(PIN_KBD_P, GPIO_MODE_OUTPUT);
(...etc for PIN 0-7...)
gpio_set_direction(PIN_KBD_STROBE, GPIO_MODE_OUTPUT); // trigger ON the STROBE for the scancode being pressed
vTaskDelay(10); // part of freertos/task.h // Arduino: delay(10);
gpio_set_direction(PIN_KBD_STROBE, GPIO_MODE_INPUT); // trigger OFF the STROBE
if (out_parity == FALSE) gpio_set_direction(PIN_KBD_P, GPIO_MODE_INPUT);
(...etc for PIN 0-7...)
}
}