lars_the_bear
Posts: 204
Joined: Thu Jan 28, 2021 8:13 pm
Contact: Website

QWERTY keyboard/keypad for Pico

Wed May 05, 2021 7:53 pm

Hi folks

This isn't really a specific Pico question -- although it relates to a Pico application I have in mind -- I just figured that the people who might know the answer are likely to be here ;)

I'm looking for a keyboard or keypad switch matrix with a QWERTY layout. I just want the key matrix -- no electronics. I could construct my own from mechanical key-switches, but I'm looking for something more compact and, frankly, less expensive.

The best idea I've been able to come up with is a replacement laptop keyboard. These are dirt cheap, but they usually have (a) completely undocumented wiring and (b) microscopically small, proprietary connectors. I guess I could figure out (a) with time and a multi-meter, but (b) is a drag.

What would be ideal would be something like this:

https://www.ebay.co.uk/p/22022775430

but with a full-size QWERTY layout rather than just a number pad.

Does anybody know if such a thing is available? Or know of a particular laptop keyboard (or similar) that is suitable for re-purposing?

Kevin


User avatar
Gavinmc42
Posts: 5689
Joined: Wed Aug 28, 2013 3:31 am

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 2:06 am

Supermarket $10 keyboard.
I have many rollup Silicone ones that were on special for $6.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
scruss
Posts: 4099
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 2:32 am

If you want really smol, there's the M5Stack CardKB. But it's very very small, and might have a bit too much logic in it for you.

There are a bunch on Tindie, such as Universal Micro Keyboard
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

bgolab
Posts: 231
Joined: Sat Jan 30, 2021 12:59 pm

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 6:11 am

I just bought these two:
https://shop.m5stack.com/products/cardk ... cdc3&_ss=r
https://shop.m5stack.com/products/cardk ... cdc3&_ss=r

The size of the credit card is ok for me. They have different connectors and I2C interface. Will try them soon.

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 10:10 am

lars_the_bear wrote:
Wed May 05, 2021 7:53 pm
I'm looking for a keyboard or keypad switch matrix with a QWERTY layout. I just want the key matrix -- no electronics.
Does the Pico have enough GPIO to interface to a full QWERTY matrix without electronics ?

I would have thought the easiest option would be to use a stripped-down standard wired keyboard interfaced via PS/2.

Older keyboards often have a separate controller PCB with easier to repurpose connections to the keyboard matrix. Newer ones can have the controller chip removed allowing wires to be soldered to its pads. But I can't see anything beating a 2-wire plus power connection to the existing chip.

For "small" I favour XBox Chatpads - Very easy to disassemble and interface, and very cheap to buy secondhand.

Many home computer keyboards were matrixes connected using 0.1" cabling. Some used real keys.

What about a Raspberry Pi Keyboard matrix ?

lars_the_bear
Posts: 204
Joined: Thu Jan 28, 2021 8:13 pm
Contact: Website

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 11:08 am

Thank you all for the suggestions. I just love the idea of using a ZX81 keyboard ;) Amazingly, the RC2014 keyboard has exactly the same layout and connectors -- but it doesn't look so easy to get in the UK (?) I turns out that you can even buy "real" keyboards for the ZX81 which, of course, have the same layout and connectors. I had one of these back in, well, 1981, but it never occurred to me that they are still for sale.

I thought it would be difficult to source a connector to plug the ZX81 keyboard into -- I don't even know what that type of connection is called. But I just went to eBay, typed in "zx81 keyboard socket", and there it was. £2.50.

Incidentally, I think the Pico has easily enough GPIO pins to scan a full-sized keyboard, if by "full-sized" you mean "ZX81". The ZX80 keyboard needs 13 connections. Of course, with a 40-key keyboard all the keys end up with three functions, but I don't expect to be typing a novel on it.

Thanks.

Kevin

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 11:39 am

lars_the_bear wrote:
Thu May 06, 2021 11:08 am
I thought it would be difficult to source a connector to plug the ZX81 keyboard into -- I don't even know what that type of connection is called.
"FPC" I believe but could be wrong.

