Saturday, April 20, 2013

Serial to USB Keyboard

So I finally gave in and got a raspi. I also got a USB Wifi dongle, SD card, and already had a power supply and mouse. However, I did not get a USB keyboard for two reasons. One, I already have a keyboard at home (I am currently in my dorm room). Second, I am in a dorm room! Real estate is at a premium and there is no way I would have room for one on my desk.

So, how do I enter data into my raspi. Well, I've done a single button keyboard before using V-USB, but it would be obnoxious to use only a few buttons for a whole keyboard. Wait! I already have an entire keyboard on my laptop. If only I could use it with my raspi. That is where this project comes in.

In this project I used a python script to detect key press on the laptop and then send them via serial to an ATTINY2313 with V-USB that converts the serial data into key presses on the raspi.

Hardware:
 The hardware is pretty simple. It is just an ATTINY2313 running at 20MHz with connections to a USB to serial converter and hardware to interface to USB.

Software:

To detect key presses on my laptop I have a python script running. It uses the msvcrt library, which only works in windows. It also cannot detect the CTRL, ALT, SHIFT, or CAPS keys by themselves. Though if you press SHIFT and a letter it will read it as a capital letter. The same goes for CTRL, though some keys overlap with other buttons (i.e. CTRL-H returns 8 which is that same as Backspace). This data is then sent to the microcontroller with serial. The ATTINY then receives this data and sends the corresponding character using V-USB.

Download

Demo: