PS2 Keyboard Code Problems with LCD

With this PS2 keyboard code which is taking input from a ps2 keyboard I have some issues when I try and send the data to my Serial LCD.

#include <NewSoftSerial.h>

#include "binary.h"
typedef uint8_t boolean;
typedef uint8_t byte;
#include <PS2Keyboard.h>

NewSoftSerial mySerial(8, 9);

#define DATA_PIN 4
PS2Keyboard keyboard;
  int r = 0;

void setup() {

int keyIn(){
  int key1 = 0;
  while(!keyboard.available()) {}
  key1 = -'0';

  return key1;

void loop() {
  r = keyIn();
  mySerial.println(r, DEC);

I have used it for my LED colour mixer, saving the data as numerical values to send to LEDs but when I try to just send the data to my LCD display I get the number followed by two random blocky unknown characters. This normally occurs when I try and do serial.println becuase the display does not accept new line commands but I have checked through the code and there doesn’t seem to be anything wrong.

Anyone understand?

Anyone help?


two random blocky unknown characters

Truly random, or consistent from string to string?

CR/LF, perhaps?

have you tried printing their hex values?

key1 = -'0';

Is only really useful for ASCII decimal digits 0x30…0x39.

Ok, random to me but consistent on each string.

CR/LF? What is that?

No I haven’t just tried printing hex values, I will try that.

The thing is that it prints fine to the normal computer serial using the arduino program.


CR/LF == carriage-return/line-feed 0x0D/0x0A, but if you’re subtracting 0x30, they’ll come out as 0xDD/0xDA

I don’t think so because it used to have serial.println for a new line and I removed all of that stuff that I could find.