Go Down

Topic: PS2keyboard doesn't work in a particular sketch (Read 410 times) previous topic - next topic

Gregg_

May 25, 2019, 12:54 pm Last Edit: May 25, 2019, 01:11 pm by Gregg_
Hi I connected standard PS/2 keyboard to Arduino and am using PS2keyboard library.
I don't have any problems reading input with the standalone standard code
Code: [Select]
#include <PS2Keyboard.h>

const int DataPin = 13;
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 == 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);
    }
  }
}


However when I tried to read from keyboard on other project the
Code: [Select]
keyboard.available()
 returns false!!!


Gregg_

Code: [Select]
#include <LiquidCrystal.h>
#include <PS2Keyboard.h>

LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
const int DataPin = 13;
const int IRQpin = 2 ;

PS2Keyboard keyboard;

void writingtolcd(){
  int i=0;
 
}


void setup() {
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("CryptoC");
    lcd.setCursor(0,1);
    lcd.print("Made by Gregg_");
    delay(2000);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Checking the");
    lcd.setCursor(0,1);
    lcd.print("keyboard...");
    delay(2000);
    keyboard.begin(DataPin, IRQpin);
    delay(500);
    if(!keyboard.available()) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Keyboard not");
      lcd.setCursor(0,1);
      lcd.print("available!");
      delay(3000);
    } 
    else {
      lcd.clear();
      lcd.print("Keyboard");
      lcd.setCursor(0,1);
      lcd.print("detected!");
    }
}

void loop() {
    if (keyboard.available()) {
      lcd.print("Keyboard available!");
      while(1) {
      char c = keyboard.read();
      lcd.print(c);
      }
    }
}


Here is the whole code :)

Gregg_

#2
May 25, 2019, 02:05 pm Last Edit: May 25, 2019, 02:14 pm by Gregg_
It appears that until you do press a key ,keyboard is not detected.
And it has to be a tab.

Go Up