Skip to content

ZX Raspberry Version 2

In which our hero downsizes radically

A couple of months ago we held the first in the ‘regeneration’ of the Milton Keynes Raspberry Jam. I took along my ZX Raspberry for all to see and wonder over. One eager and Sinclair-experienced attendee soon put me in my place. “Shame it’s so laggy”, he said. Ah. A brief defence of the necessary compromises in design ensued but I had to admit he was right, it was laggy; too laggy to be of any real use if you finally want that Jetpac high-score.

A couple of weeks later, in one of those classic ‘shower’ moments, I realised that the build was vastly overcomplicated. Recent Raspberry Pis have more than enough GPIO inputs for the ZX Spectrum’s keyboard matrix (13) and my experiences with the Atarpi project had shown me that handling keyboard inputs in Raspian had come a long way.

So here’s the original ZX Raspberry:

And here’s our version 2:

Keep it simple, right? This version takes all the keyboard lines direct to the GPIO (with a switch for handling keyboard modes) and uses a Python script to scan the keyboard for presses which uses the python-uinput module to inject those keypresses into the kernel. Did I think Python would work? Not for a second. It did. Brilliantly. The new ZX Raspberry v2 is significantly more responsive and the Raspberry Pi Zero W has plenty of horsepower to run everything.

I also decided to move to RetroPie as the OS for this project as it is just so good and refined. Setup was a breeze and Fuse works perfectly. I’ve finally got rid of that dratted mouse pointer too. As a bonus, the bluetooth capabilities of the Zero W mean I could pair a PS3 controller and use it as a Kempston joystick. Again, never expected it to work. Again, worked perfectly.

My ZX Raspberry v2 made its debut at the second Milton Keynes Raspberry Jam last weekend. There were no complaints*.

* Ok, one. “Have you got Chuckie Egg?” “Does this look like a BBC to you?”

UPDATE: After many requests, I’ve made the Python keyboard scanning script available on Github along with some notes to get you started.

Published inMakesRaspberry PiVintage Tech

8 Comments

  1. Great stuff! I’ve just ordered a replica case from Retro Radionics with the idea of doing the keyboard mod and maybe the Pi later but the cleanness of this has changed my mind.

    I have an original Model B and original Zero gathering dust. I guess there’s enough Pins on the Model B for this but the Zero could potentially be switched into gadget mode and be a USB keyboard in addition.

  2. Jozef Gallik Jozef Gallik

    Hello, great work!
    I had an idea to make just simple keyboard version for PC with emulator from my old Didaktik Gama (Czechoslovakian Spectrum clone) and found your page. After seeing you using Raspberry Pi for the complete standalone HW/SW emulator, I followed your path and seized your knowledge with version 2 (Raspberry Pi only and Retropie) 🙂
    Now, the job is done, waiting just for some additional extension cables and fan to finish the back design of the keyboard nicely with all connectors and ventilation.

    I would like to report just couple hickups to you:

    1. the libsuinput library didn’t install on my system based on your guide for some reason and as I am not very skilled with linux, fortunately I have found help on the library home site as alternative way descibed below:
    git clone https://github.com/tuomasjjrasanen/libsuinput.git
    cd libsuinput
    ./autogen.sh
    ./configure
    make
    make install

    2. The Raspberry Pi is overheating, so I checked and it seems that the Python running is getting 100% of CPU, while Fuse only something around 20% – not sure how the CPU is running on 120%, expecting that each core has it’s own 100%.. Anyway, is there some way how to make the script use some kind of interruptions or so, so that it’s not taking that much CPU, please?

    3. Not sure if it’s possible, or it’s more of an OS issue, but the ZX keyboard is not usable in linux CLI where each keypress generates at least 3-10 characters typed instead of making a delay after first character written after keypress. Also, we cannot use backspace (shift+0) and we have no other alternative on ZX keyboard. I will try to check and maybe update the script myself, but as I never worked in Python, it will take some time and maybe you have already tried..

    4. Not anything wrong with your guide, just reporting that Didaktics have same type of keyboard as original Spectrum, just the order of pins is different, so I had to connect the 8 pin part of cable pin by pin, each time testing the keys captured. Nothing too difficult.

    That’s all I can remember just now from top of my head. Anyway, great thanks for your guide here, it saves me huge amount of time and also made me ending up with even more enhanced version of the system comparing to what I was about to build first, based only on Arduino board.

    Cheers,
    Jozef

    • PJ PJ

      Hi Jozef,

      Interesting stuff. I haven’t had the CPU problem, nor have I had the cli ‘repeat’ issues you report. try adding some time.sleep(10) after a keypress detection to ‘de-bounce’ it. I’ll have a think about it and report any insights here.

      • Jozef Gallik Jozef Gallik

        Hi PJ,
        yes, that is what I did and it helped me to reduce the repetitive key presses together with the CPU load – from 100% to 1.5% with time.sleep(.05).
        Currently tried to control the fan within the same script, but not successful yet. I am used to debug things, but not sure how to do that with python, especially when it starts after boot.. I think I will need to stop that first and run normally..

  3. Dean Woodyatt Dean Woodyatt

    Thankyou so much for this article. I’ve knocked up a PCB for this and would love to send you one over free for you to play with. let me know where to send it to. The PCB is partially tested and now working for the keyboard matrix bit, just slowly figuring out the emulator side of things. happy to send some pics,

    Oh, and recently spotted the Magpi article, congrats!,

    • PJ PJ

      Hi Dean. Thanks, it was great to be featured! Would love to see the pics. Email me at pj@mrpjevans.com.

  4. Dan Dan

    Hi PJ! I’m trying to turn an old timex Sinclair into a similar device, the keyboard matrix is the same. I was going to use your original tutorial, but this way seems easier.

    I’m getting thrown off by the pin assignments on the github, think you could explain it to me? I’ve used matrix keypads, but never a keyboard before, in my previous experience you just wire the matrix to GPIOs one set as outputs the others as input. Maybe something is different about this keyboard? Why does it have a 3.3v line in? Why does it have 2 ground connections? Is there a reason you didn’t just use all the generic GPIO pins?

    17 <–this is the 3.3v line? why are we connecting to that. – KB1 / 1
    27 <–isn't this a reserved pin for ID_SC? – KB1 / 2
    22 <—GPIO25 makes sense – KB1 / 3
    18 <—-GPIO24 makes sense – KB1 / 4
    23 <—GPIO11, but this is the SPI_CLK pin, which i need for something else. can I reassign?- KB1 / 5

    5 GPIO3 but also the I2C SCL pin – KB2 / 1
    6 GND pin? why? – KB2 / 2
    13 GPIO 2 – KB2 / 3
    19 GPIO12 (but also an SPI pin)- KB2 / 4
    26 GPIO26 – KB2 / 5
    16 GPIO4 – KB2 / 6
    20 Ground again? – KB2 / 7
    21 GPIO13 (but also another SPI pin) – KB2 / 8

    • PJ PJ

      All the pins stated are GPIOn. So, 17 == GPIO17, i.e. They are the Broadcom numbers. Apologies if that was unclear! I’ll update the Readme.

Leave a Reply

Your email address will not be published. Required fields are marked *