Reading keyboard input from upload port

Good evening,

I'm trying to read messages from a keyboard connected to the upload port of the Arduino (the port used to connect it to the pc), but I'm having no success so far. I've been trying to read it with the Serial class:

void setup() {
  // initialize serial:
  Serial.begin(115200);
  // set the digital pin as output:
  pinMode(RELAY_PIN, OUTPUT);
}

void loop()
{
  if (Serial.available()) {
    if (relayState == LOW)
      relayState = HIGH;
    else
      relayState = LOW;
    
    digitalWrite(RELAY_PIN, relayState);
    delay(1000);
        
    Serial.println("Here");
    while (Serial.available()) {
      char inChar = (char) Serial.read(); 
    }
  }
}

I've also tried common C functions, such as getc or scanf, but I get nothing. Any idea on how to do this?

Thanks!

Someone can correct me on this, but I pretty sure both a keyboard and an Arduino are slave devices. So what you want to do, can not be done without an interpreter, like a computer.

You might be able to use a USB host shield, but it still may not work without a correct driver, if one even exists.

Thanks for the reply!

I found this library online http://arduino.cc/en/Reference/KeyboardControllerConstructor and it theoretically does what I want, if I understood it correctly, but I couldn't find where to download it. Besides that, why would it work on a USB Host Shield, but not directly in the upload port?

why would it work on a USB Host Shield, but not directly in the upload port?

Because a USB Host shield contains a USB Host, where as the upload port is a USB client. The two are very different.

Here is more to that link, USBHost This only works with an Arduino Due.

Here is the master library file. USB_Host_Shield

The USB port on the Arduino is a client, not a host, so in order for what you want to work, you need a USB host. And that is why there is a USB shield.

Added: Mike said it better.

tiagopms:
I’m trying to read messages from a keyboard connected to the upload port of the Arduino (the port used to connect it to the pc), but I’m having no success so far. I’ve been trying to read it with the Serial class:

Notwithstanding that the keyboard does not send ASCII serial codes, the point is - you cannot physically connect a keyboard to the USB slave connector of an Arduino. Surely there is a hint there?