Fév 092013
 

This time lets play with Arduino and a ps2 keyboard.

For the record here comes the ps2 male connectors :

ps2_male

A quick schema :

ps2_keyboard_bb

The sketch :

#include 

#define KBD_CLK_PIN  3
#define KBD_DATA_PIN 4

PS2Keyboard keyboard;

void setup ( )
{
keyboard.begin(KBD_DATA_PIN);
  Serial.begin(9600);
  delay(1000);
}

void loop ( )
{
  if(keyboard.available()) {
    // reading the "extra" bits is optional
    byte   extra = keyboard.read_extra(); // must read extra before reading the character byte
    char c = keyboard.read();
    boolean ctrl = extra & 1;  //  is bit 0
    boolean  alt = extra & 2;  //   is bit 1
    if (ctrl) Serial.print('^');
    if (alt)  Serial.print('_');
    //if      (c==PS2_KC_UP)      Serial.print("up\n");
    //if (c==PS2_KC_DOWN)    Serial.print("down\n");
    //if (c==PS2_KC_BKSP)    Serial.print("backspace\n");
    //if (c==PS2_KC_ESC)   { Serial.print("escape and reset\n"); keyboard.reset(); }
    Serial.print(c);   //lets print last input char to our serial monitor
  }   
}

(the PS2Keyboard library : PS2Keyboard)

A picture (i used female – male proto wires so that I did not have to cut out my ps2 keyboard wire).

ps2

 Posted by at 22 h 04 min

  3 Responses to “Arduino : use a PS2 keyboard”

  1. Please help!!!

    « error: no matching function for call to ‘PS2Keyboard::begin(int)' »

  2. […] : display a clock based on a lcd screen and a RTC Arduino : output to a tv (tvout) Arduino : use a PS2 keyboard Arduino : send and receive data thru radio frequency (RF433) Arduino : programming an Arduino Pro […]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.