PS2Keyboard library issue

Hi all,

We've been experimenting with a barcode scanner and the PS2Keyboard library v2.4, but we're running into a problem .

The scanner is a Symbol LS-9100 + wedge for PS/2 connection. We've soldered the PS/2 connector to a cable leading to pin 2 (clock) and 40 (data) on an Arduino Mega 2560. Most of the time, this works just fine!

The problem: following certain actions, the library starts returning garbage for every barcode read. The issue can't be resolved unless the arduino is reset!

What we tried:

  • repeat the .begin(DataPin, IRQpin) call
  • power off and then power on the scanner
  • reducing transmit speed and/or transmit delay of the scanner (up to 99ms delay between each character)

The code is SimpleTest from within the library, we don't think can't get any easier:

#include <PS2Keyboard.h>

const int DataPin = 40;
const int IRQpin =  2;
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 == 'W') {
      Serial.println();
    } else {
      // otherwise, just print all normal characters
      Serial.print(c);
    }
  }
}

The scanner is set to return a 'W' after every barcode (might just as well've been [Enter]), hence the check for it. We're only reading EAN-128 barcodes composed of digits.

Example output for scanning the same barcode over and over:

...
00703229211
00703229211
00703229211
00703229211
00703229uttem0070;uuuttemqq++++++>))&)#@@(@!!
))&)#@@(@!!
))&)#@@(@!!
))&)#@@(@!!
))&)#@@(@!!
))&)#@@(@!!
))&):UUUTTEM))&)#@@(@!!

Any hints or additional debugging tricks that we could try would be highly appreciated :(.

bump :slight_smile: no one with a similar experience? We'd dig further into the library but C++ programming isn't really our forté...

To me it doesn't look like a programming issue but a hardware problem. Have you attached a scope to see what signals you get? A standard PS/2 keyboard might behave differently than your scanner and the library doesn't claim to be compatible with all PS/2 devices. Please scan the signal with a logic analyzer or oscilloscope and post the pictures you get.