Introduction: Making a Typewriter With an Old Keyboard and a Dot Matrix Printer
This project shows how to recycle an old keyboard and a dot matrix printer to make a typewriter.
What and how.
The idea is connect the keyboard to the printer with a basic and cheap interface, i have used Arduino because is a fast development board for this kind of projects and have a large community behind. The board read the keyboard signals (use a data/clock system) and transform this info about the character to the printer. Parallel format controlling the strobe.
Hardware.
Is very basic too, a keyboard adapter with clock, data, power and GND (figure-1), a printer adapter with 8 data bits, strobe and GND (figure-2) all this
Connected to Arduino as figure-3.
Software.
The source code.
// Typewriter with an old AT Keyboard and a Dot Matrix printer.
// 2011 www.xbot.es
// Francisco Reinoso "furri"
#include <PS2Keyboard.h> // library to use a PS2Keyboard with Arduino
#include <string.h>
#include <stdio.h>
#define KBD_CLK_PIN 3
#define KBD_DATA_PIN 2
#define d0 4
#define d1 5
#define d2 6
#define d3 7
#define d4 8
#define d5 9
#define d6 10
#define d7 11
#define strobe 12
#define autofd 13
PS2Keyboard keyboard;
int caracter = 0;
void setup() {
keyboard.begin(KBD_DATA_PIN);
pinMode(d0, OUTPUT);
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(d5, OUTPUT);
pinMode(d6, OUTPUT);
pinMode(d7, OUTPUT);
pinMode(strobe, OUTPUT);
pinMode(autofd, OUTPUT);
digitalWrite(autofd,HIGH);
digitalWrite(strobe,HIGH);
Serial.begin(9600);
delay(1000);
}
#define is_printable(c) (!(c&0x80)) // don't print if top bit is set
void imprime(int letra)
{
// decode character into 8 bits
if (letra >= 128) { letra = letra - 128; digitalWrite(d0,HIGH); } else { digitalWrite(d0,LOW); }
if (letra >= 64) { letra = letra - 64; digitalWrite(d1,HIGH); } else { digitalWrite(d1,LOW); }
if (letra >= 32) { letra = letra - 32; digitalWrite(d2,HIGH); } else { digitalWrite(d2,LOW); }
if (letra >= 16) { letra = letra - 16; digitalWrite(d3,HIGH); } else { digitalWrite(d3,LOW); }
if (letra >= 8) { letra = letra - 8; digitalWrite(d4,HIGH); } else { digitalWrite(d4,LOW); }
if (letra >= 4) { letra = letra - 4; digitalWrite(d5,HIGH); } else { digitalWrite(d5,LOW); }
if (letra >= 2) { letra = letra - 2; digitalWrite(d6,HIGH); } else { digitalWrite(d6,LOW); }
if (letra >= 1) { digitalWrite(d7,HIGH); } else { digitalWrite(d7,LOW); }
// send the character to the printer
digitalWrite(strobe,LOW);
delayMicroseconds(2);
digitalWrite(strobe,HIGH);
}
void loop() {
if(keyboard.available()) {
byte c = keyboard.read();
if ( c == 13 ) { Serial.print(c); imprime(10); }
else
{
if ( is_printable(c) ) { Serial.print(c); imprime(c); } // don't print special characters
}
}
}
What and how.
The idea is connect the keyboard to the printer with a basic and cheap interface, i have used Arduino because is a fast development board for this kind of projects and have a large community behind. The board read the keyboard signals (use a data/clock system) and transform this info about the character to the printer. Parallel format controlling the strobe.
Hardware.
Is very basic too, a keyboard adapter with clock, data, power and GND (figure-1), a printer adapter with 8 data bits, strobe and GND (figure-2) all this
Connected to Arduino as figure-3.
Software.
The source code.
// Typewriter with an old AT Keyboard and a Dot Matrix printer.
// 2011 www.xbot.es
// Francisco Reinoso "furri"
#include <PS2Keyboard.h> // library to use a PS2Keyboard with Arduino
#include <string.h>
#include <stdio.h>
#define KBD_CLK_PIN 3
#define KBD_DATA_PIN 2
#define d0 4
#define d1 5
#define d2 6
#define d3 7
#define d4 8
#define d5 9
#define d6 10
#define d7 11
#define strobe 12
#define autofd 13
PS2Keyboard keyboard;
int caracter = 0;
void setup() {
keyboard.begin(KBD_DATA_PIN);
pinMode(d0, OUTPUT);
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(d5, OUTPUT);
pinMode(d6, OUTPUT);
pinMode(d7, OUTPUT);
pinMode(strobe, OUTPUT);
pinMode(autofd, OUTPUT);
digitalWrite(autofd,HIGH);
digitalWrite(strobe,HIGH);
Serial.begin(9600);
delay(1000);
}
#define is_printable(c) (!(c&0x80)) // don't print if top bit is set
void imprime(int letra)
{
// decode character into 8 bits
if (letra >= 128) { letra = letra - 128; digitalWrite(d0,HIGH); } else { digitalWrite(d0,LOW); }
if (letra >= 64) { letra = letra - 64; digitalWrite(d1,HIGH); } else { digitalWrite(d1,LOW); }
if (letra >= 32) { letra = letra - 32; digitalWrite(d2,HIGH); } else { digitalWrite(d2,LOW); }
if (letra >= 16) { letra = letra - 16; digitalWrite(d3,HIGH); } else { digitalWrite(d3,LOW); }
if (letra >= 8) { letra = letra - 8; digitalWrite(d4,HIGH); } else { digitalWrite(d4,LOW); }
if (letra >= 4) { letra = letra - 4; digitalWrite(d5,HIGH); } else { digitalWrite(d5,LOW); }
if (letra >= 2) { letra = letra - 2; digitalWrite(d6,HIGH); } else { digitalWrite(d6,LOW); }
if (letra >= 1) { digitalWrite(d7,HIGH); } else { digitalWrite(d7,LOW); }
// send the character to the printer
digitalWrite(strobe,LOW);
delayMicroseconds(2);
digitalWrite(strobe,HIGH);
}
void loop() {
if(keyboard.available()) {
byte c = keyboard.read();
if ( c == 13 ) { Serial.print(c); imprime(10); }
else
{
if ( is_printable(c) ) { Serial.print(c); imprime(c); } // don't print special characters
}
}
}

First Prize in the
Keyboard vs. Mouse Speed Challenge
13 Comments
5 years ago
this kind of printer works?
http://www.banggood.com/POS-5890K-58mm-Thermal-Receipt-Printer-Support-WIndows-Linux-p-1053549.html?rmmds=search
Reply 5 years ago
I made this for standard LPT printers (Centronics cable), your printer seems USB interfaced...
5 years ago
hello! this is really a great project!!
I was wondering if it is possible to control, for example, the space between the letters, or something like that - by messing with the code, or actually put that function in one key of the keyboard.
Also, this code can be used for a bigger dot matrix printer? A4, A3 paper size?
Thank you!
Reply 5 years ago
Yes, you can write in a A4 printer, in a laser one also, you can change letter types, bold... and more...
BUT... those things depends on the printer that you are using, you must know the Escape Codes (named Printer Codes too), something like this
http://www.bighole.nl/pub/mirror/homepage.ntlworld.com/kryten_droid/Atari/ST/spg/st_prog_guide_c.htm
I use those codes last time 15 years ago so actual printers don't use i think and to find information about this will be harder and harder, but in searching and discovering is the enjoy.
good luck in your project.
6 years ago on Introduction
Great Build!
9 years ago on Introduction
Been trying this all day and have had no luck. Hopefully you can offer some guidance.
First off, do you tie all the grounds to ground, or just strobe and d0-d7?
http://www.hilmanind.com/pinouts/cent36.htm - looks like there are 15 total grounds.
What about auto-feed, what are you doing with it?
What did you do with all the wires you didn't need? just leave the dangling?
Thanks!
11 years ago on Introduction
i want a dot matrix printer
do you think that you could invent a code that writes without the keyboard
you rock
Reply 11 years ago on Introduction
print without keyboard, easy... What do you want to print?
"I'm the gosth of the printer... HaHaHA"
a good joke.
11 years ago on Introduction
what kind of arduino do I need?
is it works whit uno?
Reply 11 years ago on Introduction
any arduino works
11 years ago on Introduction
Wow.
11 years ago on Introduction
i love it
11 years ago on Introduction
Awesome!