gordon77
Posts: 5684
Joined: Sun Aug 05, 2012 3:12 pm

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 12:20 pm

hippy wrote:
Thu May 06, 2021 11:39 am
lars_the_bear wrote:
Thu May 06, 2021 11:08 am
I thought it would be difficult to source a connector to plug the ZX81 keyboard into -- I don't even know what that type of connection is called.
"FPC" I believe but could be wrong.
Yes it's FFC (FPC)

User avatar
HermannSW
Posts: 4128
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: QWERTY keyboard/keypad for Pico

Thu May 06, 2021 10:18 pm

hippy wrote:
Thu May 06, 2021 10:10 am
. But I can't see anything beating a 2-wire plus power connection to the existing chip.

For "small" I favour XBox Chatpads - Very easy to disassemble and interface, and very cheap to buy secondhand.
I bought one such serial keyboard for 6$ after I found instructions how to use, but never really used it:
Dxx6UU2X4AA-2F6.jpg
Dxx6UU2X4AA-2F6.jpg (153.29 KiB) Viewed 817 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Fri May 07, 2021 11:45 am

HermannSW wrote:
Thu May 06, 2021 10:18 pm
hippy wrote:
Thu May 06, 2021 10:10 am
For "small" I favour XBox Chatpads - Very easy to disassemble and interface, and very cheap to buy secondhand.
I bought one such serial keyboard for 6$ after I found instructions how to use, but never really used it:
They are £0.50 / $0.70 in the UK - https://uk.webuy.com/product-detail/?id=s360valu009

I can't say I have any reason to use them but am sure they will be useful if I ever do get round to building a Pi Zero or Pico PDA type thing, a tiny Home Computer. Coupled with a Pico they could make a really small USB keyboard which can be used with any Pi, Mac, PC or other Pico.

While out and about, dodging plague yesterday, I came across a second-hand "Zippy WK-500" keyboard which was so sweet and cheap I had to buy it. That's 4" x 9", much like a Psion Series 5 keyboard, except a tad larger.

For me it would be worthwhile figuring how a USB keyboard can be used with a Pico so I can use use that without mods. Or any USB keyboard for that matter.

Looks like adding an OTG cable to a Pico, allowing USB keyboard to send via UART to another Pico, keeping its USB free for use, may be finding its way on to my To Do list.

User avatar
HermannSW
Posts: 4128
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: QWERTY keyboard/keypad for Pico

Fri May 07, 2021 6:14 pm

hippy wrote:
Fri May 07, 2021 11:45 am
HermannSW wrote:
Thu May 06, 2021 10:18 pm
hippy wrote:
Thu May 06, 2021 10:10 am
For "small" I favour XBox Chatpads - Very easy to disassemble and interface, and very cheap to buy secondhand.
I bought one such serial keyboard for 6$ after I found instructions how to use, but never really used it:
They are £0.50 / $0.70 in the UK - https://uk.webuy.com/product-detail/?id=s360valu009

I can't say I have any reason to use them but am sure they will be useful if I ever do get round to building a Pi Zero or Pico PDA type thing, a tiny Home Computer. Coupled with a Pico they could make a really small USB keyboard which can be used with any Pi, Mac, PC or other Pico.
That is really cheap.
But correction, these keyboards are not USB but UART keyboards.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Fri May 07, 2021 8:25 pm

HermannSW wrote:
Fri May 07, 2021 6:14 pm
But correction, these keyboards are not USB but UART keyboards.
I probably wasn't clear; I was envisioning using a Pico to read the chatpad via UART, the Pico acting as a HID device to turn it into a USB keyboard

WestfW
Posts: 82
Joined: Tue Nov 01, 2011 9:56 pm

Re: QWERTY keyboard/keypad for Pico

Sat May 08, 2021 9:51 am

It’s usually pretty trivial to remove the electronics from a standard PC keyboard (any style you want), which will leave a bare key matrix that is probably no more difficult to decode than a laptop arrays, and probably has bigger connectors...

lars_the_bear
Posts: 204
Joined: Thu Jan 28, 2021 8:13 pm
Contact: Website

