Mturk Jobs

Mturk Jobs
Mturk Jobs

Tank

Friday, May 17, 2019

How to Connect Arduino UNO to USB Keyboard - The Full Length Story

The actual sit and write is the essence of being a writer. Just as in any other discipline, if you do not invest time, mind and effort in doing it, you are treating it to be just a hobby.



The mind you give to the process of writing comes back to you in a form of the Flow. The process of effortlessly create something valuable with ease and timelessness. It’s well known that whatever habit that you devote yourself to is what you can be finally rewarded for.

That's why I've wanted to make this project to concentrate on the process of writing itself.


Today I’m showing you how I’ve made this new project. Of course, it’s about Arduino and it’s about writing.

For some reason I wanted to connect Arduino to my keyboard.

Because I love writing on the keyboard.

It’s that real physical feeling of switches on my fingertips that makes me feeling creative and alive.

But there’s only a small problem. My favorite keyboard is happened to be a USB keyboard.

Yes that’s the new modern technology is about and it’s something I should be happy with.

 

But the only problem I was having when I wanted to connect my keyboard to Arduino (as a host to my keyboard) I found that the standard use of Arduino with a keyboard is the PS/2 connection.

Actually there is a good well written Arduino library for this purpose.

So how could I connect my USB keyboard to Arduino? I only remembered back then when I was looking for a keyboard for my notebook (which had no PS/2 ports in it) is that I wanted to figure out some way to use a PS/2 keyboard with a USB port but I couldn’t found this.

And that’s why I bought the USB keyboard for the first place.

But this search has helped me a lot these days when I wanted to connect my USB keyboard to Arduino.

 


  I only then remembered that although I couldn’t use a normal PS/2 keyboard with a USB port in a notebook because of the different protocol, but the opposite is doable.

I remembered that I’ve found an instructable that described building a USB to PS/2 converter.

The writer mentioned that he has tried it and it worked.

This means that you can use a modern USB keyboard with your old PCs and laptops using only this converter.

It’s just a physical converter for the connection between the keyboard and the host port(not a voltage or protocol converter). That’s because the USB keyboard can be powered from the old PS/2 port, take the CLOCK signal from it and then send DATA signal to it.

And the writer has tried to make this setup and it worked. Now it was my turn. When I looked for some information to connect a USB to an Arduino board I found that in order to do this I need either an Arduino USB shield or an Arduino board with Microcontroller that have the native USB host physical feature. Neither option were available to me.

So I’ve decided to try the physical USB to PS/2 converter - the writer has tried with his PC - between my USB keyboard and Arduino. You know what? This one also worked.

Using the PS/2 Arduino library we can connect the USB keyboard directly to Arduino boards such as Arduino UNO or Arduino Mini.






I had that female USB connector but I had to first test its pin-out with a voltmeter.

Then I made a cross connection between the USB connector and the PS/2 keyboard of the library.

USB Keyboard PS/2 Port

+5 v Vcc +5 v Vcc

Data- Data

Data+ Clock

GND GND






Components

Arduino UNO 

Female USB port




Connection

USB Port Arduino

+5 v Vcc +5 v Vcc

Data- PIN 2

Data+ PIN 3

GND GND








Software
Download and save the latest Arduino PS/2 library from here.

Open Arduino IDE.

On the sketch menu, select library. Add Zip file.

Point to the Arduino PS/2 library Zip file location and then press Enter.

On the File menu select examples.

From PS2keyboard sub-menu select International.

You find the international.ino sketch loaded into the Arduino IDE.

https://github.com/PaulStoffregen/PS2Keyboard

Edit these two lines of code

#include

const int DataPin = 8 ;

const int IRQpin = 5 ;

In this case, I used

DataPin to be Arduino Pin 2

and

IRQpin to be Arduino Pin 3








Open the Serial Monitor and watch try the keyboard as you wish.




Note:

There will be a different response from some keys on the keyboard.

This is caused by difference of Arduino response to the keyboard than the standard PC.










 




2 comments:

Dave said...

This actually works for you?. because I tried and I'm getting some problems, firstly this line

keyboard.begin(DataPin, IRQpin, PS2Keymap_German);

Doesn't works because I've got this message:

International:20:35: error: 'PS2Keymap_German' was not declared in this scope

keyboard.begin(DataPin, IRQpin, PS2Keymap_German);

^

exit status 1

'PS2Keymap_German' was not declared in this scope

So I decided to eliminate that, and the code compile,
but the problem is that I'm not recibing any data from my keyboard, I try 2 ways, conecting with wires as you explain and I conect my keyboard by the Native Port (Because I'm working on a Arduino Due Board), but neither works, and actually I don't know if it is a problem with the code or the library, or if is a voltage problem.

Some extra that is happen to me, I conect the keyboard but actually the Bloq Num Led is not turned on, and I think this is something that shouldn't happen because it's only Power Alimentation, maybe that is the problem, but I don't how to resolve that.

If you have an idea or some suggestions for me, I will apreaciate.

Regards.

Dave



tc said...

it is working, thanks :)

Tank