Optocoupled Amstrad CPC 464 USB Keyboard

The project

This time we are going to use our CPC 464 or CPC 8162 as a USB regular keyboard, but still using our 80’s 8 bits computer. Both at the same time!!

To succeed we need to isolate the 3.5v of the CPC Keyboard (Sound) chip AY-3-8912 and let our Arduino Leonardo know that a key was pressed.

The CPC knows that a key is pressed by checking rows (R) and columns (C). Current moves from C to R. There are 10 rows (C1-C9) and 9 columns (R1-R10).

But, how does Leonardo works? More or less the same that CPC. By crossing columns ( Pins 0-8 ) and rows (9-12, A0-A5).

byte rowPins[ROWS] = {9, 10, 11, 12, A0, A1, A2, A3, A4, A5}; //connect to the row pinouts of the keyboard
byte colPins[COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; //connect to the column pinouts of the keyboard

Amstrad CPC 464 USB Keyboard

The project

As I was not completely satisfied coding with my ZX Spectrum + keyboard, I decided to implement the same with an Amstrad CPC 646 without altering the original parts, and leaving it steal useful.

So I decided to buy some connectors, solder them in a small PCB and pin the rows and columns into an Arduino Leonardo that is able to send keboard codes to a computer through the HID USB interface.

Don’t leave your old computer in your storage!! Transform it into a useful retro USB keyboard!

How to start?

Yo need:

  • Old Amstrad CPC 464 o CPC8162
  • One arduino Leonardo
  • FCB Connectors (Flex Circuit Board conennector)
  • Some cables
  • USB cable
  • Solder

 

First, make it easy by soldering the connector and some cables to a board.

You can still reuse the Arduino Leonardo board and connect both the Keyboard cols and rows of the FCB to the Leonardo, and to the Amstrad mainboard, too:

Please take note of the connectors that are confronted (contacts face to face) to connect them easily to the main board.

Yo need two connector (9 pins for the columns and 10 for the rows). The first row and comumn is dedicated to the DEL key!!

Here I show you the Spanish keyboard matrix. Please take care of the equivalent keys when using different layout:

You have to include the Keypad and Keyboard libs.

#include <Keypad.h>
#include <ctype.h>
#include <Keyboard.h>

Define the number of cols and rows:

const byte ROWS = 10; //ten rows
const byte COLS = 9; //nine columns

And finaly the “normal” keys and “special” keys.

I am defining two layouts that are commuted when CAPS Lock key is pressed:

char alphaKeys[ROWS][COLS] = {
{ KEY_BACKSPACE,' ',' ', ' ', ' ', ' ', ' ', ' ', ' '}, //1 
{ ' ','1','2', KEY_ESC, 'q', KEY_TAB, 'a', 0x04, 'z'}, //11 0x04 => KEY_CAPS_LOCK = Map change
{ ' ','4','3', 'e', 'w', 's', 'd', 'c', 'x'}, //12 
{ ' ','6','5', 'r', 't', 'g', 'f', 'b', 'v'}, //13
{ ' ','8','7', 'u', 'y', 'h', 'j', 'n', ' '}, //14
{ ' ','0','9', 'o', 'i', 'l', 'k', 'm', ','}, //15
{ ' ',KEY_INSERT,'=', '@', 'p', ';', ':', '/', '.'}, //16
{ ' ',KEY_DELETE,'[', KEY_RETURN, ']', '4', 0x02, '\\', 0x01},//17 0x7e (ª), 0x01 = KEY_LEFT_CTRL, 0x02 = KEY_LEFT_SHIFT
{ ' ',KEY_LEFT_ARROW,0x03, '7', '8', '5', '1', '2', '0'}, //18 0x81 = COPY = Ctrl +c
{ ' ',KEY_UP_ARROW,KEY_RIGHT_ARROW, KEY_DOWN_ARROW, '9', '6', '3', KEY_RETURN, '.'} //19
};
char specialKeys[ROWS][COLS] = {
{ KEY_BACKSPACE,' ',' ', ' ', ' ', ' ', ' ', ' ', ' '}, //1 
{ ' ','!',0x22, KEY_ESC, 'Q', KEY_TAB, 'A', 0x04, 'Z'}, //11 0x04 => KEY_CAPS_LOCK = Map change
{ ' ','

The pins mapping for Arduino Leonrdo :

byte rowPins[ROWS] = {9, 10, 11, 12, A0, A1, A2, A3, A4, A5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; //connect to the column pinouts of the keypad

 

And the photos of the inside:

And the outside

A small video with CAPS Shift and Control Shift functions

 

I will continue soon …

 

 

,'#', 'E', 'W', 'S', 'D', 'C', 'X'}, //12 { ' ','&','%', 'R', 'T', 'G', 'F', 'B', 'V'}, //13 0x26 (&) { ' ','(','\'', 'U', 'Y', 'H', 'J', 'N', ' '},//14 { ' ','-',')', 'O', 'I', 'L', 'K', 'M', '<'}, //15 { ' ',0x80,'_', '|', 'P', '+', '*', '?', '>'}, //16 0x80 (€) { ' ',KEY_DELETE,'*', KEY_RETURN, '+', '4', 0x02, '\\', 0x01},//17 0x7e (ª), 0x01 = KEY_LEFT_CTRL, 0x02 = KEY_LEFT_SHIFT { ' ',KEY_HOME,0x03, '7', '8', '5', '1', '2', '0'}, //18 0x81 = COPY = Ctrl +c { ' ',KEY_PAGE_UP,KEY_END, KEY_PAGE_DOWN, '9', '6', '3', KEY_RETURN, '.'} //19 };

The pins mapping for Arduino Leonrdo :

 

 

And the photos of the inside:

And the outside

A small video with CAPS Shift and Control Shift functions

 

Special mappings

I use special keycodes, not printable (0x01, 0x02, .. 0x06), for sending the HID a combination of keys or special Function Keys (F1-F12).

When the special key is pressed, in the PRESSED state, I call a special function: modKey

case 0x05: 
              if (debug) Serial.println("KEY_LEFT_SHIFT+KEY_LEFT_ALT");
              modKey(KEY_LEFT_SHIFT, KEY_LEFT_ALT);            
              break;
void modKey(char key, int mod)
 {
  Keyboard.press(mod);
  delay(200);
  Keyboard.press(key);
  delay(200);
  Keyboard.releaseAll();
  delay(200);
 }

ZX Spectrum + USB Keyboard

Purpose

I had an old Spectrum + 48k keyboard for years. When I say “for years” I mean more than 20 years. Someone gave it to me in case it is usefull for repairing my brother’s computer that, despite spending hours and hours searching for it in my porent’s house, I have never found.

Well I decided to leave it to fill with basic electronic parts and some cables to connect it to my PC..but time passes fast and the “projects” is never done.

What’s next? Technology advanced and when I find some time for the project (more than 20 years later), I find hundred of related web pages!

Many PS2, some complex schemas, but the easier is that implemented wit Arduino micro controller.

I decided to use Alistair MacDonald code for programming an Arduino Nano. He uses Pro Mini for Zx Spectrum (rubber keykaps) but I wanted to have my keyboard always conected in “developent” mode to reprogram it in real time “as needed”, based on my own user experience.

What I didn’t know jet was that it was the begginig of a kind of “keyboard fever”. The first one of many retrokeyboards!

What do I need?

One Arduino Nano or Arduino Pro Mini

Three resistor (2x2KΩ, 1×68Ω)

One ZX Spectrum +

FCB connecors (somehow difficult to find)

Some cables

How do I start?

The software

First, you better check your Arduino Genuino version. The one that I am using at this time is 1.8.5

Next, remmber to incude “UsbKeyboard.h” in your project. That files will alow you to use the HID (Human Interface Devices) for the Keyboard and use the mapped key codes. UsbKeyboard.h also includes usbdrv.h (the Virtual USb Port) that is responsible for sending the keys through the seril port.

You will find the vusb-for-arduino libraries in Gidhub repository.

You have to copy the USB Keyboard dirctory in the “libraries” directory that it is normaly located in your Documents\Arduino folder.

The hardware

Of course you need some cables,the FCB (flexible circuit board connectors), a tin solder, USB cable …

For me the FCB connector was the most difficult part to find. Write me if you need some directions.

Some photos:

The Circuit board

The Circuit board detail

Arduino soldered (front)

Arduino soldered (back)

What’s next

I really enjoyed my time with this ZX Spectrum + USB keyboard. But, despite being customized for my prefered Caps and Symbol Shift combination keys, the keyboard is not much confortable. In fact I am writing this post with it (it took me long time) and I still need the full version keyboard for those key combinations that I learned time ago and I am unable to change (like Ctrl+C, Ctrl+v).

Therefore I made my next proposal: to connec an Amstrad CPC-464 computer to my PC as a keyboard, that posseses better “mechanical” keycaps with springs!