Let's Make Robots!

Connecting a PS2 Keyboard to an Arduino

Hi, 
This is my first post.

My name's is Eddy and I'm a teacher from Portugal. I'm helping a student with a project - persistence of vision - and i need help on Connecting a PS2 Keyboard to an Arduino. The ideia is to type the letters using a keyboard...

I'm trying to compile this exemple:

/*  PS2Keyboard library example
  
  PS2Keyboard now requries both pins specified for begin()

  keyboard.begin(data_pin, irq_pin);
  
  Valid irq pins:
     Arduino:      2, 3
     Arduino Mega: 2, 3, 18, 19, 20, 21
     Teensy 1.0:   0, 1, 2, 3, 4, 6, 7, 16
     Teensy 2.0:   5, 6, 7, 8
     Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
     Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
     Sanguino:     2, 10, 11
  
  for more information you can read the original wiki in arduino.cc
  at http://www.arduino.cc/playground/Main/PS2Keyboard
  or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
  
  Like the Original library and example this is under LGPL license.
  
  Modified by Cuninganreset@gmail.com on 2010-03-22
  Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/
   
#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  5;

PS2Keyboard keyboard;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  Serial.println("Keyboard Test:");
}

void loop() {
  if (keyboard.available()) {
    
    // read the next key
    char c = keyboard.read();
    
    // check for some of the special keys
    if (c == PS2_ENTER) {
      Serial.println();
    } else if (c == PS2_TAB) {
      Serial.print("[Tab]");
    } else if (c == PS2_ESC) {
      Serial.print("[ESC]");
    } else if (c == PS2_PAGEDOWN) {
      Serial.print("[PgDn]");
    } else if (c == PS2_PAGEUP) {
      Serial.print("[PgUp]");
    } else if (c == PS2_LEFTARROW) {
      Serial.print("[Left]");
    } else if (c == PS2_RIGHTARROW) {
      Serial.print("[Right]");
    } else if (c == PS2_UPARROW) {
      Serial.print("[Up]");
    } else if (c == PS2_DOWNARROW) {
      Serial.print("[Down]");
    } else if (c == PS2_DELETE) {
      Serial.print("[Del]");
    } else {
      
      // otherwise, just print all normal characters
      Serial.print(c);
    }
  }
}

 

and i kept gettin' this errors:

 

C:\Users\User\Documents\arduino-0022\arduino-0022\libraries\PS2Keyboard\PS2KeyboardExt.cpp:25: error: 'byte' does not name a type

C:\Users\User\Documents\arduino-0022\arduino-0022\libraries\PS2Keyboard\PS2KeyboardExt.cpp:34: error: 'PROGMEM' does not name a type

I've followed this "How To"

 

Thx a lot

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hmm few weeks ago, unsure if you still got the problem.  The error doesn't imply anything wrong with your library installation per se. The compiler can't relate "byte" and "PROGMEM" to anything because these are declared in <wiring.h> and <avr/pgmspace.h> respectively. (And probably not included from PS2KeyboardExt.cpp.)

Try adding this at the top of that file (at the top of your sketch might also work), and try again.

#include <wiring.h>

#include <avr/pgmspace.h>

 

Like he said, he didn't have the library installed at first.
The PS2 library should include the other libs it needs automagically 

Look at the error in the initial post. Does that imply he does not have libraries installed? It shows the full correct path to them on his local filesystem. Exactly where it should be.

Seriously. If he did not have the library installed, how could the Arduino IDE find the files, and even bork on the types referenced in the file? Not installed, no file, no errors on the contents.  In fact, it would bork during compile on  "include <PS2Keyboard>" with a file not found error.

The errors above absolutely do not imply that...

(Also, nothing "automagical" happens in the Arduino IDE... Oddly enough you have to include any classes and or libraries referenced by included classes, and all the parent classes that your used classes derive from in your main sketch or it simply won't compile...)

 

never mind...

Hi there,

I manage to fix my problem. So, as i said on previous posts, i've deleted this file PS2KeyboardExt.cpp and the program works like a charm. Still i have no clue what's wrong with the file. As far as i know, the program works without PS2KeyboardExt.cpp

Oh btw, good to hear you managed to get it working one way or another. :)

So,

Sick of the same errors i've deleted the file PS2KeyboardExt.cpp, and got no errors on compiling.

(http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html)

 

Anyone have a clue about this errors on PS"KeyboardExt.cpp?

 

Thx and cheers

EddY

how you were getting errors with PS2KeyboardExt.cpp when you never show it as being included in your original program.

Have you been to this, http://www.arduino.cc/playground/Main/PS2KeyboardExt, website?

 

Hi,

Yes, i've been there.

#include <PS2Keyboard.h>

#include <PS2Keyboard.cpp>

const int DataPin = 8;

const int IRQpin =  5;

 

PS2Keyboard keyboard;

 

void setup() {

  delay(1000);

  keyboard.begin(DataPin, IRQpin);

  Serial.begin(9600);

  Serial.println("Keyboard Test:");

}

 

void loop() {

  if (keyboard.available()) {

 

    // read the next key

    char c = keyboard.read();

 

    // check for some of the special keys

    if (c == PS2_ENTER) {

      Serial.println();

    } else if (c == PS2_TAB) {

      Serial.print("[Tab]");

    } else if (c == PS2_ESC) {

      Serial.print("[ESC]");

    } else if (c == PS2_PAGEDOWN) {

      Serial.print("[PgDn]");

    } else if (c == PS2_PAGEUP) {

      Serial.print("[PgUp]");

    } else if (c == PS2_LEFTARROW) {

      Serial.print("[Left]");

    } else if (c == PS2_RIGHTARROW) {

      Serial.print("[Right]");

    } else if (c == PS2_UPARROW) {

      Serial.print("[Up]");

    } else if (c == PS2_DOWNARROW) {

      Serial.print("[Down]");

    } else if (c == PS2_DELETE) {

      Serial.print("[Del]");

    } else {

 

      // otherwise, just print all normal characters

      Serial.print(c);

    }

  }

}

 

... And i kept getting the same errors

 

Hi, 

Thx you all!

 

I still dont't get it. I think i have all the libraries installed.

The contents of arduino-0022\libraries\PS2Keyboard\ are:

Keywords.txt

 PS2Keyboard.cpp

PS2Keyboard.h

PS2KeyboardExt.cpp