PS2 Keyboard library not loading

I have been working with Arduino for the past few weeks. I am having issues including PS2 Keyboard library. I tried every steps laid out on this thread but no luck.

Could someone explain me what I am doing wrong? I would really appreciate any feedbacks.

My code is uploaded here on github.

I am getting the following error:

In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from PS2Communication/PS2Communication.h:34,
from PS2Communication/PS2Communication.cpp:29:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from barcode_v1.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]

warning "Defaulting to Release Build"
^
barcode_v1.cpp: In function 'void setup()':
barcode_v1.cpp:12:33: error: no matching function for call to 'PS2Communication::begin(const int&, const int&)'
int i;
^
barcode_v1.cpp:12:33: note: candidate is:
In file included from barcode_v1.cpp:2:0:
PS2Communication/PS2Communication.h:134:10: note: void PS2Communication::begin()
void begin();
^
PS2Communication/PS2Communication.h:134:10: note: candidate expects 0 arguments, 2 provided
barcode_v1.cpp: In function 'void clearBarcode()':
barcode_v1.cpp:31:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
b[i] = c;
^
make: *** [barcode_v1.o] Error 1

Error: Could not compile. Please review your code.;

I’ve reformatted your error report and will have a look - give me some time tho’ :wink:

But as far I can see the thread you referenced is not actually using my lib.
While I look into your intended use case, you might want to have a look at the example that comes with the library.
It’s mainly targeted at PS/2 mice, but since they are more complicated than keyboards, you might get the neccessary clues for your case too.


Looking at your error report, these are the important clues

...
barcode_v1.cpp:12:33: error: no matching function for call to 'PS2Communication::begin(const int&, const int&)'
...
note: candidate expects 0 arguments, 2 provided

PS2Communication does not provide a function begin() that takes two parameters.
The way you’d set the pins for your needs goes via the constructor. But if you do use the default pins D0 & D1, you can omit them.


Some other notes

    ...
    else {
      b[i] = c;
      i++;
    }
    ...

This code is prone to break your program, due to the lack of boundary checks (<13).

and

  Spark.variable("Barcode", &b, STRING);

Don’t use the ampersand & here!

1 Like

I really appreciate you replying me on this. How can I load up your library? This is the only way I know how to load a library. Could you tell me whats right library to use? I am such a newbie here.

Could you give me an example of this please?

How can I rewrite the code then?

I would appreciate a any feedbacks.

Thanks!

Sure

// for alternative pin assignment
PS2Communication keyboard = PS2Communication(dataPin, clkPin);

  ...
  keyboard.begin(); // no parameters here - that easy
  ...
  Spark.variable("Barcode", b, STRING); // no ampersand - just as easy

About the library usage:
You are right there.
If you want to include the lib in your own project, just press INCLUDE IN APP, then you’ll get a list of your own projects where you select your desired one and press USE IN THIS APP.
If you want to try one of the provided examples click the sample file (e.g. PS2MOUSE.INO) and press USE THIS EXAMPLE.
You can’t use APPLICATION.CPP sample in Web IDE - as the three line comment clearly states :wink:

1 Like

I really appreciate your help! I made those changes and still getting the some error. Here is the code:

    #include "PS2Communication/PS2Communication.h"
    
    const int DataPin = D0;
    const int IRQpin = D1;
    int i;
    char b[13];
    
    void setup() {
        PS2Communication keyboard = PS2Communication(DataPin, IRQpin);
        keyboard.begin();
        delay(1000);
        Spark.variable("Barcode", b, STRING);
      
    }
    
    void loop() {
     
     if (PS2Communication.available()) {
    
        int c = PS2Communication.read();
    
        if (c == 0) {
              }
        else {
          b[i] = c;
          i++;
        }
      }
      
    }

And I am getting the following error :frowning:

> In file included from ../inc/spark_wiring.h:29:0,
> from ../inc/application.h:29,
> from PS2Communication/PS2Communication.h:34,
> from PS2Communication/PS2Communication.cpp:29:
> ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
> #warning "Defaulting to Release Build"
> 
> In file included from ../inc/spark_wiring.h:29:0,
> from ../inc/application.h:29,
> from barcode_v1.cpp:2:
> ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
> #warning "Defaulting to Release Build"
> ^
> barcode_v1.cpp: In function 'void loop()':
> barcode_v1.cpp:19:22: error: expected primary-expression before '.' token

> ^
> barcode_v1.cpp:21:29: error: expected primary-expression before '.' token

What am I missing?

In your original code you had keyboard declared as global and this is how it should be (mark the different indentation in my code snippets ;-))
I also mentioned, that the default pins are just the same as you use, so you would not need the alternative pin mapping.

Just try this

#include "PS2Communication/PS2Communication.h"
    
PS2Communication keyboard;
// for other pins to use replace pinData & pinClk
//PS2Communication keyboard = PS2Communication(pinData, pinClk);

char b[13];
int i;
    
void setup() 
{
  keyboard.begin();
  delay(1000);
  Spark.variable("Barcode", b, STRING);
}
    
void loop() 
{
  int c;

  while(keyboard.available()) 
  {
    c = keyboard.read();
    if (c != 0 && i < sizeof(b) - 1) 
      b[i++] = c;
    b[i] = 0; // make sure to terminate string
  }
}
2 Likes

I have loaded the code. I did not have any issues with it, however the barcode characters are messed up. I need to dig further into this problem. I really appreciate you helping me on this matter!

1 Like

In what way are the characters messed up?
Do you receive wrong characters or are you just getting mixed up barcodes?

If it’s the latter, it might well be the syncronisation issue, that I was talking about in the other thread you found.
An additional delay(10); inside the while() might help a bit in a general way. But you need to find a way to figure out where the boundaries between seperate barcodes are.

Furthermore you might need to look into the data you scanner produces and the interna of the PS/2 keyboard protocol, since a “normal” keyboard data packet does not actually transmit the ASCII character you press but carries scan codes, make and break codes and other things (and sometimes even many at once).

I am just recieving bunch of question marks. I have a friend who is an arduino guru, he is going to take a look at it tomorrow. I will keep you posted!

I think this is a hardware issue. Could you check this post and see if I am doing something wrong here.

Thanks!