How to Make a USB Laptop Keyboard Controller

Introduction: How to Make a USB Laptop Keyboard Controller

About: I am a retired Boeing engineer that enjoys experimenting with Pi & Teensy projects.

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 Geekhack and Deskthority and the TMK 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 Teensyduino functions give you total USB control. 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 converted a Sony Vaio into a Raspberry Pi laptop. An Instructable 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 GitHub repository to view and download all files.

Step 1: Keyboard Cable Specifications

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 Re-PC, 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 typically measures about 0.30 mm to 0.34mm 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. It can be difficult to measure the pitch between traces so another method is to measure the width of the entire FPC cable and use this formula:

Pitch = Total width / (N + 1) where N is the number of pins

A few of the keyboards at Re-PC had 30 to 34 traces and some had a 0.8mm or 0.5mm 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.

***********Update************

I have added support for keyboards with up to 36 pins, 0.5mm pitch contacts, and dual FPC cables. See step 6 for details.

Step 2: Modify Your FPC Cable As Needed

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 scissors. 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.

Step 3: Teensy LC FPC Connector Assembly - Surface Mount or Thru-Hole

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. I created a second circuit board for keyboards that have a 0.5mm pitch. For those that don't want to solder surface mount connectors, I created the board shown on the right for thru-hole FPC connectors. A 24, 25, or 26 pin FPC connector can be soldered to these boards 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 reroute I/O pins or cut the Teensy off the board. If you buy a Teensy LC with pins, it will not have pins on I/O's 24, 25, and 26 so you'll need to add them.

Step 4: Teensy 3.2 or 4.0 FPC Connector Assembly

I designed the back side of the board for a Teensy 3.2 with 34 I/O signals and an FPC connector with a 1 mm or 0.8 mm pitch. A different 3.2 circuit board is available if you have a 0.5mm pitch.

Whichever side of the board you mount the Teensy on, you must solder the FPC connector on the same side.

*****Update for the Teensy 4.0********

PJRC is now selling the Teensy 4.0 so I created a new circuit board for it that routes 34 I/O signals to pads for an FPC connector with a 1 mm or 0.8 mm pitch (see pictures above).

If your keyboard uses FPC pin 34, you must unsolder the LED near I/O 13 on the Teensy 3.2 or 4.0. If you don't unsolder the LED, it will interfere with the keyboard scan.

Solder the FPC connector to the 3.2/4.0 side of the board and then proceed to the next step.

Step 5: Teensy 3.2 and 4.0 Surface Mount Pads

The Teensy 3.2 and 4.0 use surface mount pads for I/O signals 24 thru 33 so it’s a little more work to solder them to the board. Solder “flying leads” to the surface mount pads on the Teensy 3.2 or 4.0 and then pass each wire thru the corresponding pad on the board for soldering. Finish the assembly by soldering wires to the remaining I/O signals.

For those that dislike flying leads, I redesigned the Teensy 3.2 board and Teensy 4.0 boards so that header pins can be used for the surface mount pads. The pictures above show how to modify a 2 x 7 right angle header. Note that you can still use flying leads with these boards.

For the Teensy 3.2, cut the header down to 2 x 6, then partially pull and cut the two pins on one end so they are straight as shown above. These 2 pins will help align the header. A small perf board with holes can also be used to hold the header in alignment while soldering the surface mount pads. You will need a long soldering iron tip in order to reach the pads.

For the Teensy 4.0, pull out the 4 right angle leads at the ends and replace them with 4 straight pins that will hold the header in the correct position. The remaining right angle header pins are a touch too long so I recommend they be trimmed in order to not overhang the surface mount pads of the Teensy 4.0.

Step 6: Order the Board and Components