Re: QWERTY keyboard/keypad for Pico

Sat May 08, 2021 4:00 pm

WestfW wrote: It’s usually pretty trivial to remove the electronics from a standard PC keyboard (any style you want), which will leave a bare key matrix that is probably no more difficult to decode than a laptop arrays, and probably has bigger connectors...
Sure. Problem is that it can be difficult to work out the matrix arrangement. It would be nice to think, for example, that a 4x10 keypad was electrically arranged into 4 rows and 10 columns, or vice versa, but often that isn't the case. Manufacturers will try to minimize the number of scanning lines. That's why I'd rather use a keypad that comes with a wiring diagram.

Kevin.


hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Sat May 08, 2021 4:45 pm

lars_the_bear wrote:
Sat May 08, 2021 4:00 pm
WestfW wrote: It’s usually pretty trivial to remove the electronics from a standard PC keyboard (any style you want), which will leave a bare key matrix that is probably no more difficult to decode than a laptop arrays, and probably has bigger connectors...
Sure. Problem is that it can be difficult to work out the matrix arrangement.
I have done that and it doesn't take too long. You can simply connect the wires to random GPIO pins then have code figure out which is connected to which when a key is pressed, have it determine which are rows and columns, and even have the code build up most of the keyboard mapping.

Unless you are building your own keyboard from switches and wiring your own matrix you are going to have to figure out how it is wired.

lars_the_bear
Posts: 204
Joined: Thu Jan 28, 2021 8:13 pm
Contact: Website

Re: QWERTY keyboard/keypad for Pico

Sat May 08, 2021 5:55 pm

hippy wrote:
Sat May 08, 2021 4:45 pm
Unless you are building your own keyboard from switches and wiring your own matrix you are going to have to figure out how it is wired.
Not if it comes with a circuit diagram.

I'd venture to suggest that, unless you're lucky, or have some inkling how the matrix is connected, figuring out the wiring isn't quite as easy as you suggest. I'm not saying it's rocket surgery, but it's tedious.

I don't know -- I thought that, given the number of point-of-sale terminals and kiosk terminals that have full-size keypads, that there would be hundreds to choose from, costing in a few quid. But maybe they're all custom made? In any case, the ZX81 keyboard somebody mentioned above is the nearest thing I've seen for sale. And there's no problem getting a circuit diagram for it.

Kevin.

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Sat May 08, 2021 7:23 pm

lars_the_bear wrote:
Sat May 08, 2021 5:55 pm
I'd venture to suggest that, unless you're lucky, or have some inkling how the matrix is connected, figuring out the wiring isn't quite as easy as you suggest. I'm not saying it's rocket surgery, but it's tedious.
That's where code comes in. Here's an example for a matrix which has 8 wires, connected in any convenient order to GPIO 0 through 7. Set it running, press all keys, one at a time, hit Ctrl-C in the REPL when done ...

Update : See later post for more optimal code

From that, pressing just two keys - actually jamming jumper wires into holes - we can see I linked 0-to-1 / 1-to-0 and 0-to-5 / 5-to-0.

I can't find my original code, and it's in M6800 assembler anyway, and long ago, so I can't remember how to work out which are rows and which are columns but I'll try and figure it out.

Update : See later post

Then, with rows and columns figured out, you can use another program, pressing the keys in order A-Z, 0-9, F1-F12, determine which row and column they are on, reverse that to get most of the key mapping. The rest have to be entered by hand but the code will tell you which row and column you are pressing and where in the table that should go.
Last edited by hippy on Sun May 09, 2021 12:43 pm, edited 1 time in total.

User avatar
shabtronic
Posts: 74
Joined: Mon Feb 08, 2021 11:13 pm

Re: QWERTY keyboard/keypad for Pico

Sun May 09, 2021 8:01 am

For me it would be worthwhile figuring how a USB keyboard can be used with a Pico so I can use use that without mods. Or any USB keyboard for that matter.

Looks like adding an OTG cable to a Pico, allowing USB keyboard to send via UART to another Pico, keeping its USB free for use, may be finding its way on to my To Do list.

