Objective
The objective for this week was to design, build, and connect wired or wireless node(s) with network or bus addresses and local input &/or output device(s). In a way I already did this for the Input Devices week by using the camera web server, so I wanted to do something to work towards my final project.
Specifically, I wanted to get the ESP32C3 to connect with the Apple watch via Bluetooth and send some inputs as a keyboard. Apple products are notorious for having a closed ecosystem, so this was a make or break week to determine if my final project was feasible.
Planning
Initially, I was going to try to use the standard Bluetooth libraries with the ESP32. However, after doing a little research, I learned that to haave a chance of success I would need to have the ESP32 be recognized as a Human Interface Device (HID).
HIDs are devices used to interface and control the device, and typically include keyboards and mice.
After a little searching, I managed to find a BLE Keyboard library for the ESP32 on Github here: https://github.com/T-vK/ESP32-BLE-Keyboard
I downloaded this and manually added it to Arduino IDE by adding it as a ZIP library.
Process
I used my first PCB from earlier in the semester. This PCB has an ESP32C3 with a simple LED circuit on one side, and three tactile switches attached to GPIO pins on the other side. My intent was to use the three tactile switches as navigation buttons on the Apple Watch: left, right, and select (done with caps lock + spacebar).
To code it, I started with the sample BLE keyboard code that came with with the library to make sure I set it up properly. Then, I assigned each GPIO to a keystroke (left arrow, right arrow, and caps + space). Finally, I set the GPIO pins to look for a state change that will come when the switch is pressed. The state change is registered as a keystroke for the given key.
Testing
Surprisingly, things worked well from the beginning!
My biggest worry was that the Apple Watch wouldn’t even recognize the device. But to my delight, when I ran the program on the ESP32C3, it immediately was discoverable as a keyboard to the Apple Watch!
Unfortunately, it would not connect; I got an error message in the Serial Monitor that indicated a security problem.
While this initially worried me, a quick consultation with ChatGPT showed me a few changes I could make in the library files.
I made a few tweaks, and…
CONNECTED!
Here’s a video of it working to put in the passcode:
I can’t emphasize how big of a relief this is. WE’RE IN BUSINESS!
Files: