Connecting USB keyboard to Arduino UNO

Hi, I am new to the arduino, but i do have a basic understanding of electronics, and a sound background in programming. I have been trying to connect a USB keyboard to my arduino uno, i have the following connections from the USB keyboard to the arduino pins:

  • --> 5 v+ (power) RED
    D- --> data pin 2 WHITE
    D+ --> data pin 3 YELLOW (I don't have a GRN wire)
  • --> GND (power) BLACK
    (sorry the attached image skews the pin connections, but I am sure that the connections from the USB are going to the pins indicated above.)

I've been trying to use the PS2Keyboard library, and the following example to try to get output from the keyboard:
#include <PS2Keyboard.h>

const int DataPin = 2;
const int IRQpin = 3;

PS2Keyboard keyboard;

void setup() {

  • delay(1000);*
  • keyboard.begin(DataPin, IRQpin);*
  • Serial.begin(9600);*
  • Serial.println("Keyboard Test:");*
    }

void loop() {

  • if (keyboard.available()) {*

  • Serial.println(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("[Lft]");*

  • } else if (c == PS2_RIGHTARROW) {*

  • Serial.print("[Rght]");*

  • } else if (c == PS2_UPARROW) {*

  • Serial.print("[Up]");*

  • } else if (c == PS2_DOWNARROW) {*

  • Serial.print("[Down]");*

  • } else if (c == PS2_DELETE) {*

  • Serial.print("");[/i]*
    * } else {*
    * // otherwise, just print all normal characters*
    * Serial.print(c);*
    * }*
    * }*
    }
    I've tried this with multiple keyboards and i haven't been able to get any to produce any output. I have tested the keyboards with other PCs and the keyboards function. I've also tried to use other pins for the D- connection, but still no luck.
    All of the examples of others doing this have been very simple and straightforward.
    I've spent several hours trying to figure out what I could be doing wrong, can anyone assist me with this???
    Thanks,
    Frank




I think you got the colours correct at least, which is better than what this person had ..... link here ..... where they appear to have got their colours green and white mixed up.

Not sure from the image, are the two data wires plugged into pins 2 and 3, or 3 and 4?

So how do you know this "USB keyboard" will actually respond in PS/2 mode? Did it come with a PS/2 adapter?

If so, it will work as PS/2 but this is not automatically the case. :astonished:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.