0

I'm new in the Arduino Community and I'm facing a problem when I try to use a PS2 Keyboard and an LCD Display (16x2) on an Arduino Uno with a Wifi shield.

I would like to write something with the keyboard and display it in the LCD before sending it to a webservice.

Here is my problem:

  • When I use the keyboard and the display on my Arduino WITHOUT the wifi shield --> All is OK. I can write on the display the key that has been pressed.
  • When I use the keyboard and the display on my Arduino WITH the wifi shield --> All is OK until I write something on the display. As soon as I write on the display with the function lcd.print(), the keyboard does not work anymore (it detect the character '2' every time I press a key).

It's very surprisingly because if I dont use lcd.print(), the keybord works without any problem.

Here is a part of my code:

#include <LiquidCrystal.h>
#include <PS2Keyboard.h>

LiquidCrystal lcd(12, 11, 2, 5, 6, 8);
PS2Keyboard keyboard;

const int DataPin = 9;
const int IRQpin = 3;

void setup(){      
  keyboard.begin(DataPin, IRQpin);      
  lcd.begin(16, 2);
}

void loop(){
  checkKeyboard();
}

void checkKeyboard(){
  if (keyboard.available()) {

    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 {
      Serial.print(c);
      displayText(c);
    }
  }
}

void displayText(char c){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Pressed key:");
  lcd.setCursor(0,1);
  lcd.print(c);
}

Does somebody know how to solve this problem?

Thank you very much in advance :)

Edit: Here are the pins that I use on the board :

  • Arduino pin 2 -> LCD pin 11
  • Arduino pin 5 -> LCD pin 12
  • Arduino pin 6 -> LCD pin 13
  • Arduino pin 8 -> LCD pin 14
  • Arduino pin 11 -> LCD pin 6
  • Arduino pin 12 -> LCD pin 4
  • Arduino pin 3 -> Keyboard IRQ
  • Arduino pin 9 -> Keyboard Data
1

Sorry I do not have enough reputation to place a comment.

@Valentin from the link, you provided, to the wifi shield it states that it uses pins 11 ,12 and 13 on the UNO which will give you a conflict on pins 11 and 12 with the LCD. Not sure why that manifests as an apparent keyboard error though:

From the linked page:

Arduino communicates with both the Wifi shield's processor and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Uno and pins 50, >51, and 52 on the Mega. On both boards, pin 10 is used to select the HDG204 and pin 4 for >the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, >53, is not used to select either the HDG204 or the SD card, but it must be kept as an output or the SPI interface won't work.

Again sorry this is not a full answer but thought it may help.

0

You must verify which pins the wifi shield is using and see if they aren't used also by the LCD. Can you provide further details on the wifi shield ?

  • I put the keyboard on the pins 3 (IRQ) and 9 (Data). The LCD use the pins 12, 11, 2, 5, 6 and 8. I know the Wifi shield use some pins. If I correctly read the documentation (arduino.cc/en/Main/ArduinoWiFiShield), the pins 4, 7 and 10 are reserved for the Wifi shield. – Valentin Jan 26 '15 at 16:05
0

As you say, I can't use pins 10, 11, 12, 13 because they are used for the SPI.

-> So, I tried to use the pins 4 and 7 instead of 11 and 12.

The problem is that the pin 7 is used by the Wifi shield (Handshake) and I have no other free digital pin.

-> So, I tried to use an analog pin instead of the pin 7 and ..... it works very well.

Here is my final solution :

  • Arduino Pin 2 -> LCD Pin 4 (RS)
  • Arduino Pin 3 -> Keyboard IRQ
  • Arduino Pin 4 -> LCD Pin 11 (D4)
  • Arduino Pin 5 -> LCD Pin 12 (D5)
  • Arduino Pin 6 -> LCD Pin 13 (D6)
  • Arduino Pin 7 ->
  • Arduino Pin 8 -> LCD Pin 14 (D7)
  • Arduino Pin 9 -> Keyboard Data
  • Arduino Pin 10 ->
  • Arduino Pin 11 ->
  • Arduino Pin 12 ->
  • Arduino Pin 13 ->
  • Arduino Pin 14 (= Analog 1) -> LCD Pin 6 (E)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.