tiny usb keyboard example here:

https://github.com/raspberrypi/pico-exa ... t/host_hid

You just need to power the pico via vbus 5v so it will route that thru to the usb socket and power the keyboard. Tiny usb doesn't work with all keyboards at the moment - wireless or devices that have hidden hub layers - but there's a update coming soon apparently that may fix that.

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Sun May 09, 2021 12:39 pm

An update to the auto-magical reverse engineering of a keyboard matrix.

It struck me, providing only the keyboard matrix is connected, the wires can go to any of the Pico GPIO, in any order, and the code can sort it all out -

Code: Select all

from machine import Pin
import time

wires = 22

matrix = [ "-" * wires ] * wires
input = [ None ] * wires

def Chr(n) : return chr(ord("A") + n)
def Ord(c) : return ord(c) - ord("A")
  
try:
  while True:
    for op in range(wires):
      for ip in range(wires):
        input[ip] = Pin(ip, Pin.IN, Pin.PULL_UP)
      pin = Pin(op, Pin.OUT)
      pin.low()
      time.sleep(0.1)
      for ip in range(wires):
        if ip != op and input[ip].value() == 0:
          matrix[op] = matrix[op][:ip] + Chr(ip) + matrix[op][ip+1:]

except KeyboardInterrupt:
  pass

finally:
   for ip in range(wires):
      Pin(ip, Pin.IN, Pin.PULL_UP)

typ = [ "N/C" ] * wires

for n in range(wires):
  if typ[n] == "N/C":
    if matrix[n] != "-" * wires:
      typ[n] = "Row"
      for w in range(wires):
        c = matrix[n][w]
        if c != "-":
          typ[Ord(c)] = "Col"
          
rows = []
cols = []
for n in range(wires):
  if   typ[n] == "Row" : rows.append(n)
  elif typ[n] == "Col" : cols.append(n)
  
if len(rows) > len(cols):
  rows, cols = cols, rows
  for n in range(wires):
    if   typ[n] == "Row" : typ[n] = "Col"
    elif typ[n] == "Col" : typ[n] = "Row"
    
print("# Raw Matrix")
print("#")
for n in range(wires):
  print("# {} {}\t{} : {}".format(Chr(n), n, typ[n], matrix[n]))
print("")
print("rows = {} # {} Outputs".format(rows, len(rows)))
print("cols = {} # {} Inputs".format(cols, len(cols)))

For example, a 3x4 matrix ...

Code: Select all

# Raw Matrix
#
# A 0	N/C : ----------------------
# B 1	N/C : ----------------------
# C 2	N/C : ----------------------
# D 3	N/C : ----------------------
# E 4	N/C : ----------------------
# F 5	Col : ------------MNO-------
# G 6	Col : ------------MNO-------
# H 7	Col : ------------MNO-------
# I 8	Col : ------------MNO-------
# J 9	N/C : ----------------------
# K 10	N/C : ----------------------
# L 11	N/C : ----------------------
# M 12	Row : -----FGHI-------------
# N 13	Row : -----FGHI-------------
# O 14	Row : -----FGHI-------------
# P 15	N/C : ----------------------
# Q 16	N/C : ----------------------
# R 17	N/C : ----------------------
# S 18	N/C : ----------------------
# T 19	N/C : ----------------------
# U 20	N/C : ----------------------
# V 21	N/C : ----------------------

rows = [12, 13, 14] # 3 Outputs
cols = [5, 6, 7, 8] # 4 Inputs
The code can of course generate the scan routine which needs to be used from 'rows' and 'cols'.

WestfW
Posts: 82
Joined: Tue Nov 01, 2011 9:56 pm

Re: QWERTY keyboard/keypad for Pico

Tue May 11, 2021 3:05 am

