Communication using PC keyboard

Hey everyone,

I've been playing with the LCD for a while. Thought that it would a great idea to try to create a game. In the game there should be a car which has to avoid the upcoming obstacles. In order to do that I want to use arrow keys(Up and Down) in my PC keyboard. The problem is that I couldn't find a way to do that properly. I could use the Serial monitor for input, but that would too clumsy because everytime I input a character(arrow up or down) I would have to confirm that by pressing enter. Is there any way to avoid that?

Any help would be appreciated.

There are libraries for connecting the Arduino to a PS2 keyboard (the one with the little round purple plug).

Paul__B:
There are libraries for connecting the Arduino to a PS2 keyboard (the one with the little round purple plug).

Are you talking about this library?

No, because it says "USB".

Paul__B:
No, because it says "USB".

The thing is that I don't have a PS2 keyboard, I have a laptop( forgot to mention that). How I could use my laptop keyboard or do I have to buy PS2 keyboard?

Well, you don't necessarily buy PS2 keyboards new, you get them for a dollar or two at garage sales or "op-shops", or at the recycle depot. Likely for free when you point out they are "obsolete". :grinning: The purple plug is the give-away.

I don't quite follow what you are planning to do with this laptop keyboard (which presumably is USB)? Is this a dead laptop you are recycling?

The point is that to interface a USB "slave" device to an Arduino, you need a USB "host shield" and it gets absurdly complex.

Paul__B:
Well, you don't necessarily buy PS2 keyboards new, you get them for a dollar or two at garage sales or "op-shops", or at the recycle depot. Likely for free when you point out they are "obsolete". :grinning: The purple plug is the give-away.

I don't quite follow what you are planning to do with this laptop keyboard (which presumably is USB)? Is this a dead laptop you are recycling?

The point is that to interface a USB "slave" device to an Arduino, you need a USB "host shield" and it gets absurdly complex.

My laptop is fine and I'm not going to strip it only for the keyboard :smiley:

I'm usually using this laptop to upload the codes to arduino and it's always connected via an USB cable.

I thought that I can use the keyboard (which is in my laptop) to send commands to arduino while the program is running,(I don't want to use serial monitor input line, because after every command I would have to confirm it by pressing enter) but if you say that it is too complex then, I guess, I'll just order a keypad or some custom buttons from ebay and connect them to my breadboard

Try PuTTY, then you don't need to press Enter.

(I just tested it: not sure if it's a setting I may have chosen before, but right now it sends a character as soon as you type it.)

neiklot:
Try PuTTY, then you don't need to press Enter.

Actually, yes, that will work just fine. PuTTY sends keystroke by keystroke so you can direct them to the Arduino USB serial port.

neiklot:
Try PuTTY, then you don't need to press Enter.

(I just tested it: not sure if it's a setting I may have chosen before, but right now it sends a character as soon as you type it.)

Tried it out, didn't really worked out, maybe I messed up something.

Downloaded the latest version of PuTTy, installed it, turned it on, put in the settings(COM(number) and 9600), opened it. There was written "Testing keyboard" or something like that. I thought everything is fine, so turned on the arduino IDE and tried to upload the code (which worked fine earlier). Got an error message that it timedout.

Watched few videos on how to connect PuTTy to arduino, acording to them everything was in the way it should be.

Have no idea what could go wrong.

I used the same COM at Arduino and at PuTTy.

You can't have them both open on the same port at the same time.

So if you had PuTTY open and then tried to upload new code from the ide, the ide can't connect.

So close PuTTY, upload the code, make sure serial monitor's not open, then open PuTTY.

The fact that you got a message in PuTTY shows it was connected, and was receiving whatever the pre-existing sketch was sending.

Thank you guys, now everything is working perfectly :slight_smile: