USBZX Keyboard

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

USBZX Keyboard

Unread post by pgimeno »

Apologies if this isn't exacty MiSTer related, but it's a project that was born in these forums and with the idea of being used with the MiSTer. It's also an open "libre" project and I don't think I'll provide pre-built units so it's clearly not for profit.

Those who have been following the Recreated ZX Spectrum support thread may remember that I've been working on this project. Given the general lack of availability for Recreated keyboards, I liked the idea initially raised here by Chris23235 to use an actual ZX Spectrum case with a USB controller that could serve as a USB keyboard, instead of having to find and buy an expensive Recreated keyboard. The drawback is that you lose the Recreated's NKRO (even though the Speccy never had actual NKRO in the first place) and the possibility of connecting via Bluetooth.

It turns out that there are several projects about the same thing:

  1. https://www.instructables.com/ZX-Spectr ... rd-Part-1/ (same article is available in other webs)
  2. http://web.archive.org/web/202210060749 ... -part-two/ (archived version, as original link is now defunct)
  3. https://hackaday.io/project/2076-zx-keyboard
  4. https://www.instructables.com/ZX-Spectr ... RetroPie-/

Each had its drawbacks:

  • The first one requires a Minimus USB, which is sadly no longer sold. The firmware's source code is not public.
  • The second one doesn't provide any firmware, and requires lots of glue.
  • The third one requires a MCU well above what's necessary for this project, and requires you to make modifications to the MCU board: "The Arduino's LED on pin 13 needs to be removed or a pullup resistor to VCC added".
  • The fourth one doesn't provide the PCB modifiable files, therefore the PCB is not "open source". It uses a Teensy 3.2 which is also no longer sold. The firmware kind of sucks, and doesn't specify a license.

So, I started this project with the goal of including:

  • Full Kicad files for both a Spectrum/Spectrum+ PCB and a ZX81 PCB. Of course the associated Gerber files too (currently pending because there's no official release yet).
  • Open source firmware which can be built with standard tools, that doesn't need an Arduino IDE.
  • Support for both normal USB protocol (which is limited to 6KRO) and Recreated protocol (which supports full NKRO). Note that the normal USB protocol just provides the raw keys used by the Spectrum; it's not intended for use as a generic keyboard, but just for emulation. To control the emulator, you additionally need a normal keyboard; in the case of the MiSTer, you could also use a controller with the Menu button mapped.
  • Support for using a Spectrum case with a ZX81 core, and vice versa. Talk about a "ZX 81 Spectrum" :D

I also got rid of the need for diodes and pull-up resistors used in the other projects, using the MCU's built-in high-impedance and internal pull-up features. So, if two rows are connected because two keys are pressed for the same column, e.g. Caps Shift+P (see PJ Evans' diagram on the problem), the high-impedance state of the rows not being scanned suffices to prevent a short, and the reading is meaningful with no diode necessary.

Current status (Sep 21, 2024)

Thanks to Alejandro (wilco2009) who did a field test of the second, corrected PCB (the first one had some screws misplaced), some problems were detected and corrected. The current PCB has not been tested yet, but when it is, a release will be made. Problems identified by Alejandro were:

  1. With a socket, the MCU is too high and clashes with the keyboard.
  2. The USB cable clashes with the case too.
  3. The MCU's µUSB connector is too flimsy; he broke his and had to make some repair work.
  4. There were two rows flipped. This was a software problem which I quickly fixed and he has confirmed to be working fine again.
  5. Some keys were not working properly. Again, a software problem solved by raising the settle time delay before reading the inputs.

The first two problems were a rookie mistake on my side, which was fixed by moving the MCU to the top of the board in the new version.

The third problem was solved with this approach: the board will have a microUSB cable that will be cut and soldered to a USB-C connector added to the PCB via a breakout board. This way, the internal cable will not need to be moved or disconnected, and a USB-C cable can be used to connect the unit. The case window used is that for the TV connector, which is the highest and provides the most leeway space for the placement of the USB-C connector.

Additionally, I've placed ribbon connectors at several heights just in case your ribbon cable is too short or something like that. The bottom ones are placed at the height that an Issue 3B Spectrum has them, the idea being to prevent bending those flimsy ribbons more than they were when they were connected to their original board.

Project link: https://codeberg.org/pgimeno/ZXUSBKB

Pics of the old board, with the MCU in what will be its new placement:

Rubber ZX Spectrum case:

Rubber Spectrum USBZX placement.png
Rubber Spectrum USBZX placement.png (798.92 KiB) Viewed 3115 times

 

ZX Spectrum+ case:

Spectrum+ USBZX placement.png
Spectrum+ USBZX placement.png (789.77 KiB) Viewed 3115 times

 

Preview of the new board:

Top side:

image_2024-09-21_10-21-43.png
image_2024-09-21_10-21-43.png (42.3 KiB) Viewed 3115 times

 

Bottom side:

image_2024-09-21_10-25-54.png
image_2024-09-21_10-25-54.png (34.94 KiB) Viewed 3115 times

The ZX81 board is currently on hold, until I can get a decent ZX81 case for measurements; the one I bought had the screwing points for critical screw positions broken.

AmintaMister
Posts: 313
Joined: Thu Sep 16, 2021 10:54 pm
Has thanked: 840 times
Been thanked: 51 times

Re: USBZX Keyboard

Unread post by AmintaMister »

A great THANKS for you beautiful work!!! I can't wait to see the ZX81 project! If you want please send me a private message, I have many empty ZX81 cases I can send you right away one!

jordi
Posts: 282
Joined: Thu Jun 11, 2020 10:11 am
Has thanked: 112 times
Been thanked: 87 times

Re: USBZX Keyboard

Unread post by jordi »

Love this idea

ghorricks
Posts: 46
Joined: Fri Jan 07, 2022 11:27 am
Has thanked: 8 times
Been thanked: 6 times

Re: USBZX Keyboard

Unread post by ghorricks »

I'd love to be able to use a +2 /A /B or +3 with this too!

FPGA64
Top Contributor
Posts: 937
Joined: Mon Mar 01, 2021 3:10 pm
Has thanked: 49 times
Been thanked: 374 times

Re: USBZX Keyboard

Unread post by FPGA64 »

You are aware that there are USB C versions of the Pro Micro so you wouldnt need the exntension cable ?

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: USBZX Keyboard

Unread post by pgimeno »

FPGA64 wrote: Sun Sep 22, 2024 3:28 pm

You are aware that there are USB C versions of the Pro Micro so you wouldnt need the exntension cable ?

I wasn't. I'll look into that as it seems cheaper and simpler, thanks for the tip. It forces the MCU to be very close to the border if exiting through the TV connector, but hopefully that won't be a problem if I go 2-sided (which I've avoided just for cosmetic reasons).

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: USBZX Keyboard

Unread post by pgimeno »

ghorricks wrote: Sun Sep 22, 2024 11:42 am

I'd love to be able to use a +2 /A /B or +3 with this too!

I haven't seen the inside of one of those. It's purely a question of connections, you can always make a more rudimentary solution with an idea similar to this one: http://web.archive.org/web/202112151550 ... 2264-1.jpg

The pinout of a Pro Micro is here: https://golem.hu/pic/pro_micro_pinout.jpg (archived version, in case the link dies)

The pins used by the project are: for rows, in ascending Z80 address order (A8-A15), the ones labelled B3, F6, F5, F4, F7, B1, B2, B6 (they are all in the bottom right side), and for columns, D0, D1, D2, D3, D4 (funnily, the port names correspond exactly to the Z80 data lines used). These are in the top left, with two GND pins in the middle.

The mode ports are C6 (Recreated mode), D7 (Alternative mode) and E6 (ZX81 mode), marked as 7, 6 and 5 in the MCU. Connecting each of these to GND will activate it.

Anyone can make their own that way without needing a PCB.

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: USBZX Keyboard

Unread post by pgimeno »

wilco2009 and I have looking into the +2 keyboard connections and it seems they're not so trivial. It's trivial if you only will use the alphanumeric keys, Caps, Symbol and Enter; apparently, however, the special keys are not activated mechanically like in a Spectrum+, but they have their own lines and their special handling.

wilco2009 is in touch with spark2k06 (the author of the PCXT core) who apparently wrote a +2 to PS/2 keyboard adapter; hopefully he'll be able to provide some insights.

This means a specialized board for +2 and later will be necessary, and I'm concerned that there aren't enough pins in the MCU to handle the 13 + 11 lines in the keyboard, so the extra lines will probably need to be handled with additional electronics in the PCB. Hopefully nothing more than diodes and resistors will be necessary, but I can't tell for sure. It might be the case that a bigger MCU with more I/O lines, or maybe additional logic gates to handle these special key lines, become necessary.

For now I'll focus on Spectrum, Spectrum+ and ZX81 support. Not sure if the 128K "Toastrack" uses the same layout and connectors, but if so, the same Spectrum/Spectrum+ will be usable. Alas, no numeric keypad support.

FPGA64
Top Contributor
Posts: 937
Joined: Mon Mar 01, 2021 3:10 pm
Has thanked: 49 times
Been thanked: 374 times

Re: USBZX Keyboard

Unread post by FPGA64 »

If you used a Toastrack for this you would be hunted down and killed. They are very rare now days

ghorricks
Posts: 46
Joined: Fri Jan 07, 2022 11:27 am
Has thanked: 8 times
Been thanked: 6 times

Re: USBZX Keyboard

Unread post by ghorricks »

pgimeno wrote: Thu Sep 26, 2024 2:42 pm

wilco2009 and I have looking into the +2 keyboard connections and it seems they're not so trivial.

Over the years it has been clear the 128's are different and more difficult to do anything with the keyboard.
I appreciate that the 48's are considered classics, and the community has focused on this effort though.

The Amstrad made 128's (not toast rack) do have the best usable keyboard, and with plenty of room inside the cases for additional boards (pi, mister, other) I believe it is time for those with the knowledge to see if there is an appetite or funding that can make this possible. I'm happy to contribute some cash, maybe others are?

My dream would be a +2 which houses a MiSTer or PI (bare metal) which is linked to the Datacorder.
Able to output HDMI and use the keyboard, joystick ports and reset switch on the side.

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: USBZX Keyboard

Unread post by pgimeno »

Well, I can only try to help with turning a case into a USB keyboard.

Here's the keyboard matrix for a +2: http://web.archive.org/web/202409261703 ... lpdBkUvLLw

Clearly the first 8x5 part of the matrix is the same; the extra keys will need special handling. I'll look into what can be done.

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: USBZX Keyboard

Unread post by pgimeno »

Thanks to AmintaMister's generous contribution, now I have a ZX81 case with the screwing points in perfect shape! So thanks a lot @AmintaMister. Sorry for posting so often; the case arrived just a few minutes ago.

I've also ordered a couple ProMicro MCUs with USB-C, so hopefully I will have a final Spectrum PCB soon, and make faster progress on the ZX81 PCB.

Exile
Posts: 1
Joined: Sun Sep 29, 2024 9:25 am

Re: USBZX Keyboard

Unread post by Exile »

In case it is of interest, there is a description and code for making a ZX81USB keyboard based around a 3d printed ZX81 case and Raspberry Pi Pico at https://github.com/ikjordan/ZX81_USB_KBD It is very rough and ready, with no PCB, but it does the job. As the Readme says,

those with more hardware skills than me could fabricate a dedicated PCB, including mounting the Pico 2040

so it would fit in with this project.

The ZX81 case design is well suited to 3d printing, which saves having to break up an existing ZX81.

Several have used the keyboard design to build a solution using the Raspberry Pi Pico based ZX80 / ZX81 emulator, picozx81 https://github.com/ikjordan/picozx81

Post Reply