ZX Keyboard

July 31st, 2014 by Alistair MacDonald Leave a reply »
A ZX Spectrum converted in to a USB keyboard on show at Manchester Mini Maker faire.

The ZX Keyboard, a USB keyboard made from an old ZX Spectrum on show at Manchester Mini Maker Faire.

Several year ago I decided that I wanted to make an old ZX Spectrum keyboard work with an emulator and ended up making one in to a USB keyboard. This is the rather waffly history of the project with a few tips and links for building your own. I have also created a Hack a Day page for the basic build instructions and a GitHub repository for the files.

Although I have never owned a working rubber keyed ZX Spectrum (mine was a Spectrum+ with a more solid tactile keyboard) I was given a broken rubber keyed one many many years ago. It was in a bit bashed up and did not work, and I have used a few of it’s components to fix other machines, but surprisingly the keyboard was okay.

Back in the start of 2012 I wanted to mount a soon to be released Raspberry Pi inside and emulate a full ZX Spectrum, as well as a Commodore 64 just to mess with people’s heads. I waited until the Model B was Pi eventually available but it would not fit without making more modifications than I wanted, and the smaller Model A was a long way off becoming a reality. I then decided that instead of mounting the Pi inside I should turn it in to a USB keyboard so I could use it with a Pi or a normal desktop PC. Naturally I then forgot about it for another couple of years, until for some reason just now.

Several people have asked why I did not use Bluetooth (some more criticising that asking, but whatever) and there was a Kickstarter making new Bluetooth ZX Spectrum style keyboards, but the project was to use an original ketboard, get it working with the Pi, and to do it myself.

Anyway, the build…

The hardware was surprisingly easy with the big unknown being the USB communication to which I considered a few solutions. Lots of projects use  a Arduino Leonardo that can natively emulate a USB keyboard, or reprogramme the Arduino Uno’s serial controller that requires zero extra hardware, but will prevent the Arduino from being programmed via the USB port. I was keen to use a low cost (the one used cost £1.30) Arduino Pro Mini clone and a small number of basic components.

Having decided on the Arduino Pro Mini (yes, I have my cart pull the horse for pet projects) the easy solution (for me because of prior knowledge) was to get the Arduino to emulate a PS2 keyboard and use a cheap PS2 to USB converter. If it was a one off commercial project, or I was against the clock then this is what I would do as it is the quick and easy solution that adds pennies to to cost of the project. This however is a daft pet project that is an ideal excuse to use as a learning experience, so I decided to play with the V-USB library from Objective Development.  In the end I found the VUSB for Arduino library that had done a lot of the porting work for me, although I am bypassing the top levels of the library to increase compatibility and allow multiple keys to pressed. Now I have thins knowledge my default may well be to opt for USB for future projects.

Connecting to the keyboard hardware was easy enough as I reused the original connectors from the old motherboard that already had components missing. The flat cable from the membrane was very tarnished and had cracks across the connections but I chopped an inch off the end and this solved the problem. The connections have been well documented by hobbyists over the years so there was no backwards engineering required. The way it is wired to the Arduino is not just to make things look neat mind. I will also help the software. Instead of having to check each button of each column at a time it is arranged so multiple values can be read in an operation.

The key mapping took a lot of thought and I have tried to make the keyboard usable for normal operations while keeping full compatibility for Spectrum Emulators. I think I have managed that and have written a little about how it works on the hackaday page mentioned at the top of this post.

So that is it. I will be taking the keyboard to future hack days, Bar Camps, and Mini Maker Fairs if you would like to see it. I hope you are inspired to have a go at building one, perhaps a better one than mine. Do let me know if you do. If you want one but don’t have the time or skills to convert your old ZX Spectrum (or any other machine for that matter) then I am happy to do it for a few quid so get in touch.

Update: It appears that the latest Arduino IDE (version 1.6) will not compile the VUSB library because of an old big in it. A quick work around is to install an older version of the Arduino IDE. It works for me with version 1.0.5.

Advertisement

27 comments

  1. Sean Higgins says:

    Hi,

    Great project.
    I have been looking at doing this. I bought a couple of different Pro Mini clones but cannot get them to be recognised as an USB device.

    I have downloaded your sketch to them, so that side works. I guess the sketch adds the USB bit, or is there something to do with the Bootloader I have to do?

    Also I read something about the LED on D13. And that you have to connect an additional resistor to D13 and the other end to GND?

  2. Hi Sean. Have you built the hardware as documented on GitHub? It has to be set up the same as documented there or it will just not work. Also you will need to add a pull-up resistor between pin 13 and 5V if you do not remove the LED. I suspect a 10K resistor will do but I have not tested this.

  3. Sean Higgins says:

    Thanks for the quick reply Alistair.
    I did build via GitHub info.
    I did try to read up on ‘pull-up’ resistors, I am a mech eng with elec interests so have to read up about most of these thing! :)
    I connected D13 to GND not 5V, maybe that is my mistake? When people say ‘remove’ LED, you mean actually knock it off the PCB? or is there another meaning?
    If this is the case I think most people would leave the LED alone, so adding the ‘pull-up resistor’ info on the elec schematic might be useful?

    Also I guess the device would connect via USB without the actual Spectrum Keyboard attached? – I find it easier to try and get it working without having the keyboard in the way (my wires are not that long :) ).

    I did not find it very easy to find out what connector on the Speccy keyboard ribbons is 1 for ROWS & COLUMNS. I guess if I have wired it back to front it just means the wrong key is outputted rather than the thing not working?

  4. Sean Higgins says:

    Hello Alistair,

    Just to say I got it working:

    http://i62.tinypic.com/2uzfcrt.jpg

    Chap at work removed the D13 LED. i tried using some Pro Mini 328P but no luck. In the end I used a Nano clone.

    I had some issue with one half of the columns being the wrong way around? I kept checking the schematic and could not see a problem. Anyhow I swapped them around and all is great.

    Thanks for the work and sharing it with the World :)

  5. Thanks for letting me know Sean. It always feels good to know my work is appreciated. :-)

  6. Antonio says:

    You sell the arduino programed ?

    I need 2

  7. Hi Antonio. I am afraid I am not in a position to sell them programmed. It is easer to programme than you might think and I imagine you should be able to do it yourself.

  8. Shaun says:

    Hi alistair,
    I have followed all the instruction and built the bread board interface. The problem I am having though is programming the arduino mini pro.
    I can upload to the mini and have no problems with the blinking led example.
    I can’t upload your sketch as it always comes up with an error whilst compiling (Prior to upload).
    Can you help me out please?
    Regards shaun

  9. Antonio says:

    Automatic translation…sonrry.

    I do not know like to programme the arduino.

    Several friends of the forum “Va-de- retro ” they have tried it without success.

    They say that the code has mistakes or is false, but I see that there are persons who have obtained it.

    I try to programme with arduino 1,6,0 with your sketch and the librarie vusb-for-arduino-005.zip but also I have the code of ” compilation error “.

  10. jt says:

    Alistair

    Can I confirm, on your 1.1 pdf of the circuit diagram have you included the resistor to pin 13 or does that diagram still show the circuit as having “led removed” from pro…

    I see 2 resistors there.. but not sure if there should be 3 if i can’t remove the led from my pro..

    Thanks..

  11. Shaun, it could be many things going wrong but my guess is either that the VUSB library is not installed properly, or that you have cut and pasted the source from GitHub without selecting raw first.

    The first thing to try is to upload one of the VUSB examples. If that works try downloading the source from GitHib. If you are still stuck then probubly best to email me though my contact page.

  12. pedro lopez says:

    I think this sketch is really a fake.

    No lost your time try upload this to arduino.

  13. Antonio,

    Oddly a Mr Lopez had the same problem. He was rather rude to me so I did not publish his comment and asked him to look elsewhere for help. Thank you for being polite.

    If several people on Va-de-retro are having problems I wonder if it might be related to language settings. Can you check that the VUSB library is working first by installing one of the examples. Then can you download another Arduino project from GitHib then try and upload that to an Arduino.

    Just to clarify this does work, I have demonstrated it at fairs, and that others have taken my work and reproduced it.

  14. Jt,

    The diagram is of what I have actually built and know works. I took the LED off and did not add another resistor.

    Adding a resistor should work but I do not want to be publishing things I have not tested. Please feel free to submit a GitHub push request, or just email me if you do this and it works.

    Removing the LED was not hard though. I did it using a soldering iron to heat the ends (switching between them quickly) and a screwdriver to knock it off. For more guidance on this check out the Ben Heck podcast on YouTube.

  15. Mr Lopez,

    I will let this one comment through so others can see your opinion on my project, but please stop posting now and leave me alone.

  16. Sean Higgins says:

    To Mr Lopex & other people – THIS PROJECT WORKS.

    Mine built from 1.1 – http://i62.tinypic.com/2uzfcrt.jpg

    It is difficult. I am a Arduino/electronics noob but I can solder (the worse kind of noob :) ), and I did it.
    I had strange things along the way, I installed reinstalled Arduino 1.5.5 then 1.6 etc etc. It does not help with so many Arduino clones being about.

    A key (for me) was to remove the LED physically from the Arduino board. I did not edit the SKETCH at all.

    Don’t worry about the Spectrum to start with as it adds complications. Build the circuit. Plug into USB port with Windows loaded and open up Notepad etc. Just touch the Arduino contacts together to simulate the keyboard press. If it works move onto the next phase – integrating the Spectrum keyboard.

    Remember this is a difficult project, but it can be done.

    Please don’t take it out on the developer if you cannot do it. He did not have to publish his work – I am glad he did. :)

  17. Sean Higgins says:

    Question Alistair, I’ve been having a play with Speccy emulators on my Raspberry Pi.
    A lot of the emulators use ‘F’ keys to get into a menu/load games etc.

    As I will mainly be using this keyboard for emulation can I use the ‘PC Direct Mode’ to map an ‘F’ key to a key?

    Or maybe ‘F’ keys are already there with a button press combination?

    I probably just need 2 F keys.

    Thanks

  18. Sean, thank you for the kind words. It means a lot to know people are thankful.

    As for changing the function of the keys in direct mode, yes that is easy enough. Find the function fillReportBufferDirect() and look down the list within for the key you want to change. You can have a guess at the new constant name of the key, but if it will not compile or does not do what you were wanting then search online for Hut1_12v2.pdf and lookup the key code you need and use that instead.

  19. Sean Higgins says:

    Many thanks (and for the quick reply)
    Just did a quick and dirty mod & it works :)
    Just substituted 1-9 to F1-F9. All with a flick of the PC-Speccy mode switch. Nice :)

    Now I am trying to substitute 0 for ESC as Fuse uses that to quickly exit the menu, but I am having Compiling issues:

    Keyboard_1_1_SeanMod.ino: In function ‘void fillReportBufferDirect()’:
    Keyboard_1_1_SeanMod:193: error: ‘KEY_ESC’ was not declared in this scope

    What does that mean? ESC is not referenced anywhere in the sketch, but neither are the ‘F’ keys and they work?

    Thanks.

  20. Yes, KEY_ESC is not declared in the library. First try KEY_ESCAPE, and if that does not work try the code 0x29 instead.

  21. Sean Higgins says:

    I already tried _ESCAPE (sorry I should have said).

    But… I just tried 0x29 and that works!!! Great!!
    Shame time is getting late, just time for a quick RPi / Speccy fiddle then bed ;-)

    Many thanks for the help

  22. Shaun Morris says:

    Absolutely outstanding work Alistair.

    This is my first Arduino build and I can only say to the doubters out there that it is genuine, as is Mr McDonald himself.

    Great blog Alistair and thank you so much for sharing your work with us.

    Now I’m just struggling with a zx spectrum emulator to boot from power on (Hint Sean please help me).

    Regards

  23. Sean Higgins says:

    Hi Shaun,

    It’s great when you get the keyboard working isn’t it!

    First thing, what system are you using to emulator on?
    If it is Raspberry Pi then download this emulation distrubution:

    http://blog.petrockblock.com/retropie/retropie-downloads/

    Once you copy games into the correct folders, then the emulators appear.

    Another new emu is this one:

    https://sourceforge.net/projects/zesarux/

    It has to be compiled, but instructions are in the readme.

    What is your aim? A RPi that just boots into Speccy emulator? I have spare early 256mb Model B RPi that I am think of doing this on.
    Recent changes to the emulators mean that this should be much easier to do. Before it was a pain gettting fullscreen etc.

  24. David Bulmer says:

    Hi Alistair,
    loving the setup, had been trying for ages to get a keyboard remap version working well (using a cannibalised USB flexible keyboard controller) but eventually gave up and went down your route of Arduino interface.
    I have your sketch working fine on a 48k speccy, but wondered if you had ever managed to do something similar with a spectrum 128k as I have a broken grey +2 just crying out for this mod, but unfortunately the extra keys on the 128 keyboard are problematic, and I wondered if you had figured out how to remap these?

  25. Hi David, I did look at this a while ago and I believe the 128K membrane is compatible with the 48K one. This is achieved by having multiple layers on the membrane so pressing a new key does the same electronically as pressing a shift and the relevant key. In short it should just work.

  26. Mark Howard says:

    Hi Alistair,

    I am having the same problem as Sean Higgins in that I am using a 328P Arduino Pro Mini and it is not recognised by Windows 10. (Unknown USB Device (Device Descriptor Request Failed)).

    I have followed the GitHub instructions exactly. I found VUSB for Arduino 005 library and added it. The script uploads with no problems using Arduino IDE 1.0.6.

    I have also uploaded the USBKeyboardDemo1 script and get the same result.

    I have left the LED on pin 13 in place and added a 10k pull up resistor, I don’t think this would interfere with the USB operation?

    I have enjoyed building the ZX Spectrum USB keyboard and would love to see it working.

    I think that I have either not installed the libraries properly or the 328P Arduino Pro Mini is incompatible.

    Can you help?

    Regards,

    Mark.

Leave a Reply

css.php