Pages: [1]   Go Down
Author Topic: Connecting a PS2 Keyboard to an Arduino  (Read 1524 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

***********************************************************
Code:
/*  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);
    }
  }
}

I have copied the library to 3 places, because i don't have sure...
.../arduino/libraries/PS2Keyboard/
PS2Keyboard.cpp
PS2Keyboard.h
PS2Keyboardext.cpp

I have the same dir on .../arduino/hardware/PS2Keyboard/ and /arduino/hardware/libraries/PS2Keyboard/

So, i can't find the problem.
Thx a lot for your help,

cheers
EddY
« Last Edit: June 15, 2011, 04:47:54 pm by eddygrinder » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, the above topic is pretty ugly!  smiley-confuse

Here is some errors:

In file included from sketch_jun15a.cpp:1:
Code:
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:10:35: error: invalid suffix "px" on integer constant
(...)
In file included from sketch_jun15a.cpp:1:
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:22: error: stray '#' in program
(...)
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:163:10: error: #include expects "FILENAME" or <FILENAME>
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:164:10: error: #include expects "FILENAME" or <FILENAME>
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:165:10: error: #include expects "FILENAME" or <FILENAME>
In file included from sketch_jun15a.cpp:89:
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:10:35: error: invalid suffix "px" on integer constant
(...)
In file included from sketch_jun15a.cpp:89:
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h:22: error: stray '#' in program
(...)
In file included from sketch_jun15a.cpp:2:
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:24: error: 'byte' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:25: error: 'byte' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:34: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:37: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:38: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:39: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:42: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:47: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:53: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:55: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:57: error: 'PROGMEM' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:60: error: 'byte' does not name a type
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:102: error: 'byte' was not declared in this scope
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:102: error: 'byte' was not declared in this scope
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:102: error: initializer expression list treated as compound expression
C:\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2KeyboardExt.cpp:104: error: expected ',' or ';' before '{' token
« Last Edit: June 15, 2011, 04:48:15 pm by eddygrinder » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12428
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Please modify your post, select all code and press the # button. (maybe do an auto format first in the IDE => CTRL-T)

you must close all IDE's before a new library is seen, they are loaded at boottime of the first instance IIRC.

Rob

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Please modify your post, select all code and press the # button. (maybe do an auto format first in the IDE => CTRL-T)

you must close all IDE's before a new library is seen, they are loaded at boottime of the first instance IIRC.

Rob



Done! Much better... thx!

I've done that. Every time i modify the dir, i re-started the IDE, but the results were the same!

Thx
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12428
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you post your - :\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h - file?

The compiler sees this file but it doesn't "understand" the contents.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you post your - :\Users\grinder_2\Documents\arduino-0022\libraries\PS2Keyboard/PS2Keyboard.h - file?

The compiler sees this file but it doesn't "understand" the contents.

html code!? What the h€ll!!!!!??? smiley-mad smiley-mad smiley-mad smiley-mad

The damn file has html code!!!!  smiley-mad smiley-mad smiley-mad
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So... ignorance aside, i cleaned the damn html code but i kept gettin this error:
Code:
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:24:1: error: 'byte' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:25:1: error: 'byte' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:34:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:37:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:38:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:39:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:42:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:47:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:53:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:55:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:57:1: error: 'PROGMEM' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:60:1: error: 'byte' does not name a type
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:102:17: error: 'byte' was not declared in this scope
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:102:31: error: 'byte' was not declared in this scope
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:102:43: error: expression list treated as compound expression in initializer [-fpermissive]
/usr/share/arduino/libraries/PS2Keyboard/PS2KeyboardExt.cpp:104:1: error: expected ',' or ';' before '{' token

Now, i'm running under Linux, by the way!

Thx a lot
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Sick of the same errors i've deleted the file PS2KeyboardExt.cpp, and got no errors on compiling.
That removed all the functionality, too, and most likely resulted on linker errors, instead of compiler errors.

What version of the IDE are you using?

Have you tried including WProgram.h in the source file?
Logged

0
Offline Offline
Shannon Member
****
Karma: 160
Posts: 10416
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try putting the library in sketchbook/libraries/ where user libraries belong - I think the compiler picks up some different #includes for things from there.
« Last Edit: June 18, 2011, 12:07:39 pm by MarkT » Logged

[ I won't respond to messages, use the forum please ]

CO, USA
Offline Offline
God Member
*****
Karma: 4
Posts: 710
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

html code!? What the h€ll!!!!!??? smiley-mad smiley-mad smiley-mad smiley-mad

The damn file has html code!!!!  smiley-mad smiley-mad smiley-mad

I downloaded the zip file from PJRC, and unzipped it. I see no HTML markup in either the .h or the .cpp file. Unless you're referring to:
Code:
// http://www.quadibloc.com/comp/scan.htm
// http://www.computer-engineering.org/ps2keyboard/scancodes2.html
Which doesn't matter, as it's commented out.
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Pages: [1]   Go Up
Jump to: