PS2 keyboard Serial Communication

#include <PS2Keyboard.h>
  
String theCommand;

const int DataPin = 2;
const int IRQpin = 3;
PS2Keyboard keyboard;

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

void loop(){
  if(keyboard.available()){
   char c = keyboard.read();
   if(c == PS2_ENTER){
     Serial.println(theCommand);
     theCommand = " "; 
   } else {
    theCommand + c; 
   }
  } 
  
}

im using the code above with the PS2 library, http://playground.arduino.cc/Main/PS2Keyboard
and im getting the following errors:

SERIAL.ino: In function ‘void setup()’:
SERIAL.ino:11:33: error: no matching function for call to ‘PS2Keyboard::begin(const int&, const int&)’
SERIAL.ino:11:33: note: candidate is:
In file included from SERIAL.ino:1:0:
/home/nhsstudent/sketchbook/libraries/PS2Keyboard_014A/PS2Keyboard.h:77:10: note: void PS2Keyboard::begin(int)
     void begin(int dataPin);
          ^
/home/nhsstudent/sketchbook/libraries/PS2Keyboard_014A/PS2Keyboard.h:77:10: note:   candidate expects 1 argument, 2 provided
SERIAL.ino: In function ‘void loop()’:
SERIAL.ino:19:12: error: ‘PS2_ENTER’ was not declared in this scope

any help on this matter would be much appreciated.

The first error message would seem to indicate that you are calling the begin() method of the library with two parameters when only one is expected. Where did you get the syntax for the begin() method from ?

The second error message is simply saying that the constant PS2_ENTER is not defined either by the library or by your code.

It is almost as if there are 2 libraries with the same name and you have used a program written for one version with the other version.

Where is the library installed ? Do you perhaps have two versions with the same name installed in different folders ? Can you please give a link to the library.

The issue definitely has something to do with the library. The example code on the page I linked to is:
#include <PS2Keyboard.h>

#define DATA_PIN 4
PS2Keyboard keyboard;

void setup() {
keyboard.begin(DATA_PIN);

Serial.begin(9600);
Serial.println(“hi”);
delay(1000);
}

void loop() {
if(keyboard.available()) {
byte dat = keyboard.read();
byte val = dat - ‘0’;

if(val >= 0 && val <= 9) {
Serial.print(val, DEC);
} else if(dat == PS2_KC_ENTER) {
Serial.println();
} else if(dat == PS2_KC_ESC) {
Serial.println("[ESC]");
}

The download I used was:
http://playground.arduino.cc/uploads/Main/PS2Keyboard002.zip

I’ll check to see if I have any folders with the same name,
The reason I’m confused is at:
http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
There is the following example code:

#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("");
} else if (c == PS2_RIGHTARROW) {
Serial.print("");
} else if (c == PS2_UPARROW) {
Serial.print("[Up]");
} else if (c == PS2_DOWNARROW) {
Serial.print("[Down]");
} else if (c == PS2_DELETE) {
Serial.print("");
} else {

// otherwise, just print all normal characters
Serial.print(c);
}
}
}
This calls two parameters in keyboard.begin. And uses different names for special keys. I don’t know which code corresponds with the library I used.
Thanks for the help.

Example code 1

keyboard.begin(DATA_PIN);

Your code

 keyboard.begin(DataPin, IRQpin);

It certainly looks like there are two libraries with the same name. Obviously if the begin method is only expecting one parameter then it will barf if it is sent two unless it is written to accept either. The error message you got seems to indicate that that is not the case.

I'm going to try just doing DataPin, and change PS2_ENTER to PS2_KC_ENTER and see if that fixes the problem Thanks for the help

#include <PS2Keyboard.h>


#define DATA_PIN 4
PS2Keyboard keyboard;

void setup() {
  keyboard.begin(DATA_PIN);

  Serial.begin(9600);
  Serial.println("hi");
  delay(1000);
}

void loop() {
  if(keyboard.available()) {
    byte dat = keyboard.read();
    byte val = dat - '0';

    if(val >= 0 && val <= 9) {
      Serial.print(val, DEC);
    } else if(dat == PS2_KC_ENTER) {
      Serial.println();
    } else if(dat == PS2_KC_ESC) {
      Serial.println("[ESC]");
    } 
  }
}

I have added the KC but now I’m getting a new error

In file included from example_sketch.ino:1:
/Users/jenniferburke101/Documents/Arduino/libraries/PS2Keyboard/PS2Keyboard.h:56: error: 'byte' does not name a type
/Users/jenniferburke101/Documents/Arduino/libraries/PS2Keyboard/PS2Keyboard.h:83: error: 'byte' does not name a type
example_sketch.ino: In function 'void loop()':
example_sketch:17: error: 'class PS2Keyboard' has no member named 'read'

I’m using the following library.PS2 keyboard library download
I don’t know why I didn’t get this error earlier, any help would be much appreciated