Pages: [1] 2 3   Go Down
Author Topic: Keyboard/mouse controller for ThinkPad X41 keyboard  (Read 3865 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would like to connect a ThinkPad X41 keyboard with TrackPoint via USB, with the help of an Arduino. Some facts:

  • I've never used an Arduino before, and neither am I an electronics guy. While I know some basics, and I've used a soldering iron in the past, I am mostly a programmer, capable of writing code close to hardware.
  • The connector has 40 pins. (I am still looking for a suitable socket.)
  • The TrackPoint (mouse) on the keyboard already generates PS/2 signals.
  • I want to be able to configure the TrackPoint using proprietary PS/2 commands directly from the Arduino, on certain key combinations. Made up example: FN-F2 = increase sensitivity

Questions, under the assumption that this is feasible:

  • Which Arduino should I chose?
  • I saw that some Arduinos, such as the Leonardo, can be used as HID via USB. However, when looking at the library functions, I see for example no method to send mouse scroll commands. Could I add methods myself, i.e. somehow bit-bang the USB connection?
  • How do I get started? My idea is to put something in between the keyboard and the laptop, and then use a multimeter to measure the signals that get emitted when a key is pressed. Only afterwards, I would connect the keyboard to the Arduino.

(There are ready-made ThinkPad keyboards for USB, but I'm not interested in those.)
« Last Edit: April 02, 2013, 10:47:46 am by feklee » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Which Arduino should I chose?

Probably a Mega2560 to read the whole Keyboard. You can program the ATmega16U2 on the board to do the same as the Leonardo is doing, you just have to define a serial protocol between them. You can try a Leonardo with some additional hardware (shift-in/-out registers may work) but be prepared that this gets a bit more complex.

Quote
However, when looking at the library functions, I see for example no method to send mouse scroll commands.

Scroll commands are button clicks with button numbers greater 3.

Quote
How do I get started? My idea is to put something in between the keyboard and the laptop, and then use a multimeter to measure the signals that get emitted when a key is pressed. Only afterwards, I would connect the keyboard to the Arduino.

My guess is that a multimeter isn't fast enough. You need something like a scope or logic analyzer to get a knowledge of what's going on. It's probably some kind of matrix with row and column pins. You can check that with a multimeter. If my guess is correct two of the pins are connected if you press a key.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Probably a Mega2560 to read the whole Keyboard. You can program the ATmega16U2 on the board to do the same as the Leonardo is doing, you just have to define a serial protocol between them.

Thanks for the suggestion. Just to make sure: What is "them", the ATmega2560 and the ATmega16U2?

Is writing that serial communication straight forward? Has someone done this before?

Quote
You can try a Leonardo with some additional hardware (shift-in/-out registers may work) but be prepared that this gets a bit more complex.

Not interested.

How about a Due? According to product description: "The Native USB port is connected to the SAM3X. It allows for serial (CDC) communication over USB. This provides a serial connection to the Serial Monitor or other applications on your computer. It also enables the Due to emulate a USB mouse or keyboard to an attached computer. To use these features, see the Mouse and Keyboard library reference pages."

Quote
My guess is that a multimeter isn't fast enough.

I assume, though, that keeping a button pressed causes a current to flow, which can be measured. I don't expect there to be just some quick signal.

Quote
You need something like a scope

Don't have access to one, and it's expensive.

In the worst case, I have to connect the keyboard directly to the Arduino, right from the beginning.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks for the suggestion. Just to make sure: What is "them", the ATmega2560 and the ATmega16U2?

Yes.

Quote
Is writing that serial communication straight forward? Has someone done this before?

For exactly the same purpose? To my knowledge: no. For parts of your problem (just keyboard): yes.

Quote
How about a Due?

The Due is able to do that but might be a bit expensive for the task. And you always have to keep in mind that the Due runs on 3V3 and not 5V.

Quote
I don't expect there to be just some quick signal.

As I wrote, I expect it to be wired as a matrix, so the controller will turn on one row, read all column inputs and turns that row off again to turn on the next row. This will be fast enough to get the fastest key strokes, do you think your multimeter is fast enough?

Quote
In the worst case, I have to connect the keyboard directly to the Arduino, right from the beginning.

As I already wrote: you can use your multimeter but not when the keyboard is connected to the notebook. Use it in the "beep" mode (connection check) and find out how the matrix is wired (which are the rows, which are the columns). It's a tedious job but if you connect the Arduino from the beginning chances are quite high you fry your GPIOs.


Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Due is able to do that but might be a bit expensive for the task.

Well, the first goal is to make it work at all. If later other people are interested in the solution, then it may make sense to try it with a cheaper Arduino.

Quote
As I wrote, I expect it to be wired as a matrix, so the controller will turn on one row, read all column inputs and turns that row off again to turn on the next row.

Phew, that would be complicated. I was expecting that one key press corresponds to current flowing over two pins, one for column, the other one for row.

I wonder whether it would be easier to simply get a dedicated keyboard controller, such as the KeyWarrior. I could let that convert keyboard signals to PS/2, and then pipe them into the Arduino, together with the mouse PS/2 signals. Then the Arduino would take care of configuring the TrackPoint (mouse) on key press, and for converting PS/2 signals to USB.

Quote
It's a tedious job but if you connect the Arduino from the beginning chances are quite high you fry your GPIOs.

Thanks for the warning!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Phew, that would be complicated. I was expecting that one key press corresponds to current flowing over two pins, one for column, the other one for row.

That would be a problem if two (or more) keys are hit together. You cannot distinguish which are actually pushed down.

Quote
I wonder whether it would be easier to simply get a dedicated keyboard controller, such as the KeyWarrior. I could let that convert keyboard signals to PS/2, and then pipe them into the Arduino, together with the mouse PS/2 signals. Then the Arduino would take care of configuring the TrackPoint (mouse) on key press, and for converting PS/2 signals to USB.

KeyWarriors all know USB and you can buy a cheap PS/2 to USB converter for the TrackPoint. Because of the last comment in your first post I thought you want to do it with an Arduino because you're interested in doing it not because you're interested in the result.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That would be a problem if two (or more) keys are hit together. You cannot distinguish which are actually pushed down.

Right - I didn't think about that.

Quote
KeyWarriors all know USB and you can buy a cheap PS/2 to USB converter for the TrackPoint.

Note that I need to bring the keyboard and the TrackPoint signals together in a microcontroller, because - to quote from my earlier messages: "I want to be able to configure the TrackPoint using proprietary PS/2 commands directly from the Arduino, on certain key combinations. Made up example: FN-F2 = increase sensitivity"

Possibly it's easiest not even to attempt to convert to USB at all inside of the Arduino:

Code:

[TrackPoint PS/2]------------------\
                                    ====[Arduino]====[PS/2-to-USB converter]----[HID input]
[keyboard]----[KeyWarrior PS/2]----/


Only it makes me unhappy that there are so many components. Reducing them could be something for the next iteration.

Quote
I thought you want to do it with an Arduino

If it's reasonably straight forward, then I would be interested in doing all inside of an Arduino right from the beginning.
« Last Edit: April 03, 2013, 04:26:57 am by feklee » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If it's reasonably straight forward, then I would be interested in doing all inside of an Arduino right from the beginning.

It's reasonable to do it with an Arduino. Even for the KeyWarriors you have to find out how the keys are wired, these chips don't know it and I doubt that the connector is standardized for that purpose. I don't see where the use of the KeyWarrior provides an advantage in this system.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's reasonable to do it with an Arduino.

So how would I do it? A possibly naive idea: Cycle through the rows and columns real fast, applying a voltage to them. Each time check if a current is flowing.

Hm, to see how the ThinkPad controller is doing it, it looks like an oscilloscope would be very handy. Perhaps I can find someone to lend me one.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And you always have to keep in mind that the Due runs on 3V3 and not 5V.

...and that could be problematic when working with PS/2 (TrackPoint), which runs with 5V.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
...and that could be problematic when working with PS/2 (TrackPoint), which runs with 5V.

If you always keep it in mind, it's not such a big problem. You just have to make sure you use some kind of voltage divider if a PS/2 output goes to a Due input.

Quote
A possibly naive idea: Cycle through the rows and columns real fast, applying a voltage to them.

Almost the right idea: cycle through the columns and make the row pins inputs. If you read any input for a given column, you have a key hit. But you have to derive which pins are which column or which row. That may be quite a lengthy task.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you always keep it in mind, it's not such a big problem. You just have to make sure you use some kind of voltage divider if a PS/2 output goes to a Due input.

For output from PS/2, yes. But for input, it could be (haven't checked) that it's necessary to provide signals at 5V. Input is necessary to configure the TrackPoint, e.g. the sensitivity.

Others have experimented with connecting a PS/2 mouse to a Due.

It's a tough decision: Due (3.3V may be a pain) or Mega 2560 (HID/USB may be a pain). All other Arduinos look unattractive because of their low number of pins.

Quote
Almost the right idea: cycle through the columns and make the row pins inputs. If you read any input for a given column, you have a key hit.

Makes sense - thanks!

I guess for the keyboard interface, 5V vs. 3.3V should not be an issue.

Quote
But you have to derive which pins are which column or which row. That may be quite a lengthy task.

40 pins are scary. ;-) I hope that it's easy to see which pins are for the TrackPoint and which ones are for the keyboard, simply by looking at the ribbon cable.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can try a Leonardo with some additional hardware (shift-in/-out registers may work) but be prepared that this gets a bit more complex.

Does it really become that more complex?

Suppose the keyboard is arranged in an 8x8 matrix, then two 8 bit shift registers should be able to do the job. To check if the key at column 5 in row 2 is active, I would set the column shift register to 00001000, and the row shift register to 01000000. Then I would check if a current is flowing.

Disadvantage: Setting the pins via a shift register may take some extra clock cycles, thus slowing down scan speed. For comparison: The KeyWarrior is clocked at 6MHz.

If my message is confusing: Note that I'm a total beginner, never having touched an Arduino so far, and also never having worked with a shift register (and a bit lazy on reading ;-).
« Last Edit: April 05, 2013, 06:07:33 pm by feklee » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does it really become that more complex?

Yes, you have more components which you have to solder separately. And you have more complexity in the programming because a shift register is differently programmed than a GPIO. But it's not that much, that's why I added the "bit" in the sentence.

Quote
Then I would check if a current is flowing.

How do you do that?
In a 8x8 matrix you need one shift-out register and one shift-in register. Set the row and read the column. An additional problem may be that the typical keyboard has more than 64 keys.

Quote
Disadvantage: Setting the pins via a shift register may take some extra clock cycles, thus slowing down scan speed.

That's absolutely no problem you'll be more than fast enough for a keyboard. If you can hit a key 5 times a second you're really fast, even with the shift registers you'll get a scan rate much above 5Hz.

Quote
For comparison: The KeyWarrior is clocked at 6MHz.

The typical Arduino is clocked at 16MHz, so it's much faster.

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Then I would check if a current is flowing.

How do you do that?

From the top of my head (it has been a long time that I last dealt with electronics): Probably with an input pin and a resistor, to measure if current is flowing through the wire providing voltage to the shift register.

Quote
If you can hit a key 5 times a second you're really fast, even with the shift registers you'll get a scan rate much above 5Hz.

Hitting the key five times per second would require a scan rate of at least 10 Hz (down, up, down, up, ...) - nitpicking, yes, but also for my own better understanding. Please correct me if I'm wrong.
Logged

Pages: [1] 2 3   Go Up
Jump to: