Keybaud Pi: dropping the Pico, and an I2C timing bug that was a missing ground
Keybaud Pi is a 60-key keyboard on a 100 by 60 mm board. Over USB-C it is an ordinary HID keyboard. Over a four-pin JST connector it is an I2C target at address 0x5F that sends standard terminal codes. One or the other gets plugged in at a time, never both.

It started as a Pico on a daughterboard
The first version put a Raspberry Pi Pico on a board of its own, soldered down by its castellated pads, with the switch matrix on a second board above it and a bare cover board on top carrying the legends. Two rows of machined header pins carried signals from the Pico board up to the key board. The Pico was there to supply USB.
Two things drove the Pico off the design. The first is that the arrangement does not get smaller. A module occupies board area wherever it sits, so either it gets a layer to itself and the keyboard is three boards thick, or it shares a layer with the switches and the outline has to grow to make room. Neither is worth it on a board this size.
The second is the connector. I wanted USB-C on the keyboard, and the Pico arrives with its own micro-USB soldered to the module, so the port is decided for you before you start.
Why stay on the RP2040
Built-in USB was the main reason. The chip does USB device without an external controller, which is the whole job for a keyboard, and the module was only ever there to supply that.
Having USB and I2C available at the same time mattered too, since the point of this board is to be a keyboard for a PC and a keyboard for a serial terminal without changing anything about it. Pin count is not close: 30 GPIO against a budget of about 22, which is 17 matrix lines, three indicator LEDs and two for I2C. Raspberry Pi publishes a reference design for a bare RP2040 and it is a good one, widely used and easy to check your own schematic against. And I like the name Keybaud Pi.
So the rework put the bare chip on the key board. That removes the module and the board-to-board header in one move, and the stack goes from three boards to two.

Drawing it
EasyEDA Pro, following Raspberry Pi’s minimal RP2040 reference design. The bare chip needs everything the module had been providing: 16 MB QSPI flash, a 12 MHz crystal, a 3.3 V regulator, a USB-C receptacle and a BOOTSEL button. USB-C wants 5.1 kOhm pull-downs on CC1 and CC2 or a C-to-C host will never turn on VBUS, and the receptacle’s duplicated D+ and D- pins get tied together in pairs.
The RP2040 is a QFN, so the board goes out for machine placement rather than being soldered at the bench.
The switches
The project carried two key board designs for a while, one laid out for 2-pin switches and one for 4-pin, and I went back and forth between them longer than the decision deserved.
The 4-pin part won on feel. It is a 6 by 6 mm tact rated at 160 gf, which is light for the type, where plenty of tacts that size sit at 250 gf and up. 300,000 cycles is reasonable life at the price.
There is a trap in the 4-pin footprint. Pins 1 and 2 are internally joined, 3 and 4 are joined, and the switch sits between the two pairs. On the older board every switch had its diode on pad 1 and its column on pad 2, which are the same node, so every key would have read as permanently pressed. The current board takes one pad from each pair and uses the spares to carry a row or column through.
The grid they sit on is square: 12 columns on a 7.5 mm pitch, five rows on 7.0 mm. The switch bodies are rotated 16.5 degrees inside that grid, and the rotation is what makes the pitch workable. The footprint’s four pads span 6.5 by 4.5 mm, so square to the grid the nearest pads of two adjacent keys would sit 1.0 mm apart. At 16.5 degrees they sit 2.24 mm apart. The two columns at one end are at 18 degrees rather than 16.5.
Bring-up
Plug a board with blank flash into USB and an RPI-RP2 drive appears. That single event proves the crystal, the USB path and the chip, because the RP2040’s bootloader runs off the 12 MHz crystal. The first port I tried showed nothing at all and a different port on the same machine worked immediately, with the cable already checked good, which is a reminder to try another port before suspecting the board.
After that: test firmware flashed and ran, all three LEDs lit, the short test passed on all 17 matrix lines, and all 60 keys reported the right name, row and column with the switches seated in their holes but not yet soldered.

An I2C timing bug that was a missing ground
Terminal mode worked on the bench and then did not, depending on how things happened to be plugged in.
The setup while I was writing the I2C side was Keybaud on a bench supply and an ESP32-S3 test host running off a PC’s USB port. I had not tied the test host’s ground to the bench supply’s ground, so the only path between the two was through mains earth. About 30 percent of reads failed, and some that came back carried flipped bits, 0x01 arriving with no key pressed.
It presented as a timing problem, so that is where I spent the time. Pull-up values made no difference. Bus speed made no difference. Rewriting the target handler made no difference. A direct ground wire between the two boards took it to zero failures across thousands of reads.
That is in the repository now as a requirement rather than a suggestion. The JST ground pin always gets wired. A shared mains earth is not a ground connection.
Two side findings from the same session. A board with the pull-up jumper left open also read zero failures at 100 kHz on a short wire, on nothing but the chips’ internal pull-ups, which is not a reason to skip real pull-ups on a longer bus. And an ESP32-S3 clone DevKit may not put 5 V on its 5V pin at all. One measured 2.2 V and 0.9 V from its two USB ports until an IN-OUT pad was bridged.
Throwing out the terminal protocol
The first version of terminal mode copied the byte protocol of an existing small I2C keyboard, on the theory that working with hosts people already had beat doing it cleanly.
That protocol has no encoding for F1 to F12, or Home, End, PgUp and PgDn. Those keys needed codes invented for them, and then every host that wanted them had to be told what had been invented. It was a private extension to someone else’s private protocol.
What it sends now is ASCII for characters and control keys and xterm escape sequences for
everything else: ESC [ A for Up, ESC [ 5 ~ for PgUp, ESC O P for F1, with xterm’s modifier
parameter when Shift, Alt or Ctrl is held. Any serial terminal, shell or terminal library already
reads it.
The one mechanical wrinkle is that escape sequences are multi-byte and the bus hands out one byte per read. A sequence goes into the 64-byte FIFO in one piece so it cannot be torn across polls, and a 0x00 immediately after 0x1B means the Esc key itself rather than a sequence that went missing.
Hardware, firmware, the fab package and the case are at lautus-creations/keybaud-pi.