I thought that, given the number of point-of-sale terminals and kiosk terminals that have full-size keypads, that there would be hundreds to choose from
Nah; they've mostly come pre-made with some sort of built-in encoder since the early 80s. PC, PS/2, ADB, Uart, USB, Bluetooth... Whole companies have made their fortunes building keyboards with "easy" interfaces.
I built a parallel ASCII keyboard in the late 70s based on a "surplus" keyboard (that wasn't at all cheap) and the "CMOS Cookbook" circuit, but I haven't seen any bare keyboards in a long time. (I do have a small collection of mini and folding keyboards (mostly UART) from the PDA era, but the recent versions seem to be bluetooth.)

I'm with Shabtronic and Hippy - decoding an unknown keyboard isn't as hard as you think. In particular, you don't need to do it before you connect it up. (IIRC, the CMOS CB circuit required the matrix to be in ascii-ish order, which was a real pain...)
Figure out the wiring for the official RPi Keyboard might be of general benefit. https://howchoo.com/pi/official-raspber ... -and-mouse (although the internals could theoretically change without notice.) (but: relatively expensive...)

Why do you want a bare matrix, anyway?

lars_the_bear
Posts: 204
Joined: Thu Jan 28, 2021 8:13 pm
Contact: Website

Re: QWERTY keyboard/keypad for Pico

Tue May 11, 2021 10:58 am

WestfW wrote:
Tue May 11, 2021 3:05 am
Why do you want a bare matrix, anyway?
I don't, particularly. I want something that is compact (e.g., a 4x10 layout), easy to interface, and easy to build neatly into a piece of equipment without a lot of fiddling. Since scanning the matrix is relatively straightforward, I have no particular need for a keyboard with electronics, even if such a thing were available that matches my requirements.

To be honest, I really thought such things would be widespread and cheap. I guess I was mistaken. Oh, well.

Kevin

hippy
Posts: 9959
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: QWERTY keyboard/keypad for Pico

Tue May 11, 2021 3:31 pm

lars_the_bear wrote:
Tue May 11, 2021 10:58 am
I want something that is compact (e.g., a 4x10 layout), easy to interface, and easy to build neatly into a piece of equipment without a lot of fiddling.
That's the XBox 360 Chatpad to a tee. Small, elegant, 4 x 10 ( 47 keys with familiar QWERTY keyboard layout ), easy to interface ( two UART signals plus power ), easy to mount. It is small, 1.7" x 4", so not suited to all applications, but is good quality and nice to use considering how small it is.
lars_the_bear wrote:
Tue May 11, 2021 10:58 am
Since scanning the matrix is relatively straightforward, I have no particular need for a keyboard with electronics, even if such a thing were available that matches my requirements.
That feels like a case of 'cutting your nose off to spite your face', opting for the more complicated option while discounting alternatives which may be easier to obtain, easier to use or cheaper to buy.
lars_the_bear wrote:
Tue May 11, 2021 10:58 am
To be honest, I really thought such things would be widespread and cheap. I guess I was mistaken. Oh, well.
They probably are but not on the off-the-shelf market. They are not things many hobbyists would use so it makes little sense for anyone to stock them.You would probably need to approach a keyboard manufacturer but they perhaps won't be interested in one-off sales.

Given the $4 cost of a Pico is pretty much nothing in the grand scheme of things, if someone asked me how they could have keyboard input, I would say get another Pico, set it up as a USB host, decode key presses and send characters over UART to the project's Pico. That way any USB keyboard can be used.

I would code the project Pico to accept characters over a virtual USB serial port driven by 'minicom' so development can continue without that add-on hardware being available, having made sure my receive character routine can be easily switched between virtual serial port and UART.

lars_the_bear
Posts: 204
Joined: Thu Jan 28, 2021 8:13 pm
Contact: Website

Re: QWERTY keyboard/keypad for Pico

Tue May 11, 2021 6:44 pm

Well, you're right, of course. I was just hoping there was something readily available, that was designed specifically to be integrated into another piece of equipment. For the record, I'm looking for something that will fit into the lid of this case:
case.jpg
case.jpg (244.21 KiB) Viewed 332 times
There's only about 8mm of top-to-bottom clearance, so conventional mechanical key-switches won't fit (I tried). A Pico or Promicro will just fit under a membrane keypad of some sort.

Kevin

Return to “General”