External Usb Keyboard For Laptop
This Instructable will provide a step by step procedure for building a USB laptop keyboard controller. I created this guide and video to hopefully make it easier for people to re-purpose an old laptop. A typical laptop keyboard relies on the motherboard for the scanning circuitry. I use a Teensy microcontroller mounted on a connector board to take over this function. Teensies are often used by the mechanical keyboard enthusiasts at and and the software is the most popular controller code. The TMK code is a bit of an overkill if you just want a simple USB keyboard but it will certainly provide all the features you could ever need. If you would rather write your own keyboard software using Arduino, the functions give you total USB control.
Add to cart Thermaltake® Tt eSPORTS® KBCMCPLBDUS01 Commander USB Wired Optical Gaming Gear Keyboard and Mouse Combo, Black.
Whatever software you decide to use, it will require a key matrix that maps out how your keyboard is wired. One approach, (that I never want to do again) is to exhaustively check every connector pin combination with an ohm meter while holding down each key. I did this when I into a.
An from alpinedelta disassembles the keyboard in order for the connections to each switch to be visually traced back to the connector. Instead of taking the keyboard apart or using an ohm meter, this Instructable will load the Teensy with an automated continuity tester. The Teensy will report over USB, the two pin numbers that are connected when you press a key. After every key has been pressed, the results can be transferred to a row-column matrix and used by the TMK keyboard controller software or a home-brew Teensyduino routine.I will include download buttons for the relevant files in the Instructable but you can also go to my to view and download all files. Laptop keyboards use a flexible printed circuit (FPC) that connects all the key switches in an array of rows and columns. The two bins of laptop keyboards shown above are from, a local recycling store.
About 75% of the keyboards have FPC cables that end with exposed metal traces on one side and a plastic backing on the other side. The plastic backing plus the FPC material measure about 0.33 mm thick. A typical keyboard without a number pad has 24 or 25 signal traces with a 1 mm pitch. If there is a number pad, then it’s common to have 26 traces with a 1 mm pitch. A few of the keyboards at Re-PC had 30 to 34 traces and some had a 0.8mm pitch.
Connectors for 24 to 34 pin keyboard cables are readily available from companies like Aliexpress or Digikey. The number of signal traces and the pitch are the parameters you will need when ordering. There were some old keyboards in the bins with rigid printed circuit board connectors and some other keyboards with specialized connectors soldered to the end of the FPC cable.
These keyboards will not be the focus of this Instructable. Some FPC cables need to be modified to fit in a generic connector. Locking nubs on the side of the cable are easy to remove with wire cutters. If the FPC traces don't line up with the connector pins, use an X-ACTO knife to trim along the side of the cable. The Dell Latitude D630 keyboard needed the most modifications. It had a solder-less connector on the end of the FPC cable that was easily removed.
Then I pulled off the extra thick plastic backing that was glued on the end of the cable and cut a notch on the side to align the contacts. To bring the thickness back to normal, I glued 2 pieces of paper to the end of the cable.
I designed a circuit board using Eagle for the Teensy LC that routes its 26 I/O pins to 26 surface mount pads for an FPC connector with a 1mm pitch or a 0.8mm pitch. A 24, 25, or 26 pin FPC connector can be soldered to this board based on your needs.
I avoided using the 27th Teensy LC output because it’s connected to an LED and 27 pin FPC connectors are rare.After soldering the FPC connector to the board, I soldered 4 header posts to the board to support the corners of the Teensy and then I soldered the Teensy to the header posts. The last step was to connect the rest of the Teensy I/O signals to the board with 30 gauge wire.
I used wire instead of header posts to make it easy to cut the Teensy off the board, if necessary. The Teensy pads that must be connected to the board are marked with a small line. Don't forget to put a wire on I/O's 24, 25, and 26. You will need header pins, wire, solder, flux, and a USB cable for this project in addition to the main components given below:.
The Teensy LC is $15.53 or the Teensy 3.2 is $23.49 from. You can also order direct from. The FPC connectors from are about $5 for a lot of 5.
An example search on their website would be “laptop keyboard connector 1.0 spacing 24 pin”. Digikey is another source and you can specify whether the connector contacts are on the bottom or top. They also offer right angle or vertical orientation for the cable insertion. Here are examples for 3 different Molex 30 pin 1mm pitch connectors:,. The and files can be downloaded below or from my repo. The KeyboardScannerLT board file has pads for a 2 bit level translator in case you want your Teensy LC to talk to a 5 volt touchpad (see schematic above).
If you don't want the level translator, order the other board or just leave these pads empty. Fabrication of the circuit board costs $18 from OSH Park for a lot of 3 purple boards, or $14 from DirtyPCBs for their 'protopack' lot of about 10 red boards, or $7 from JLCPCB for 10 green boards, all shown above. Fabricates the boards in the United States and my order took 12 days to arrive in Tacoma, Washington. Are fabricated in China and it took 28 days for the boards to be delivered. Is also in China and they took 18 days to ship the boards. If you don’t need to make any modifications, then you can send the Eagle file directly to OSH Park or DirtyPCBs.
To fabricate with JLCPCB, I used to upload the KeyboardScannerLT file and convert it to a that you can use to purchase boards from JLCPCB (see next step for details). DirtyPCBs and JLCPCB offer HASL for the surface finish which is cheaper than the ENIG finish used by OSH Park. The different PCB surface finishes are explained in this post. Check out the next step for information on a Group-Buy that brings the cost of the board down even more.Attachments. The first group buy from DirtyPCBs and the second group buy from JLCPCB have sold out. I just received 10 more boards from DirtyPCBs so if you want a board and live in the United States, send me an email at. The cost for 1 board is $2.00 with U.S.
For those outside the US, you should order directly from JLCPCB. I have uploaded and converted the Eagle board file to EasyEDA and made it a to make it easier for you. Click on the 'Register' button so you can create an account.
Once you've registered and activated your account, go back to my public project and select 'open in editor' and click on the G in a box that stands for generate fabrication file (Gerber). It will ask if you want to run DRC and you should click 'No, generate gerber'. There are DRC errors but they are not 'real' and don't impact the fabrication process. The next window gives the quantity, thickness, color, finish, and weight that I leave at the default settings. Click the box 'generate gerber' then after it downloads the zip file, get back to the same window and click the box 'order at JLCPCB'.
You'll need to allow pop ups so you can see their order form. You can see all the settings and click 'save to cart'. From this point on it's just like ordering anything from the internet.One last requirement: Try really really hard to actually build a keyboard controller with the board and send in a picture of your finished project to the 'I made it' link at the end of this Instructable. If you have any problems, let me know and I'll help you out.
Follow the for installing Arduino and Teensyduino on your computer. Download the MatrixDecoder Arduino code. Use file for a Teensy LC or for a Teensy 3.2.
Laptop With External Keyboard
Load the MatrixDecoder code into the Arduino integrated development environment (IDE). Connect a USB cable from the Teensy to the computer. Your computer should automatically load the necessary USB drivers.
In the Arduino IDE, under “tools”, select board: Teensy LC or Teensy 3.2/3.1 depending on what you’re using. Also under “tools”, select USB type: Keyboard. If you forget to do this step, you will get an error message that says 'Keyboard was not declared in this scope'. Compile and load the MatrixDecoder code into the Teensy. If it’s your very first time loading the Teensy, you’ll have to push the button on the Teensy to enable the loader. Disconnect the USB cable from the Teensy.Attachments.
Open a text editor on your computer. I like to use Notepad on Windows or Geany on the Pi because they have column editing.Original Method:There are two “key-list” text files you can download, named.
The “key-list” file should have every key that you will push followed by tabs to make the results more readable and easy to copy into a spreadsheet.New Method:Marcel Hillesheim has written a Python program that takes much of the manual labor out of my original process. Has a Python program and two blank key-list files that use the PJRC key codes. If you're comfortable running Python, download his key list text files and the. It will save you a lot of time.Modify as needed:You may need to modify the key list file slightly to match your keyboard’s keys. A non-US keyboard can still use this routine, just make a list of your keys and the Teensy will report pin connections. The GUI key is either the 'windows key' from a PC or the 'clover key' from a Mac. Place the cursor to the right of the very first key in the list as shown above.
This will determine where the Teensy begins to display the pin numbers as you push each key. Inspect your FPC connector to determine the correct orientation for the cable.If your FPC connector has contacts on the bottom like the picture on the left, use your finger nail to gently lift the connector locking bar to the open position.
Slide the FPC cable into the connector with the bare metal contacts pointed down (closest to the board) and the plastic backing strip pointed up. Lock the cable to the connector by gently pushing the bar down. The locking bar mashes the bare metal of the FPC cable down against pins on the bottom of the connector.If your FPC connector has contacts on the top like the picture on the right, use your finger nail to slide the locking bar to the right. Insert the cable into the connector with the bare metal contacts pointed up and the plastic backing strip pointed down. The orientation is opposite from the first picture because when the locking bar is slid to the left, it pushes the cable up against pins on the top of the connector.Connect a USB cable from the Teensy to the computer and wait 20 seconds for the Teensy to be recognized as a USB keyboard. This delay is in the code to make sure your computer is ready to receive numbers from the Teensy. If numbers are reported on the screen before any keys are pressed, these pins are shorted together and must be fixed.
If you have an FPC cable with more than 26 signals, it may use some of the extra traces for grounds, back-lighting, or a track-pad. This may cause the test routine to register two pins as shorted. If this happens, you’ll need to do some code modifications to exclude these pins. The code normally scans all pins starting from pin 1 and ending at the last pin but you can adjust these variables to avoid shorts. Press each key, one by one on the test keyboard as listed on the editor screen. The Teensy will send two pin numbers over USB that were connected when the key was pressed.
The Teensy will then send a down arrow to position the cursor for the next key. After pressing every key on the keyboard and confirming that pin numbers were given for all, save the finished file for analysis. At this point you've created a very thorough keyboard tester.The original key list on the left gives every key and the results are in columns for transfer to a spreadsheet. Marcel's key list on the right uses the PJRC key names to make it easier for his Python program to build the matrix. If a key is listed that is not on your keyboard, use your mouse or arrow keys on your PC to move the cursor to the next key. The Python program jumps over the unused keys so there's no need to edit them out manually. If you are using, it will automatically incorporate the basic 'rules' given below.
Make sure the completed key list file is in the same directory as the Python program when you run it.The following manual procedure will determine the keyboard pins that will be Teensy inputs and outputs. This procedure is based around the Modifier keys; Control, Alt, Shift, GUI, and Fn.
As a general rule, 8 of the keyboard pins will be inputs to the Teensy and the remainder will be outputs. The Modifier keys usually have an output row all to themselves which allows these keys to be held down while other keys are pressed.
This avoids a sneak path which would cause. These “rules” are not always followed (especially by the Fn key) so you may need to do some trial and error as you build the matrix. I have lots of at my Github repo to help you out.Control-Left and Control-Right will have a common pin between them. Example:Cntrl-L 19 20Cntrl-R 20 22The common pin, Pin 20 in this example, will be a Teensy output, and 19 & 22 will be inputs.Similarly Alt-Left and Alt-Right will have a common pin between them, just as Shift-Left and Shift-Right will also have a common pin. Example:Alt-L 7 24Alt-R 7 15Shift-L 21 23Shift-R 23 25The Alt common pin will be a Teensy output, and 15 & 24 will be inputs.The Shift common pin will be a Teensy output, and 21 & 25 will be inputs.The GUI key is usually a single key as in this example;GUI 9 26Search all the other pins in the list to see if 9 or 26 are used on other keys. In this example, pin 9 was not used for any other key which means it will be a Teensy output and 26 will be an input.
Sometimes both pins are used for other keys but one of the pins is used for common keys like letters and numbers and the other pin is used for less-common keys like page-up. In this case the pin used for common keys will be a Teensy input and the other pin will be an output. Note that the GUI key will still work if you swap the pins.The Fn key is also a single key as in this example;Fn 12 18Using the same approach as the GUI key, search all the other pins to see if 12 or 18 are used on other keys. In this example, pin 12 was not used for any other key therefore it will be an output and 18 will be an input. If both pins are used on other keys, follow the same rules as the GUI example. Sometimes both of the Fn pins are used by common keys which means you can pick either pin as an input and the other as an output.The eight input pins for the HP DV9000 example keyboard have been identified as; 15, 18, 19, 21, 22, 24, 25, and 26.
All other pins will be Teensy outputs. Make a keyboard matrix table like the one shown above with the 8 input pins across the top in ascending order and all the other pins as outputs on the side, also in ascending order.The orientation of the keyboard matrix is just my personal preference.
You can swap the rows/columns and inputs/outputs if you want. Swapping pins may be necessary if you have a rare laptop keyboard that has diodes for each switch. With diodes, you need to make sure the cathode (first pin listed) is designated an output from the Teensy and the anode (second pin listed) is designated an input to the Teensy.Sometimes only 7 pins can be identified as inputs because two modifier keys share the same input pin (usually the Shift-R and Control-R). If this happens, you’ll have to make an educated guess for the 8th input.
I've even seen keyboards that had the same two input pins for the Shift, Alt, and Control keys so after determining the GUI and Fn input pins, only 4 inputs were identified. For some keyboards, the input pins are grouped together (i.e., 17 thru 24) which makes it easy to fill in the missing pins.
Other keyboards have no grouping of pins which means you’ll have to begin filling out the matrix with some inputs missing. The remaining input pins will be found when some of the keys can’t be placed in the matrix. To fill the matrix, place each key name at the row/column intersection of the pins as shown in the HP DV9000 keyboard example given above. The modifier keys are in bold to make it easy to see that they have a row all to themselves. This keyboard followed the “rules” exactly.You don't need to fill out the matrix if you're using.
The HP DV9000 results that were output from the Python program can be downloaded below.The 8 FPC input pins and 18 FPC output pins are listed along with the corresponding Teensy I/O numbers.There are separate matrix tables for the Normal keys, Modifier keys, and Media keys. Everything is formatted for easy cut and paste into my homebrew USB keyboard controller routine.
A from 'flabbergast' describes using the development environment to configure TMK for ARM based processors like those used on the Teensy LC and 3.2. A toolchain such as the is used to compile the code for the Teensy LC or 3.2.
You will need to install the ChibiOS development environment per these. The example to create a working TMK build. The keyboard routine is based on TMK and it also has ChibiOS for the Teensy LC and 3.2. There is a for QMK.Jay Thompson has created a that gives all the information for his Teensy 3.2/Lenovo T420 keyboard project. Jay provides his build environment setup and the make instructions so you have an example to modify for your keyboard.The TMK/QMK keyboard software is very powerful with tons of features but it can be confusing, (at least to me). As an alternative, I wrote an Arduino USB keyboard routine using the Teensyduino “Micro-Manager” functions. There's just 1 file to load using the Arduino IDE and it's only about 375 lines with lots of comments.
I'm a hardware guy so expect ugly code but it provides a basic keyboard controller with 6 key rollover that you can modify to suite your needs. The detailed instructions named ' and ' describe the changes you need to make for your matrix. These instructions also detail how to use the results from.Every keyboard listed below has a folder at my repo containing a pin connect list, key matrix table, and a Teensyduino USB keyboard routine giving you lots of examples to follow.
Use the links to my repo to view and download these files. The 1525, 2100, and DV9000 folders also have Marcel's completed key list file and the results from his Python program. Keyboard Part Number D9K01. Keyboard Part Number V-0511BIAS1-US.
Keyboard Part Number 0M6607. Keyboard Part Number DP/N 0DR160. Keyboard Part Number AEKT1TPU011. Keyboard Part Number NSK-H3L01. Keyboard Part number AEAT5U00110. Keyboard Part Number KFRMBA151B. Keyboard Part Number 148754321.
Keyboard part number A-1765-621-A. – Keyboard part number A-1766-425-A. – Keyboard part number 42T3177Olga has modified my code for a Commodore 64 keyboard. The Teensy LC code, key list files and project description are in a. If your keyboard has a non-standard FPC cable like the Lenovo connector shown above, the task becomes more challenging.
If you can't find a mating connector at Aliexpress or any other site, your only alternative is to remove the connector on the laptop motherboard. A common method is to put flux and low melt solder on all the joints, then use a hot air rework station and tweezers as shown in this. You will need to make a board layout that routes the Teensy I/O signals to your keyboard connector. I like to do a preliminary layout on paper first in order to place the parts and route the signals with the fewest via's. It's easy to assign the Teensy I/O pins in software based on whatever pin order makes the layout work best.
It's tempting to make the layout next, but do the schematic first so your layout will have air-wires showing you how to route each trace. I didn't make a schematic for the keyboard scanner board because of the confusing front side LC/back side 3.2 routing. The downside of not having a schematic was the lack of any verification that the layout was electrically correct. I had to triple check everything before sending the file out for fab., and are some of the free layout tools that are available. I've chosen to use Eagle and I pay a monthly subscription of $15 for a commercial license.
If you don't need a commercial license, you can download the freeware version of. Sparkfun has excellent tutorials for Eagle. Also look at the on creating parts in Eagle because you'll need to make a package and symbol for your connector. After you get your layout fabricated, you'll need to change the MatrixDecoder software to work with the new I/O pin-out. A perfect example of a non-standard FPC cable is the 44 pin connector used on the Lenovo Thinkpad T61 laptop.
There are at least three web sites that detail how to make a USB controller for a Lenovo keyboard. An from rampadc uses a connector board with some glue logic and wires to an Arduino. A later from rampadc uses a single board with an MSP430 microcontroller.
From Tome uses a connector board with wires to an Arduino. Mark's web site states that a Digikey connector will work with the keyboard FPC cable. This saved me from having to unsolder the connector from the motherboard.
It was pretty easy to search online and find a schematic for this laptop due to its popularity. Without the schematic or the info from rampadc, I would have been doing a lot of probing with an ohm meter to determine the ground pins and narrow down which pins needed to be scanned for the key matrix. I really like the feel of this keyboard which made it worth the effort to design the Teensy 3.2 circuit board shown above. I modified the MatrixDecoder scanning software to only scan the 8 input pins and 16 output pins from the matrix. You can use this scanner code as a guide if you have a keyboard with lots of grounds and more pins than your Teensy can handle.
The scanning software produced a connection list that was turned into a key matrix table using the same steps described earlier in this Instructable. The Fn switch has its own two pins on the connector that are scanned separately from the key matrix. The Trackpoint on the keyboard needs PS/2 clock and data signals from the Teensy plus a reset signal when power is applied.
The Teensy 3.2 is 5 volt tolerant so it can directly drive these signals. All of the T61 3.2 files are at my or can be downloaded with the buttons below. I wanted to build a standalone T61 Keyboard on a block of wood but the 3.2 circuit board from the previous step needed the connector and Teensy re-positioned so the circuit board would be hidden underneath the keyboard.
I figured while I'm at it, I should change over to the LC and save some money. The Teensy LC has fewer I/O signals and they are not 5 volt tolerant so I needed to make some design changes. I adding a TLV810 to generate a reset for the trackpoint plus a couple BSS138 FETs as level translators for the trackpoint clock and data.
To save an I/O pin, I wired the Fn switch into an empty cell in the matrix so it can be scanned with all the other keys. There was one Teensy I/O pin left to drive the Caps Lock LED. All of the T61 LC files can be downloaded from my or use the download buttons below. Converting a keyboard to USB is the most complicated piece of the laptop to get working. The LCD can be converted to VGA or HDMI using an video converter card. I've got one of these boards driving an HP LCD that I mounted in a picture frame (shown above).
The touchpad PS/2 signals can be converted to USB by the Teensy. I have written that utilizes the Teensyduino USB mouse functions. I merged the touchpad code with the Dell Latitude D630 keyboard code to give you an of a 'USB Composite device'.In addition to standalone keyboards, picture frames, or Raspberry Pi laptops, another use for your old laptop is a portable VGA display with USB keyboard and touchpad. My friend troubleshoots servers at various locations and needs to connect a keyboard, video, and mouse (KVM) to the server rack. Instead of borrowing a display from his customer or leaving one in each server room, he carries a modified laptop that I built. The broken laptop motherboard was replaced with a VGA converter card that drives the LCD.
The keyboard and touchpad have been converted to USB using the methods from this Instructable.This KVM was so popular that I built a second one that also has a Raspberry Pi inside. Check out my that describes the steps to build a basic and a Pi KVM.I hope you find this Instructable useful for re-purposing your old laptop.
Leave a comment below or send me an email at if you have any questions, comments, or corrections.Good LuckFrank Adams Attachments. Yes I created the design pattern for the circuit board and the Teensy 3.2 side of the board will work with a 30 pin FPC keyboard. You can download the design pattern named KeyboardScanner.brd using the link at the bottom of step 6. Many circuit board manufacturers will accept the Eagle board file directly so you won't need to convert to GERBER format. If you install the free Eagle layout software from, you can take measurements and even make modifications or file conversions if necessary. Your Dell 9370 keyboard FPC cable may have nubs on the side that are used to lock the cable in the motherboard connector.
If you're using a generic 30 pin FPC connector, you will need to trim off those nubs. You could use a 34 pin FPC connector and center the 30 pin cable in the middle so you don't need to trim the nubs. This keyboard has a backlight and maybe some other circuitry with grounds so you may need to modify the Matrix Decoder software to exclude these pins otherwise the code will hang because it detects two pins as shorted and it will wait (forever) for the short to go away.
Sorry, I don't know of an easy way to add Bluetooth to this keyboard. Let me know if you have any more questions.
I overlooked the design patter. Got the circuit printed in my area and soldered teensy on it. But ran into a problems.
Like You said, 2 side pins are solid connected //=shorted. But neverthless the pins in the middle do not work as expected imo. I tried to test it - if I push the button on a keyboard, 'del' for instance, I should get another shorted circuit between specific 2 other pins. But when I use ohm meter, there is no shorted circuit among any of the pins on the FPS (not counting 2 pernamently shorted side pins). How do I get the signal of key pressed from a keyboard like this? Can you think of any solution what to do? There is also an extra FPC cabel with 4 pins (might be used only as 2, at least it look like so, see the attached image).
But it's a keyboard with backlit, so I suppose its just for passing the power to lightning. Thanks for reaction, Tomas. Hi Tomas, the code will hang when it finds a short and not proceed to scan any other pins so you’ve got to fix the problem. I’ve had lots of shorts and this is my method to finding (or excluding) them: First make sure you have no shorts without the keyboard connected to the board. I’m assuming you have loaded my MatrixDecoder3p2.ino code into your Teensy 3.2. Open an editor on your PC and hook up the USB cable. After 20 seconds, if your board has any shorts, the connector pin numbers will be reported on the editor screen.
I’ve had solder hairs that I couldn’t see but scrapping between the FPC connector pads with a dental pick, cleared the short. If you have no shorts on the board, make sure the code reports two pin numbers when you touch a wire between two of the Teensy I/O pins. If the shorts only show up when you hook up the keyboard cable, try re-positioning the cable to make sure you have the connector pins aligned in the center of the FPC traces. If the two shorted pins are at the side of the FPC cable (which is what you have), they may be grounds and you will need to exclude at least one of them in the MatrixDecoder3p2.ino code.
An example would be if pin 1 and pin 30 are both grounds. They will be reported as tied together but they are not needed for scanning the key matrix. In this case, set the minpin integer on line 44 to 2 and the maxpin integer on line 43 to 29. This method works if the shorts are at the edges of the FPC cable. If you have grounds throughout the cable like on a Lenovo T61 keyboard, you will need to switch to the MatrixDecoderT61.ino program.
It has a list of pins that are scanned instead of scanning sequentially from min to max. I think you are correct that the small cable is for powering the backlight.
Let me know how things are going and I'll try to help you out. You can send me an email with any test results or pictures. Good Luck Frank.