Close

Does this project spark your interest?

Become a member to follow this project and don't miss any updates

ZX Keyboard

An Arduino based project to convert an old broken ZX Spectrum computer in to a USB keyboard.

Similar projects worth following

This project was created on 07/24/2014 and last updated 2 months ago.

Description
This is a project to convert an old ZX Spectrum in to a fully usable USB keyboard that will function with a PC, Raspberry Pi, or an Android device that supports HID devices via a USB host adapter.

More about the history of the hack and a background to the decision making process please see my blog. For the source code and other files please see the GitHub repository. (Links below)
Details

he USB communication is achieved using the VUSB library from Objective Development that is wrapped in the VUSB for Arduino library. The USB hardware is based on a design from the book Practical Arduino and as all the hard work is being done in code is frighteningly simple.

The keyboard is a simple matrix with 5 columns and 8 half rows. Each column is pulled to ground one at a time while the others are left floating. We can then poll the rows (done in two block operations). As we are using the internal pull up resistors inside the Arduino we do not need any external components to do this. It is worth noting that we are using the analogue pins as digital pins but that is fine and how the micro-controller is designed to work. We also need to remove the LED from PIN 13 as this will interfere with the pull-up function.

The keyboard operates in two different modes. When you are typing normally the key presses are simply mapped on to the relevant HID code. When Caps Shift is pressed a shift “modifier" is sent along with the letters just as would happen on a normal USB keyboard.

Where it gets a little more complex is when we are pressing Caps Shift and a number are pressed as these are used for navigation, caps lock, and delete. When this happens we don't send any modifier and map the key to the navigation, caps lock, and delete respectively. If a letter and a number is pressed we then do send the shift modifier that may give an unexpected outcome on a PC, but that will always be the case without writing a special keyboard driver for the keyboard, and doing so will maximise compatibility with most spectrum emulators.

When Symbol Shift is pressed we enter another mode. This is because we need to pretend some symbols are typed with shift pressed, and some without. As a compromise we send a single press and release of each symbol that is typed and do not return to the normal mode unless the Symbol Shift key is released. We also send an unmodified alphanumeric key if there is not sensible symbol to map to for emulator compatibility.

The keyboard de-bounce is achieved by a simple delay of around 100ms that is an age in modern times but needed for the old membrane keyboards that physically bounce. We have had to disable timer0 as it causes the USB to behave unreliably and this breaks the delay() function, so we call delayMicroseconds() several times to do the same thing.

Components
  • 1 × ZX Spectrum An original Sinclair ZX Spectrum with a working keyboard.
  • 1 × Ardunio Pro Mini A 5V ATMEGA328 based clone will work fine.
  • 1 × 2.2KΩ Resistor
  • 2 × 68Ω Resistors
  • 2 × 3.6V Zener diodes Must be rated at 0.5W or less
  • 1 × USB A plug and lead You can reuse an old USB lead
  • 1 × Short length of cable Ribbon cable is prefect but I used old Cat5 cable

Project logs
  • "Direct" mode added

    2 months ago • 0 comments

    I have just added a "direct" mode that does not map the spectrum keys to the ones expected from a standard PC keyboard like before. This is useless most of the time but essential to get the ZX Keyboard working with some Spectrum emulators. To enable the direct mode a hardware switch has been added to the A4. Short to ground to enable direct mode. Leave open to stick with PC emulated mode.

    When active all alphanumeric keys, enter and space are directly mapped regardless of any shift buttons being pressed. Caps Shift is mapped to the left shift key and Symbol Shift to the left control key. This works with all the emulators that the original emulated PC keyboard mode.

  • Debugging the USB

    4 months ago • 0 comments

    When I was experimenting with the V-USB library I found it useful to monitor the message being sent in to the computer an compare them with a traditional USB keyboard. The best tool I found for this on the Windows platform is the HHD's Free USB Analyser.

    One word of warning in the installer can pull in some "crapware" that was caught by the virus scanner but I called the company and the site (separate from there main site) is apparently legitimate.

    The reason why I mention this now is that I have had some problems with Virtual Box and VMWare USB integration and tracked it down to the analyser. Uninstalling it fixed the problem and you can reinstall without issue when it is needed again though.

    Happy debugging.

  • ZX Keyboard tested with JSSpeccy

    4 months ago • 0 comments

    I have tested the ZX Keyboard with JSSpeccy created by the demo scene genius Matt Westcott running on a PC. The good news, and somewhat expectedly, it works.

    The bad news is that, like Fuse, the key mapping I have done to get the Keyboard to work with modern operating systems has broken compatibility. I am now looking at implementing an emulator compatibility mode by using a hardware switch or key combination.

View all 7 project logs

Build instructions
  • 1

    Remove the old workings from an old ZX Spectrum. (but never destroy a working one!)

  • 2

    Solder the keyboard connectors to the Arduino Pro Mini via some wires.

  • 3

    Build the USB adapter using the 5 components. A copy of the circuit diagram is in the GitHub repository.

See all instructions

Discussions

Similar projects