You will need header pins, wire, solder, flux, and a USB cable for this project in addition to the 3 main components given below:

  1. The Teensy LC is $15.48, the Teensy 3.2 is $23.63, the Teensy 4.0 is $23.78 and the Teensy ++2.0 is $27.83 from PJRC.
  2. The surface mount FPC connectors from AliExpress 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: CONN FPC BOTTOM 30POS 1.00MM R/A, CONN FPC TOP 30POS 1.00MM R/A, and CONN FPC VERT 30POS 1.00MM SMD. You should check the thickness at the end of your FPC cable with a micrometer. A common thickness is 0.30mm but sometimes the thickness is less so measure and order the appropriate connector.
  3. The Keyboard_Scanner_LT2.brd file can be downloaded below or from my repo. This board has pads for 1mm or 0.8mm pitch FPC connectors as well as pads for a 2 bit level translator in case you want your Teensy LC to talk to a 5 volt PS/2 touchpad (see schematic above). If you don't want the level translator, leave these pads empty. The hole spacing for the backside I/O signals has been adjusted so a right angle header can be used instead of flying leads. Fabrication of the circuit board costs $18 from OSH Park for a lot of 3 boards, or $8 from JLCPCB for 5 boards (if you choose economy shipping). OSH Park fabricates the boards in the United States and my order took 12 days to arrive in Tacoma, Washington. JLCPCB is in China and they took 18 days to ship the boards. JLCPCB offers HASL for the surface finish which is cheaper but not as good as the ENIG finish used by OSH Park. I have had no trouble with the HASL finish. The different PCB surface finishes are explained in this Optimum Design Associates post. If you don’t need to make any modifications, then you can send the Eagle file directly to OSH Park. To fabricate with JLCPCB, download the gerber zip file Keyboard_Scanner_LT2_2020-06-09 from my repo. Go to JLCPCB.com and select "quote now". Then select "add your gerber file" and load the zip file. I usually leave the next menu at the default settings except I adjust the quantity as needed.
    **************Update for 0.5mm pitch FPC cables & Dual FPC cables*************
    • I have created a board file called Keyboard_Scanner_LT_0p5.brd for keyboards with 0.5mm pitch FPC connectors (see picture above). This board will work with a Teensy LC on one side or a Teensy 3.2 on the other side. The Eagle file can be downloaded below or from my repo. To order this board from JLCPCB, use the gerber zip file Keyboard_Scanner_LT_0p5_2020-02-26 from my repo.
    • If your keyboard has 2 separate FPC cables, you may be able to install them side by side into a single FPC connector. If that doesn't work, I created a board file called Keyboard_Scanner_Dual.brd (see picture above). This board will work with a Teensy LC on one side or a Teensy 3.2 on the other side.The Teensy LC (front) side of this board is for keyboards like the Panasonic Toughbook CF-48 which has 2 separate 1mm pitch FPC cables that are on top of each other (not side by side). The Teensy 3.2 (back) side of this board has 1mm and 0.8mm pads for FPC connectors placed side by side. The Eagle file can be downloaded below or from my repo. To order this board from JLCPCB, use the gerber zip file Keyboard_Scanner_Dual_2020-02-26 from my repo.
    • ***Update for Teensy 4.0*** I have created an Eagle board file called Keyboard_Scanner_4p0.brd that will connect a Teensy 4.0 to a 1mm or 0.8mm pitch FPC connector. The Eagle file can be downloaded below or from my repo. The Teensy 4.0 has many new features and is much faster than previous microcontrollers. The Teensy 4.0 is not 5 volt tolerant but there are pads for a 2 bit level translator on the Teensy LC side of the board if you want to control a 5 volt PS/2 touchpad. To order this board from JLCPCB, use the gerber zip file Keyboard_Scanner_4p0_2020-02-26 from my repo.
    • ***Update for Thru Hole FPC Connector*** I have created an Eagle board file called Keyboard_Scanner_LC_thruhole.brd that will connect a Teensy LC to a thru hole 1mm pitch FPC connector with up to 26 pins. The Eagle file can be downloaded below or from my repo. To order this board from JLCPCB, use the gerber zip file Keyboard_Scanner_LC_thruhole_2020-04-28 from my repo. The connector hole pattern on the board is designed for these AliExpress and Digikey connectors.
    • ***Update for Teensy ++2.0*** I have created an Eagle board file called Keyboard_Scanner_2pp.brd that will connect a Teensy ++2.0 to an FPC connector with either a 1mm, 0.8mm, or 0.5mm pitch and up to 36 pins. You must un-solder the LED located on the Teensy so that it does not interfere with the keyboard software. The Eagle file can be downloaded below or from my repo. To order this board from JLCPCB, use the gerber zip file Keyboard_Scanner_2pp_2020-06-09.zip from my repo.

    Step 7: PCB Group-Buy

    I purchased the JLCPCB boards shown above to make it easier for others to build this project. These boards are - Keyboard_Scanner_4p0, Keyboard_Scanner_LT2, Keyboard_Scanner_2pp, and Keyboard_Scanner_LC_thruhole. If you want any of these boards and live in the United States, send me an email at thedalles77@gmail.com. The cost for the Keyboard_Scanner_2pp board is $3.00 and all the rest are $2.00 with U.S. shipping. For those outside the US, or if you need several boards, you should order directly from JLCPCB using the zip file at my repo.

    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. If you want your completed keyboard code to be available for others to use, send it to me and I'll add it to my GitHub repo.

    Step 8: Load the Continuity Tester Into the Teensy

    • Follow the PJRC link for installing Arduino and Teensyduino on your computer.
    • Download the Matrix_Decoder Arduino code. Use file Matrix_Decoder_LC.ino for a Teensy LC, Matrix_Decoder_3p2.ino for a Teensy 3.2, Matrix_Decoder_4p0.ino for a Teensy 4.0 or Matrix_Decoder_2pp.ino for a Teensy ++2.0.
    • Load the Matrix_Decoder 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, 3.2, 4.0, or ++2.0 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 Matrix_Decoder 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.
    • If you are using a Teensy ++2.0, you must unsolder the LED on the Teensy so it does not interfere with the scan.

    Step 9: Load the Key-List File in the Editor

    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 Keyboard_without_number_pad and Keyboard_with_number_pad. 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. I forked Marcel's GitHub repo so I could add support for the Teensy 3.2 and 4.0. The forked repo has 3 different Python programs depending on which Teensy you are using. It also has two blank key-list files that use the PJRC key codes. If you're comfortable running Python, download the key list text file (with or without number pad) and the appropriate matrixgenerator Python program. 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.

    French computers require the shift key to be pushed in order to display the numbers 0 thru 9. I have made French matrix decoder code for the Teensy LC, 3.2, and 4.0 that takes care of the shift key so that numbers are displayed instead of @ " ' ( - _ etc. You can find this code at my Github repo.

    Step 10: Connect the FPC Cable

    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. It may be a solder short on the connector which you can check by retrying without the keyboard connected. If it is still shorted without the keyboard, use flux and solder wick on the shorted connector pads. If the short goes away when the keyboard is removed, these pins are most likely ground pins that are tied together in the keyboard and must be excluded from the routine. Adjust the max_pin or min_pin values in the code to allow the routine to skip over these pins.

    If your keyboard has shorted pins that are in the middle, adjusting max_pin or min_pin will not fix the problem. In that case load the Matrix_Decoder_LC_alternate, Matrix_Decoder_3p2_alternate, or Matrix_Decoder_4p0_alternate routine. These routines allow you to exclude any pins necessary to avoid shorts.

    If you are using a Teensy ++2.0 and you get the numbers 1 and 15 reported on your screen, you forgot to unsolder the LED located on the Teensy.

    Step 11: Test the Keyboard

    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. If you make a mistake, just use your PC keyboard and mouse to erase the error and re-position the cursor. 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.

    Step 12: Determine Input and Output Pins

    If you are using Marcel's Python program, it will automatically determine the input and output pins. 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 ghosting. 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 keyboard examples at my Github repo to help you out.

    Control-Left and Control-Right will have a common pin between them. Example:

    Cntrl-L 19 20

    Cntrl-R 20 22

    The 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 24

    Alt-R 7 15

    Shift-L 21 23

    Shift-R 23 25

    The 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 26

    Search 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 18

    Using 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 revealed when some of the keys can’t be placed in the matrix. Keyboards with dual FPC cables have the input pins on one cable and the output pins on the other cable.

    Step 13: Fill the Matrix With Keys

    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 Marcel's Python program. 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.

    Step 14: Translate FPC Pin Numbers to Teensy I/O Numbers

    Marcel's Python program automatically translates the FPC pins to the Teensy I/O's. If you are using the manual method, you will need to use the Teensy LC, 3.2, or 4.0 tables shown above. The Teensy ++2.0 uses the manual method. Notice that there is an LED on the Teensy that must be removed if you are using that I/O pin.

    Step 15: Load a USB Keyboard Routine Into the Teensy

    A Deskthority post from "flabbergast" describes using the ChibiOS development environment to configure TMK for ARM based processors like those used on the Teensy LC and 3.2. A toolchain such as the GNU ARM Embedded Toolchain is used to compile the code for the Teensy LC or 3.2. You will need to install the ChibiOS development environment per these instructions. The teensy_lc_onekey example details the steps to create a working TMK build. The QMK keyboard routine is based on TMK and it also has ChibiOS support for the Teensy LC and 3.2. There is a Complete Newbs Guide for QMK.

    Jay Thompson has created a QMK fork 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.

    Gordon has made a Hackaday.IO project called "QMK Powered Laptop Keyboard" which details the "gymnastics" of using QMK.

    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 files named "Instructions for modifying the Teensyduino LC code", "Instructions for modifying the Teensyduino 3p2 code", and "Instructions for modifying the Teensyduino 4p0 code" describe the changes you need to make for your matrix. The instructions also detail how to use the results from Marcel's Python program.

    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. The D630 folders include a Teensy 4.0 keyboard controller routine in addition to a Teensy 3.2 routine.

    Brian Chan and I teamed up to convert an IBM 380ED keyboard and trackpoint to USB as shown in this video. The code, Eagle files, and project description are in a folder at my repo. This project was documented at Hackaday.IO and Hackaday.com. Stephen designed a stand alone case for the 380 that you can 3D print with his files at thingverse. Brian has converted his IBM 380ED into a KVM, documented at Hackaday.IO.

    Olga has modified my code for a Commodore 64 keyboard. The Teensy LC code, key list files and project description are in a folder at my repo.

    T Caschy has modified my Teensy code to work with Blackberry Q10, HP Jornada, and Atari Portfolio keyboards. The code is in a folder at my repo.

    Luigi Caradonna has modified my Teensy LC code to work with a Lenovo Y480 with an Italian layout. The code is in a folder at my repo. Luigi also made a stunning marble base for this keyboard. Pictures are in the "I made it" section at the end of this Instructable.

    SimonT192 has modified my Teensy LC code to work with a GRiD 1550 keyboard with a UK layout. This laptop has a rotary encoded "IsoPoint" mouse which has been converted to USB using a Teensy LC. The code for the keyboard and mouse are in a folder at my repo along with a PDF describing the operation. Watch Simon's YouTube video for a very detailed description of his "Aliens Sentry Gun" GRiD laptop build.

    Nat has modified my Teensy code to work with a Thinkpad T43 keyboard and he has created a new Teensy 3.2 connector board using KiCad. The code, layout, and PDF description are in a folder at my repo.

    Step 16: Non-Standard FPC Cable Connectors

    If your keyboard has a non-standard FPC cable like the Thinkpad connectors 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 such as ChipQuik SMD removal alloy on all the joints, then use a hot air rework station and tweezers as shown in this video. 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.

    Eagle, KiCad, PCBWeb Designer, EasyEDA, and DesignSpark PCB are some of the free layout tools that are available. Sparkfun has excellent tutorials for Eagle schematic and layout. Also look at the Adafruit tutorial 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 Matrix_Decoder software to work with the new I/O pin-out.

    Step 17: Teensy 3.2 Controller for a Lenovo Thinkpad T61 Keyboard

    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 Instructable from rampadc uses a connector board with some glue logic and wires to an Arduino. A later Instructable from rampadc uses a single board with an MSP430 microcontroller. Mark Furland from Tome uses a connector board with wires to an Arduino. Mark's web site states that a Digikey WM6787CT-ND 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 Matrix_Decoder scanning software to only scan the 8 input pins and 16 output pins from the matrix. 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 repo or can be downloaded with the buttons below. My repo also has a zip'ed gerber file for fabrication at JLCPCP.

    Nathaniel has modified my board design for an IBM T43 keyboard which has a larger 40 pin connector. Pictures of his board are at the end of this Instructable in the "I made it" section. All of his design files can be found in a folder at my Github site.

    Step 18: Teensy LC Controller for a Lenovo Thinkpad T61 Keyboard

    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 added 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 repo or use the download buttons below. My repo also has a zip'ed gerber file for fabrication at JLCPCP. For an even smaller Teensy LC T61 controller board, check out Martin Refseth's Github repository. He has taken my board design and shrunk it down to be the same size as the Teensy. A picture of his board is at the end of this Instructable in the "I made it" section.

    Step 19: Building a Keyboard Base

    If you're not going to use the original laptop case to mount your USB keyboard, you can build a custom base like the ones shown above. Luigi Caradonna has made a stunning marble base using the CNC milling machine from his work. If you are lucky enough to have a 3D printer, you can make a custom case like TheGreenMamba's beautiful X61 Thinkpad keyboard. His 3D print files are at thingiverse. tcaschy has made a few 3D printed cases including the one shown above for a Blackberry keyboard with a Raspberry Pi Zero and LCD. Harjoc used acrylic to make a cool see-thru base. All of these projects are documented further in the "I made it" section at the end of this Instructable. My Thinkpad T61 keyboard base is made from 3 sheets of 1/4" plywood. I've done other wood bases for Toshiba 2415 keyboards, with and without touchpads, all documented at my repo. Warren has chiseled a wood base for a Dell Inspiron 1420 that is pictured on the PJRC forum with code at his Github repo.

    Step 20: Conclusion

    Converting a keyboard to USB is one of the most complicated laptop items to get working. The LCD can be converted to VGA or HDMI using an M.NT68676 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 touchpad code that utilizes the Teensyduino USB mouse functions. I merged the touchpad code with the Dell Latitude D630 keyboard code to give you an example of a "USB Composite device". It can be difficult to figure out the touchpad's clock, data, power, and ground pins if you don't have a schematic so I wrote a step by step procedure to identify the pins. If your trackpoint/pointing stick does not output PS/2, it may only provide the 4 signals from its strain gauge resistors. The Dell D630 pointing stick code and PDF at my repo shows how to translate the strain gauge voltage to USB using the ADC in the Teensy. Old Thinkpad trackpoints like the 380 can be converted to USB as documented in my Hackaday.IO project.

    If your laptop keyboard has a backlight, it can be controlled by the Teensy. This assumes your Teensy has a spare I/O pin left over after hooking up the row and column signals for the keyboard. The backlight LED signals from the keyboard are usually on a separate FPC cable which will require a matching connector. This small connector can be glued on the Teensy connector board or on a small perf board. Use an ohm meter, set to diode mode to determine the backlight anode and cathode pins. Experiment with different current limiting resistors to find a value that gives good brightness without excessive current. Solder wires from the connector pins to a BS170 or similar FET and the current limit resistor (see example schematic above). Not all Teensy I/O pins can be programmed as a PWM control signal. If you use wires instead of header pins to attach the Teensy to the board, you can re-route two I/O's to free up one of the PWM outputs. Two lines of code set the backlight frequency and duty cycle. Your code should make the duty cycle a variable that can be adjusted with Fn-Function keys.

    analogWriteFrequency(25, 400); // sets pin 25 to 400Hz PWM frequency

    analogWrite(25, 205); // sets pin 25 to a PWM duty cycle of 205/255=80%.

    In addition to standalone keyboards, picture frames, cell phone docking stations, 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 display, 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 Instructable 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 thedalles77@gmail.com if you have any questions, comments, or corrections.

    Good Luck

    Frank Adams

    First Time Author

    Participated in the
    First Time Author

    19 People Made This Project!

    Recommendations

    • Mason Jar Speed Challenge

      Mason Jar Speed Challenge
    • Bikes Challenge

      Bikes Challenge
    • Remix Contest

      Remix Contest

    97 Discussions

    0
    mr.mike.hawkey
    mr.mike.hawkey

    Question 4 days ago

    Hi Frank, Do you know of anyone who has modified your setup to use an STM32 Blue Pill?
    Thanks,
    Mike

    0
    Frank_Adams
    Frank_Adams

    Answer 3 days ago

    I have not heard of anyone using my setup with a STM32 Blue Pill. A quick look at the specs shows it has plenty of I/O but like the Uno, it doesn't have USB HID support built into the hardware.

    0
    Ties Bakker
    Ties Bakker

    Question 12 days ago on Step 11

    Hello, I seem to have a problem with my conversion. The hardware assembly went well, but non of my keyboard presses register. I have checked continuity from the teensy to the keyboard connector, and when I short the teensy pins it does send data. (with the continuity tester script), but it seems the teensy doesn't recognise the closing of the keyboard switch as a short to ground. the keyboard seems to have a 100ohm resistance when a key is pressed, I do not know if this is to high for the teensy.

    Does anyone else have this problem?

    Image 2.jpegImage 3.jpegImage.jpeg
    0
    Frank_Adams
    Frank_Adams

    Answer 11 days ago

    It's hard to tell from your pictures but my first guess is that the FPC cable is inserted upside down. FPC connectors can have contacts on the top or bottom but bottom contacts are more common. Make sure the bare metal traces on the end of the FPC cable match up to the contact pins that you can see inside the connector. Try flipping the cable over in the connector and see if the continuity tester code will give numbers when a key is pressed. 100 ohm switch resistance is normal for a keyboard. I've measured 250 ohms on some keyboards and it still works. Send me an email at thedalles77@gmail.com if you still can't get it to work.

    0
    Ties Bakker
    Ties Bakker

    Reply 8 days ago

    Thanks for the reaction! It indeed seems the resistance is not the issue. It turns out pin 28 and 12 were shorted to each other on the keyboard, making it seem the button was continually pressed (I think), disconnecting the flying lead from 28 seems to have done the trick, now on to the rest of the laptop!

    0
    yash.kishore
    yash.kishore

    20 days ago

    Hi,
    I am looking for the pinouts of 34pin ffc cable of the laptop keyboard.

    0
    Frank_Adams
    Frank_Adams

    Reply 19 days ago

    There is no standard pinout for laptop keyboards, that's why I have the Teensy act as a continuity tester while you test each key to see how it's connected.

    0
    yash.kishore
    yash.kishore

    Reply 18 days ago

    Thank you.

    0
    bbbolodden
    bbbolodden

    Question 4 weeks ago

    Hello Frank, any chance this would work for ibm x30 keyboard using teensy ++ 2.0?

    And i have other goal to extract the synaptic trackpoint from such keyboard with 3 buttons to make a usb thinkpad style trackpoint with left, scroll, and right button

    0
    Frank_Adams
    Frank_Adams

    Answer 4 weeks ago

    Yes the Teensy ++2.0 should be able to work with the X30 keyboard. The Teensy ++2.0 board shown in step 7 will work if the keyboard has a single FPC cable. You will need a new board if the keyboard has dual cables or a connector on the end of the cable as shown in step 16. This Hackaday project describes the process to make an IBM 380 keyboard and trackpoint work over USB: https://hackaday.io/project/171439-ibm-thinkpad-380ed-keyboardtrackpoint-to-usb

    0
    leabjoshua
    leabjoshua

    Question 5 weeks ago

    hello this is a awsome project but i am having so trouble getting all the keys on my keyboard to work. i have a 25 pin conector and using a teensy 3.2. i have resoderd the pins 2 times and its the same keys that dont work. i have also trimed the ribbon cable a couple of different ways to see if was makeing contact on the wrong leads but still the same keys dont work. some of the keys are CTRL-L, B, ENTER. there are more but thoughs are a few.i have also found that when i compile the code "Matrix_Decoder_3p2" no keys work but when i compile the "alternate" keys work but not the ones listed Above. any help would be great. Thanks
    0
    Frank_Adams
    Frank_Adams

    Answer 5 weeks ago

    Happy to help you. I'll need some more information. Send me an email at thedalles77@gmail.com with the following:
    A picture of your Teensy circuit board with the connector.
    A picture of the end of the FPC cable.
    A picture of your keyboard and the laptop model it came from.
    The "Matrix_Decoder_3p2.ino" code that didn't get any keys to work.
    The "Matrix_Decoder_3p2_alternate.ino" code that got most keys to work.
    The key list text file with the numbers that you got when you used the alternate matrix decoder program.
    Once I can see the pictures, look at the key list numbers and examine the code, I'll be able to tell you what things to try as we debug this problem.

    0
    TùngP13
    TùngP13

    Question 3 months ago

    Hi, thank you for making this. This is just what I am looking for. But I have several questions. Can I replace it with arduino? Because in Vietnam a Teensy cost almost 40$ I want to make it as cheap as possible. And do I have to look up for the keyboard datasheet to find which pin is Vcc,GND,...? Or they are just the same? I am going to use this for my dell inspiron15 5559 keyboard. Will it works? Thanks

    1
    Frank_Adams
    Frank_Adams

    Answer 3 months ago

    The low priced Arduino's don't have built in hardware for the USB HID keyboard interface. All Arduino's have a different pinout than the Teensy so my circuit boards won't work with them. I recently added a circuit board for a Teensy ++2.0 (see step 6 item 8). You can send the zipped gerber file to JLCPCB and get 5 boards. A Teensy 2.0++ clone can be purchased from Ali Express here. https://www.aliexpress.com/item/32953459905.html?spm=a2g0o.productlist.0.0.1efb5eff2djMTg&algo_pvid=d36bcf0c-37cd-4f83-b9ec-a12bbf5cfbf1&algo_expid=d36bcf0c-37cd-4f83-b9ec-a12bbf5cfbf1-1&btsid=0ab6fa8115925021465414159e2a14&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_
    It must be the 2.0++, not the regular 2.0. Your keyboard FPC cable has 30 pins with nubs on the side that must be cut off to fit in a generic FPC connector. I believe the pitch is 1mm but you should check it to be sure. A 30 pin 1mm pitch FPC connector can be purchased from Ali Express. This one has contacts on the bottom.
    https://www.aliexpress.com/item/32769748843.html?spm=a2g0o.productlist.0.0.51fe5d49vwYBnl&algo_pvid=8968769d-1103-4489-86ed-4f76f3e34e9b&algo_expid=8968769d-1103-4489-86ed-4f76f3e34e9b-4&btsid=0ab6fab215925024177193862ee3c1&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_
    They also have top contact connectors so check how your keyboard cable will be positioned and pick the correct top or bottom connector.
    If you want the backlight to work, you will need to order the correct FPC connector from Ali Express and solder it to the unused pads on the board. It will require some extra circuitry as described on step 20. If you need help with this, send me an email at thedalles77@gmail.com and I'll explain it further.

    0
    TùngP13
    TùngP13

    Reply 3 months ago

    Oh thank you very much. I'll order everything and start to make it. If anything goes wrong I'll email you. By the way my keyboard doesn't have the backlight so I am going to 3d print the case and wire some LEDs to the teensy. I just want to know is there any ports left on the board so I can wire and program the LEDs? And can you make a guild how to build a mechanical keyboard?

    0
    Frank_Adams
    Frank_Adams

    Reply 7 weeks ago

    I/O D6 drives the LED on the Teensy 2.0++ board but I also wired I/O D6 to pin 15 on the keyboard FPC connector. The LED acts as a pull down resistor and fools my code into thinking a key has been pressed. The solution is to unsolder the LED on the Teensy. If you don't, it will show the numbers 1 15 on the editor when you run the matrix decoder code and then the code will hang.

    0
    Frank_Adams
    Frank_Adams

    Reply 3 months ago

    The Teensy ++2.0 will have lots of extra I/O's for you to wire LEDs. Sorry I have never made a mechanical keyboard but a Google search shows lots of guides you can follow.

    0
    Luigi Caradonna
    Luigi Caradonna

    Question 2 months ago

    Hi, I'm planning to follow your guide to make my own keyboard out of a laptop's one.
    I have some concerns about the hardware I need especially about the FPC connector and the backlight circuit.
    The keyboard has a flat cable with 30 pins and it is 31mm wide, thus I suppose it should have a 0.8 or 0.5mm pitch, but I can't decide. In addition, the flat has 4 pins which seems to not be wired (shown in the attached image), 2 of them look they would make a short to 2 of the chip's pins, do they have any function?
    For the backlight, there is an additional 4 pins cable: in your instructions, you talk about the BS170, is that good for any keyboard or should I check anything?
    Last thing, which Teensy would you suggest in my situation to keep the whole thing as small as possible?
    The keyboard comes from a Lenovo Y510P laptop (ISO UK layout).
    Thank you.

    flat.jpgbacklight.jpg
    0
    Frank_Adams
    Frank_Adams

    Answer 2 months ago

    Your 30 pin keyboard FPC cable has a 1mm pitch. You can find them on Aliexpress if you do a search on "FPC connector". The formula is: Total width = Pitch x (N + 1) where N is the number of pins. You can use this to find the pitch for the connector for your 4 pin backlight FPC cable. 2 of the pins go to the anodes for the backlight LEDs and 2 pins go to the cathodes. Since the current for the backlight LEDs will be much higher than the regular keyboard switches, they have designed 2 pins on the FPC cable that are in parallel to help handle the current. Use an ohm meter with "diode mode" to get the led polarity and the forward diode voltage. The backlight will need a 4 pin FPC connector with the right pitch on a small blank board. Wire a FET like the BS170 and a current limiting resistor but you will need to experiment with different resistor values to get full brightness (without excessive current). The control for the backlight will come from the Teensy and it will drive the gate on the FET with a PWM signal to reduce the brightness.
    You will need 30 I/O's for the keyboard matrix and another output for the backlight. This can be done with smaller connector boards with a Teensy 3.2, Teensy 4.0. The Teensy ++2.0 board would also work but it is bigger.