Pages

Monday, January 11, 2021

PCA10059 running KMK firmware

Cheap way to try out KMK firmware

The PCA10059 is a USB stick with the NRF52840 chip on it. Digikey and Mouser have them in stock for $10. It is very bare bones and is designed to be powered directly from the USB port and uses the built in voltage regulator to provide the 3.3v running voltage. To run KMK you must first install CircuitPython.

There is currently a bug in CircuitPython on the PCA10059 that causes file corruption. It is being worked on.

The process is fairly involved. If you have a Raspberry Pi you can do it without buying a dedicated programmer. I followed the very complete instructions on Rototron.info. The only difference is that I used an old Raspberry Pi 1 (first generation) instead of a Raspberry Pi 3 as in their example.

The only changes to the process are to the config file. I commented out the lines for Raspberry Pi 3 and uncommented the ones for Raspberry Pi 1. I also dropped the adapter_khz to 100. I don't know if this was necessary but it worked fine for me.

The connections were identical to the example. I soldered header pins to the PCA10059 and inserted it into a breadboard. I used a USB extension cable to connect it to the Pi.

I ran all the commands remotely through a SSH connection.

The Raspberry Pi 1 has a problem with resetting when a USB device is hot plugged. You should power it down before making connections.

Heed the warning about resetting the PCA10059 before attempting to flash the bootloader. If you don't flash the bootloader immediately after erasing it you may lose the connection to the Pi and will need to use a level shifter to regain access to program it.

The flash process takes about 30 seconds. It will sit seeming to do nothing for most of this time. Just wait.

After you have flashed the bootloader you will need to install the latest CircuitPython for the PCA10059. https://circuitpython.org/board/pca10059/

Then install the latest KMK release. https://cdn.kmkfw.io/kmk-latest.zip

Instructions here

KMK Setup

I wanted to use the built in SW1 (the white button on the top of the board) for a simple 1 key keyboard. The problem is that KMK is setup in the reverse of how most keyboard matrices are setup and it pulls the input high when pressed, instead of pulling low. The SW1 being connected to ground did not register.

I modified matrix.py to invert the logic. My modified matrix.py is here.

Line 83 pull up instead of down.

Line 104 set output False instead of True.

Line 118 add 'not' to invert reading of pin.

Line 144 set output True instead of False.

I made a very simple code.py keymap that has a single key output of the letter 'A'.

The col pins don't do anything, since SW1 is connected to ground. But they do make the RGB LED light up to show the matrix scanning. There is also a limitation that you can not define a single row or column, you need at least two. So I added a P1_10 as a second non existent row.

It also wants the Adafruit BLE library, even though it does not use BLE. You can find this in the latest library archive from here. Copy the entire 'adafruit_ble' folder to the lib folder on the PCA10059.

The PCA10059 has 15 GPIO pins along the edges and a few more on tiny pads on the bottom. 15 are enough for a small macropad or even a Gherkin. It lacks any battery circuitry so a wireless BLE keypad is not likely without additional circuitry.