Go Down

Topic: Connecting a PS2 Keyboard to an Arduino (Read 2018 times) previous topic - next topic

eddygrinder

Jun 15, 2011, 11:13 pm Last Edit: Jun 15, 2011, 11:47 pm by eddygrinder Reason: 1
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: [Select]
/*  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

eddygrinder

#1
Jun 15, 2011, 11:16 pm Last Edit: Jun 15, 2011, 11:48 pm by eddygrinder Reason: 1
Wow, the above topic is pretty ugly!  :~

Here is some errors:

In file included from sketch_jun15a.cpp:1:
Code: [Select]
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

robtillaart


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

Rob Tillaart

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

eddygrinder



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

robtillaart


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.
Rob Tillaart

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

eddygrinder



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!!!!!??? :0 :0 :0 :0

The damn file has html code!!!!  :0 :0 :0

eddygrinder

So... ignorance aside, i cleaned the damn html code but i kept gettin this error:
Code: [Select]

/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

eddygrinder

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


PaulS

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?

MarkT

#9
Jun 18, 2011, 07:05 pm Last Edit: Jun 18, 2011, 07:07 pm by MarkT Reason: 1
Try putting the library in sketchbook/libraries/ where user libraries belong - I think the compiler picks up some different #includes for things from there.
[ I won't respond to messages, use the forum please ]

justjed


html code!? What the h€ll!!!!!??? :0 :0 :0 :0

The damn file has html code!!!!  :0 :0 :0


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: [Select]

// http://www.quadibloc.com/comp/scan.htm
// http://www.computer-engineering.org/ps2keyboard/scancodes2.html

Which doesn't matter, as it's commented out.
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Go Up