Step 9: The Arduino Code

The Arduino software clocks data out of the keyboard, translates the keyboard scan codes to key codes, and handles presses of the shift and caps lock keys.

First off, download and install the Arduino development environment from here.  Follow the directions on the site, but be sure to install the appropriate FTDI driver from the drivers directory in the Arduino installation.

Next, you’ll need an additional Arduino library for PS/2.  Download the file “ps2.zip” from this page.  To install, unzip the download to a folder and move that folder to be a subdirectory of the “hardware/libraries” directory under your Arduino installation.  On OSX, you can go to Arduino.app and “Show Package Contents” first.

Once Arduino and the ps2 library are installed, download the source code from here.  Open the Arduino application, create a new project, and paste the source code into it.  Save, and then go to Sketch->Verify/Compile to make sure that it builds.  If it doesn’t, make sure the library is installed correctly.

On a side note, I actually wrote absolutely no code for this project.  I started out trying to use the PS2KeyboardExt2 library, but that library is based on interrupts and while it can run on an Arduino that is also speaking serial at 9600 bps, once I cranked the serial up to 19200 bps, the interrupts stopped working in a stable way.  So I yanked all of the nice code out of PS2KeyboardExt2, including the key definitions and the nice handling of shifts and caps lock and reworked it into a program that doesn’t use interrupts and makes use of a different, much simpler PS/2 library.  This makes it capable of handling 19200 bps serial in a reliable manner.

Now, to program the Arduino!

Disconnect the lead going to Pin 1 on the Arduino.  Then, connect the Arduino to your computer via USB cable.  You may need to restart the Arduino application so that it detects the new USB serial device correctly.  Load the saved sketch with the source, and then hit the Upload button to program the Arduino.

Once the program is uploaded, plug the keyboard into the PS/2 connector.  You should see the lights flash.  You can open up the Serial Monitor in the Arduino application and try typing some letters on the keyboard.  You should see those letters show up in the Serial Monitor.  Try turning the Caps Lock on and off, the light on the keyboard should go on and off and the characters should come out correctly capitalized.

wow i could have bought a neat and tidy bluetooth keyboard and linked that to my iphone than waste that much time and money and ruin the aesthetic appeal of my iphone
But that's no fun!
Having issues with installing iPhone 2.0 Toolchain, Cydia keeps telling me it can't install because there is dependencies and conflicts that can't be identified xD<br>Anybody knows a way around?
This is great! I modified the code am currently using through USB to transfer text to putty through the COM port. Nice Instructable!
you should have a scematic and make a Arduino Shield
omg win<br />
&nbsp;lol, Im sorry but i really must insist. WOW, I've had some experience with jailbreaking but does that look complicated and a hlaf!
Hi,<br /> When I type &quot;<strong>gcc -static-libgcc -o TouchClient TouchClient.c -lvncclient</strong>&quot;<br /> I get:<br /> <br /> ld: library not found for -lSystem<br /> collect2: ld returned 1 exit status<br /> <br /> What do I do?<br />
did any1 figure out backspace or how to hit send from the keyboard?<br />
I would like to make my own dock using this, the only information I cannot find is exactly what pins I have to put wires into to charge it and how much voltage and amps should be on those pins. by any chance would you know?<br />
Is it possible to do this with a regular either graphic or basicLCD?&nbsp; if so, where can I get the codes?
Absolutely.&nbsp; So you'll need a LCD with an existing Arduinolibrary.&nbsp; <a href="http://www.adafruit.com/index.php?main_page=product_info&amp;products_id=188">Something like this</a> , perhaps.&nbsp; Follow the instructions as above, except don't botherwith the iPhone breakout or the iPhone code.&nbsp; The library andinstructions for using it on the Arduino are <a href="http://www.arduino.cc/playground/Code/GLCDks0108">here</a> .<br /><br />Simply modify the Arduino code I posted and replace the Serial.write()command with a command that prints the character to the LCD.<br /><br />That's actually an awesome idea!&nbsp; With a little storage, you couldmake an Arduino-powered word processor...&nbsp; <br /><br />Thanks for your comment!<br />
Or better yet, a serial-enabled LCD module like <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=462">this</a>.&nbsp; Wouldn't have to change the code at all to print characters!<br /><br />Would have to handle backspace and some kind of buffer yourself, butthat should be easy.<br />
ya. that is what I was planning on doing. Making a word processor.&nbsp; Thanks for responding.&nbsp; Is it harder to do it with a graphic LCD, or even a graphic touch screen LCD so that you can use&nbsp;the screen as a cursor?
<p>Will this work with the ipod touch too? if so, do you know how much all of this costs? (besides the ipod)&nbsp;&nbsp; thanks :&nbsp;)</p>
Should work with a jailbroken iPod Touch just fine.<br /> <br /> As for the cost,&nbsp; it's about $15 for the breakout board, $2 for the PS/2 connector, $20-$30 for the Arduino (a Seeduino clone would be enough).&nbsp; The resistor and wire are cheap.&nbsp; <br /> <br /> Of course, you can always find another use for the Arduino when you're not using it to type ;)<br /> <br /> - awgh<br />

About This Instructable




More by awgh:How To Connect a PS/2 Keyboard to the iPhone 
Add instructable to: