Close

Chapter 4: How it works: Keyboards

A project log for Raspberry Pi Phone in a Blackberry Priv Chassis

I'm building a phone out of a raspberry pi compute module 4 into the back of a blackberry priv, to run a full fat linux OS

bethBeth 07/07/2024 at 17:550 Comments

I promised it'd be days not weeks last time, and I think legally that's still technically true (your honour), but for anyone that needs an excuse, I had a nasty headcold for a few days midweek, so there. 

Now that that's dealt with and we're all happy, here's how to get the keyboard working!

You will need:
-To read through this: https://hackaday.io/project/164232-thumb-keyboard (read through all of the project logs, oldest first, it's an amazing comprehensive breakdown of the entire process, with photos and parts and just about everything you'll need)
-the code in here (I'll github it later dw): https://pastebin.com/jzaQqKbf
-like 100 2 pin momentary buttons (maybe 4 pin is better, but I used 2, I've probably shot myself in the foot there a little)
-a few breadboards
-some wire (really any will do, I used a bunch of old stuff I had from another project a while a go. Not one I came up with mind, I just needed a mixer for cheap) 
-a soldering iron
-your priv's keypad.
-two pi picos (one with headers soldered, one without)
-electrical tape
-a single/double AA battery holder
-a box of LEDs
-a bunch of female to female dupont cables
-mu editor installed 
-pimoroni trackball


Step 1:
Once you've familiarised yourself with the entire process of making a keyboard, thanks to David Boucher, you're going to want to consider a couple more things (and I will update this with photos later). Firstly, you need the button layout to sit underneath the priv's keymat. To achieve this, I did a rough layout through the breadboard, bent one pin on each switch, and then started soldering so they would stick without wobbling. If you wanted to be really need, you could use some sort of glue too, may I recommend super. Secondly, you'll have to consider whether or not you want to have lighting. Now, I absolutely do, I love typing in the dark, but I also love being able to see which key I'm going to press, so factor in room for your lighting on the board there too (and how you're going to make it play nice with the pico, I'd recommend looking into neopixel lights)

Step 2:
Solder your rows and columns. Be very careful with these because you're not going to have a ton of space to avoid shorting them together. I'd recommend soldering the rows together, and overlaying with electrical/insulation tape, then doing your columns afterwards. I'd then check your soldering by attaching the rows to one end of the battery holder, an LED to the other end, and then attaching all the columns to that part of the LED. It's a pretty quick way to debug your solder, which if you're trying to underlay the priv's keymat with, you will absolutely make mistakes, double so if you're using your dad's old soldering iron with no temp control, and a poorly fitting tip that you crimped on with some pliers. 

Step 3: 
Look up the instructions to load circuitpy on your pi pico (the one with the headers), and get blink working. It's turned into a bit of a superstition for me, but frankly, I've gotten through a silly amount of boards doing this project, including an actual release of the magic smoke from an arduino uno r4 minima (it's still working too), so just check the actual process of making the pico do things is working. You're gonna want to use Mu for this too. I did try using Thonny, but I didn't get all that far, where Mu was much more plug and play. It's not a nice editor by all accounts, but considering I am not a microcontroller expert, it's been a friend in time of need. 

Step 4:
Now that you've got your pico working with blink (very cool), connect up your trackball to the pico (connect 3-5v to 3v3, sda to gp20, scl to gp21, and gnd to the gnd above the 3v3 pin. We can leave int for now). To do this, I would solder on some of your wire, and then make the ends long enough to connect up to the duponts (whatever you do, just make sure they're making contact, this is the most expensive component in this step). 

Copy and paste this: https://pastebin.com/jzaQqKbf

Into your code.py for circuitpy. Now, if you're not doing a trackball (shame on you), get rid of all references mouse and i2c, because that's what that's doing, and you'll get an error if there's no i2c connected, but now you should be able to get keypresses out when you connect row pin to any column pin.

Step 5:
Once you get bored of all that, you can start soldering your buttons in, taking care to take note of which rows are connected to which pins (and same with the columns)

I'll upload a photo later, but you should have something like what I made earlier (or hopefully better):


Now, due to having used 2 pin buttons instead of 1 (I think), and probably a certain amount of ineptitude (or just being new to this if I'm being kind to myself, it is self-care-sunday after all), I actually can't get my keyboard to press more than 1 key in any give column at the minute, which is more than a little frustrating if I want to press sym + M/K/I, however, for a keyboard I whipped up for about £15, I'm not going to complain too much.

This log comes with a whole bunch of todos of course, astute observers may note the lack of LED code among other things:
1) figure out a way to fix the column issue
2) add LEDs over GPIO 
3) create a program to control this keyboard over the host device (e.g. a little gui to change the RGB values from the rpi)

However, that's a problem for later on in the project when more important things have been taken care of, as none of these are critical path. I have a keyboard that works nicely with just about any device that accepts HID!

I'd also like to say a huge thanks once again to David Boucher. I've avoided going too far in depth on the keyboard creation process because for me, 99% of it was following his work: https://hackaday.io/project/164232-thumb-keyboard, and adjusting for myself as necessary, and I don't think I'd do that side of the project any justice if I wrote it out myself, beyond just what you need to adjust to make his work fit under a blackberry priv. Granted I did port some of the code on circuitpy myself, but again, mostly cobbled together out of existing work, and emulating functionality found in David Boucher's work. 

Discussions