7

My idea seems easy:

I connect a button with arduino, then write some code and upload it to arduino. Then I open the notepad(or any other editor) on my computer. When I press the button, there will be a character "A" displayed in the notepad.

I have tried with my Arduino uno, and use Serial.write/print function to send an A to serial port 9600, but it seems the character A only shows in the serial monitor GUI.

My question is:

  1. Is "Arduino uno" is OK to implement this?
  2. If not, what other board should I use?
  3. Is Serial.write/print the correct function?
  4. Or shall I use the Keyboard.??? function?
  5. Do I have to write an application which runs on the computer and listens the serial port, and emit a real key event? (that's sad)

5 Answers 5

9

The Uno is not the best board for this. You may be able to get somewhere with the Virtual USB project but there are a couple of boards that are better suited for this.

Those are the Arduino Leonardo, Micro, and Due. In those, you can use the Keyboard Library just like you are using the Serial library now. This page has an example very similar to your project:

void setup() {
  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
}
4

There is a micro designed more specifically for keyboard emulation, I haven't done any experimenting with it (yet), but it's very popular in the flight simulator world where these micro's are rigged up with buttons and switches and rotary encoders to simulate a cockpit. These inputs are converted to keyboard inputs (as far as I can see).

There are some general projects here: https://www.pjrc.com/teensy/projects.html

Some more keyboard specific stuff: https://www.pjrc.com/teensy/usb_keyboard.html

More info on the teensy in the arduino environment: https://www.pjrc.com/teensy/teensyduino.html

More specifically about what you're looking for, this could be quite useful: https://www.pjrc.com/teensy/td_keyboard.html

I'm not steering you away from Arduino, it's just something else to look into

1
  • 1
    Go for Teensy indeed. They're small, cheap and can be used just like 'official' Arduinos. You can keep using Arduino's editor, so aside from the board nothing will change. You do not only get keyboard emulation, you can also pretend you're a mouse, a MIDI interface and many other things.
    – Tom
    Jun 16, 2014 at 9:12
1

Your example describes collecting text - does that meet your goal or do you need to generate any kind of key-event? If you don't need to generate system events, any terminal emulator (not just the Arduino IDE) should be able listen to that same port and to log whatever it receives to a file.

1
  • I need it to be some kind of key-events. My final goal is to make a custom keyboard by arduino
    – Freewind
    Jun 15, 2014 at 14:37
0

Check this video, Arduino UNO as a USB keyboard (HID device) [Anything Arduino] (ep 6), as I think this is what you are looking for.

From the youtube video you can get links to the library site and schematics.

You do need to build a small interface to connect your Arduino to a PC. I got it for Uno and Micro, but other Arduinos with latest firmware would be OK.

2
  • 1
    When you link to an outside source it helps if you summarize what the link (the video in this case) is about or how it helps to solve the problem. This is especially useful if the link "rots." We're trying to build a durable resource here, try to think for the long term in your answers.
    – dlu
    Jan 4, 2016 at 15:08
  • If you could edit your answer to provide the links in your answer that would be a good idea, as well as a copy of the schematics, quoting the source, if copyright allows that, in case the video is deleted. Jan 6, 2016 at 15:14
-1

I think you also need to install processing.

See this link

It enables you to program the computer-side of the application.

2
  • Do you mean I have to use some programming languages to write a program running on the computer-side? Do I have to use the "processing" language? I found it's interesting, but I'm sure why it's special with Arduino?
    – Freewind
    Jun 15, 2014 at 14:42
  • 3
    Processing, while a valuable addition to your arsenal when using Arduino, is not needed for your purposes. Instead, it will make things overly complex, if not impossible.
    – Tom
    Jun 16, 2014 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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