Go Down

Topic: Comunication between Arduino and keyboard (Read 1 time) previous topic - next topic

ste4os

Hi guys!
Can I send signal with my keyboard to Arduino with specific function? Even in C language if it exist!

s.

PaulS

You need some application running on the PC that collects the keystrokes and sends them to the serial port. The Arduino then reads the serial port to get the key data.

The PC application can be written in a variety of languages, including C, C++, C#, PHP, Python, Ruby, etc.

ste4os


You need some application running on the PC that collects the keystrokes and sends them to the serial port. The Arduino then reads the serial port to get the key data.

The PC application can be written in a variety of languages, including C, C++, C#, PHP, Python, Ruby, etc.


Ok, i suppose there is a C library for this work! Right? What's its name?

sjfaustino

#3
Apr 02, 2011, 10:05 pm Last Edit: Apr 02, 2011, 10:07 pm by sjfaustino Reason: 1
If you want to connect a keyboard directly to the Arduino, your best bet is a PS2 keyboard.
See http://www.practicalarduino.com/projects/ps2-keyboard-or-mouse or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html for explanation and code.

If you want to have the Arduino connected to your computer and control the arduino with the computer's keyboard, why not use the IDE's serial monitor? It will send anything you type to the arduino and all you need is:

Code: [Select]

void setup()
{
Serial.begin(9600); // Starts serial data
}

void loop()
{
  if (Serial.available() > 0)
  {
    char inByte = Serial.read(); // waits untill somthing is typed
    Serial.print(" I got: ");
    Serial.println(inByte); // shows what was stored
  }
}

ste4os

Thanks :)
I tried to write a little sketch:
Code: [Select]
void setup(){
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop(){
  if(Serial.available() > 0){
    int inByte = Serial.read();
    if(inByte == 1)
      digitalWrite(13, HIGH);
    if(inByte == 0)
      digitalWrite(13, LOW);
  }
}

If my input on serial monitor is 1, the led turn on else if my input is 0, the led turn off!
But it doesn''t work. Why?

Go Up