Wednesday, February 13, 2008

Reading a PS/2 keyboard using Arduino and Picaxe

So, i have a Picaxe 18X just lying around, not doing much at the moment. So i thought, why not put it to good use?

This involves reading key presses on a standard PS/2 keyboard using the KEYIN command from the Picaxe and then sending the key data to the Arduino. It is all very straightforward, and of course the strain on the Arduino is very minimal (compared to actually trying to code and read the keyboard purely in Arduino).

The good news is that it only uses a few resistors as external electrical components.

This is the exact schematic that i used, and it works great. Please note that this does not include the download cable for the Picaxe - refer to the first Picaxe user manual for more details. In reference to the pinheader - Arduino pin 1 is 5V, pin 2 is the RX pin and pin 3 is ground. The PS/2 pinheader is numbered as a standard mini 6-pin DIN connector.

Picaxe Code:
main:
keyin
serout 7,N2400(keyvalue)
goto main


Very quick and dirty Arduino code -- at least it sees something!
byte data;
byte old = 0;

void setup() {
Serial.begin(2400);
}

void loop() {
if(Serial.available() > 0) {
data = Serial.read();
if(data != old) {
Serial.print(data, DEC);
old = data;
}

}
}

4 comments:

Anonymous said...

Excellent project. both on the
Arduino and PICAXE side. It is a common mistake to try to load everything into one micro.

Another use for the PICAXE would be an IR receiver.

TANSTAAFL!

Myc

Sebastian Tomczak said...

yes, exactly. i guess, if you have the resources to spare, adding more than one IC or uC to a project is often a good idea and makes the whole thing easier.

_zynU said...

great idea!
I am trying now to slave the arduino, using it as a MIDI receiver, and send data to the main Picaxe.

David J Barnes said...

Very insightful!