Use keyboard to send commands to arduino thru PC

I am ultimately trying to create a set up whereby I can connect up the arduino either via usb or ethernet to a PC and have the user/client use arrow keys or other select buttons to send command signals to the arduino, which will operate servo motors or whatever.

Basically,
How can I send keyboard command signals from a PC to the arduino board?
How can I interpret those command signals in code for the software on board the arduino as one type of input or another?

I’m pretty sure that if I get those two things nailed down I will be able to do the rest.

Any help setting it up and or advice as to what might be the easiest route to accomplishing that goal would be appreciated.

Thanks in advance

Hi Mate,

I am using VB.net, there is very good free version called (Visual Basic 2010 Express).

Just start a new windows form project and add a serial connection object.

Then a few lines of code opens the serial port and sends commands via the usb serial interface.

Hope this helps.

Just a few lines of code below to show how easy it is with VB.net You have to add the serialport object from the tools panel to the form first.

When you receive the code on the Arduino, it will come through as numeric char values

SerialPort1.Open()
SerialPort1.Write(ScreenName & Message)

When you receive the code on the Arduino, it will come through as numeric char values, so you want to process what has been received have to read it as follows

while (Serial.available() > 0){
        SerialInput.concat(char(Serial.read()));
 }

Notice the char() command. This casts the numeric character values into alphanumeric characters.

Ofcourse if you going to simply pump it direct to an LCD screen you can just send what you received with lcd.write().

Thanks a bunch for the info, I'll give it a go soon as I have some time.

Ok so I installed visual basic express 2010 and created a windows form application project and add a serialport component to it, but its just a blank form.

I am a beginner with this stuff and could use some more direction.

I am also confused by what the entire arduino code would be that i would have.

I am a beginner with this stuff and could use some more direction.

Do you have keyboard events registered? You'll need some to know when a key is pressed or released.

When the event fires, you can determine which key was pressed, and send that key (or something else) to the serial port.

As for the Arduino, the code there depends on what you expect the Arduino to do in response to the incoming serial data.

How would I go about registering a select few keyboard events? just the arrow keys.

thats the idea though.

You don't register events for specific keys. You register callbacks that happen when specific events occur. When the keyPressed or keyReleased events occur, the specific key being pressed or released is passed to the function.

You decide, based on the key that was pressed, what to do - write it to serial, ignore it, do a happy dance, etc.

thanks that is helpful information to know. any way you could make a small code snippet that does just that?

i understand how the process works a lot better than i can write it.

      Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If(e.KeyCode == Keys.Left)
                  'Left arrow key was pressed
            Else if(e.KeyCode == Keys.Right)
                  'Right arrow key was pressed
            End If
      End Sub

      Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
            If(e.KeyCode == Keys.Down)
                  ' Down arrow was released
            End If
      End Sub

I presume you know how to set up a serial port connection.

so this is what i have so far.

i can successfully use the arduino code and the integrated serial monitor to send characters that display on an LCD. COM4 happens to be the serial/usb interface for the arduino board.

I presume you know how to set up a serial port connection.

So, this was not a valid assumption?

This post may help on the serial side. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1293049236

  • Note: this is not my code and I have not tested the code in this post. I just ran by it a few days back so I figured I'd pass it along. Good Luck.

nope, not a valid assumption. like i said, i am a beginner haha.

ill take a look at that code too, thanks marklar