IBM LPFK & Arduino Nano.

User avatar
InSanCen

07 Dec 2013, 23:53

I am just wondering about the feasibility of using an Arduino Nano (Clone) to control an IBM LPFK. My initial concern (Apart from my coding), is that I will need something with more I/O. 32 keys and 32 lights. I do have a Mega R3 sitting here, but I can't see that sitting inside the case happily.

Do any of the Coders on here have any ideas about controlling lights?

Just musing for the time being, as I don't fancy ripping into it if I need something with more I/O, or if I am going to fail miserably at the code (I hate C).

Findecanor

08 Dec 2013, 05:23

You wouldn't be content with software only, or a protocol converter? The IBM LPFK speaks serial, and the protocol seems to be reverse-engineered already.

I have not programmed/built a LED keyboard, but I have looked up some info on how to do it on the AVR.
When many LEDs need to be lit individually, they are usually lit in a matrix, with each row being turned on in turn, cycling faster than the eye can notice. I suppose that you are going to reuse as much as possible of the PCB/membrane that the LPFK is using. Then you would have to reverse-engineer not only the keyboard matrix, but also the LED matrix.

Lots of people have made LED matrices controlled by Arduino/AVR, but you may have a challenge in making the timing for updating the LEDs work together with the timing for the USB port.
You would also need additional circuitry to drive the LEDs because not only does the AVR not have enough pins for both keys and LEDs, it is limited in the amount of current it can produce for the LEDs. Several people have done it before though and there is source code and schematics available on the 'net.

User avatar
InSanCen

08 Dec 2013, 22:24

I've tried to get it going using serial, but failed miserably. I've had it for a few years now, and not got anywhere. It may be that it hates both of the USB==>Serial "converters" I have, and wants a real serial port. As I understand it, they just Emulate RS232, rather than provide afull functionality. I'll break out the Thinkpad, which may have a "real" RS232 on the Superdock...it's certainly old enough, and there is certainly a 9 pin connector. If that fails, I'll look into modding the LPFK.

I'm happy to reuse as much or as little of the LPFK as I need to. Should I need to do my own multiplexing on the Matrix for the keys and lights (assuming that's possible), I'm happy with that. I would like to reuse the membrane if possible,as that will make life a lot easier.

User avatar
webwit
Wild Duck

08 Dec 2013, 23:24

From my failed experiments earlier...
Image

ethan

23 Dec 2013, 09:18

I saw your post about using the LPFK with an Arduino and I know a little bit about it.

Inside the LPFK is an 8031 MCU (MCS/51 with ROM), a MAX232 for serial, one 74LS00 that's used for the loopback function (the switch on the bottom) and reset, and four 74LS373 latches. I haven't completely reverse-engineered the schematic, but from what I've traced so far, the keys are on a matrix, and the four '373s are used to latch the state of the LEDs.

The protocol is entirely decoded, but it's a bit odd at first glance. Protocol details are at http://brutman.com/IBM_LPFK/IBM_LPFK.html, and a library (with example code) can be found at http://hg.philpem.me.uk/liblpfk/. As long as your Nano is going through some kind of RS-232 converter, I don't know why it wouldn't be able to talk to the LPFK (unless your 9600 baud was not timing-accurate). I haven't seen your code, but I'd think it's more likely that you didn't do the handshake properly or didn't send an enable than there's a hardware reason the Nano can't talk to the LPFK.

I'm just using mine with my Linux laptop and the example code in Phil Pemberton's library (I wrote the binary clock example). To hook it up, I modified a USB serial dongle to cut RI from the USB-serial chip and to plumb +5V over pin 9 instead since that's a known standard for power-over-RS232 (used by cash registers/POS and other devices), but that was just so I could have a simple cable. I believe the original IBM cable had a plug for an external +5V supply. The device is said to draw a max of 500mA @ 5V, so I decided to steal power from the USB-side of the serial dongle.

You _could_ hack out the 8031 and put in a pin-compatible AVR chip (you might have to invert the reset line because a real 8031 has RESET while Atmel and other MCUs use /RESET), but unless you have a compelling reason to duplicate the functionality of the existing MCU, I would recommend revisiting the serial approach, perhaps experimenting with it on a laptop/desktop first, then getting your Nano to stand in. One reason for this is apparently, codeninja had at least one LPFK that had a different serial protocol. He was one of the first to hack an LPFK, over 5 years ago, and it took a bit of guesswork to figure out that the more common serial protocol is nothing like what he described. I'd suggest starting with Phil's code and see if you can get something to work there first.

I'm still learning about mine. Even though I've seen documented that pin 4 is a second power lead, my schematic analysis suggests to me it's a reset line that does work at +5V/GND, but it's not clear to me yet if it's meant to connect to a serial signal like RTS or DTR (there is a diode clamp on pin 4 before the signal goes into the 74LS00 and comes out to the RESET line on the MCU - I'm uncertain if the diodes will protect the '00 against +/-12V or not - they will probably protect against +/-6V).

The LPFK is polled at 9600 baud, so it's probably reasonable to consider an arrangement where an Atmel processor with USB capability uses a spare pair of GPIO for a software serial port to drive the LPFK while the primary serial port talks USB. Another possible arrangement is a 644P (Sanguino) with two serial ports, one for the LPFK and the other to talk to an FTDI chip. Something to note: you can't easily make the LPFK act like a US keyboard because it doesn't send key-up events to the host. It was designed to be polled, not to act exactly like a desktop keyboard. It that's what you are trying to do, it might be worth considering replacing the 8031 with an ATmega8515 or something else that's pin-compatible.

I hope this isn't too much all at once, but if you say a little bit about what you want to do with your LPFK, an obvious solution may come out quickly.

User avatar
Game Theory
Mr. Despair

23 Dec 2013, 14:17

[great and helpful first post btw :) ]

User avatar
InSanCen

28 Dec 2013, 08:54

I'll re-read your post later, (about to leave for work), but that looks awesome.

Thanks for posting.

EDIT:-

Thanks for your post, and the links.

I'll try again with the thinkpad (Running Zorin Linux), and your examples. Hopefully with some decent source, and a real port, I can make it work without resorting to the Arduino. Should I need to however, I suspect I'll find your leads quite useful.

I'm not plannin on doing anything specific with the launchpad, but I did have a fancy about making a "ghetto" basic form of a launchpad. Partly for shits and giggles, partly because I want to see it used.
https://www.youtube.com/watch?v=yXLL46xkdlY

ethan

30 Dec 2013, 05:38

Having found your other thread, I see your original goal was just to get the LPFK working with a laptop. The MAX232 in the LPFK should work with any USB-serial dongle (I've seen issues with older 1488/1489 circuits not working with modern serial dongles, but the MAX232 is far more forgiving).

You can tap power off of a PS/2 or USB port or use an external +5V power supply to inject +5V down the LPFK cable. As I mentioned, I hacked a USB dongle to pass +5V down pin 9, then I made a DE9-DIN8 cable (by cutting an 8-pin DIN cable in half). The more traditional arrangement would be to use an unmodified dongle (or real serial port) and add the +5 at the DE-9 end of the cable.

The dongle I modified is a Keyspan USA-19HS (USB ID 06cd:0121), and it works fine with Linux.

I also asked Phil Pemberton about the reset pin. He just left that unconnected, so that leaves +5V, GND, TxD and RxD. Here's my wiring diagram...

Sun keyboard cable | DE-9
RED/WHT 1 GND 5
WHT/RED 2 GND 5
BRN/WHT 3 VCC 9 (my +5V mod on pin 9)
WHT/BRN 4 Reset NC
ORN/WHT 5 TxD 2 (PC RxD)
WHT/ORN 6 RxD 3 (PC TxD)
BLK/WHT 7 NC
WHT/BLK 8 NC

Because there's no reset line connected beween the PC and the LPFK, I've found that occasionally, I have to power the LPFK off and on to get it to reset the first time - you should see all the lights pulse on and off. If you do not, the LPFK might not respond to serial commands. Try a power cycle and see if it responds.

User avatar
InSanCen

31 Dec 2013, 09:21

Thank you very much.

I have some time off in the next few days, so I'll be trying that. I'll post back with any success.

I will have no issues finding 5v for testing purposes, I suspect I can use a 7805 and some Li-Ion cells (of which I have far too many), for a more permanent installation.

User avatar
wheybags

31 Dec 2013, 15:33

What kind of switches are in these?

User avatar
InSanCen

31 Dec 2013, 19:32

Membrane Switches.

It's not something you would want to type on, it's more of a most interesting oddity.

User avatar
Compgeke

31 Dec 2013, 19:58

Doing a web search for "IBM LPFK classiccmp" brings up a few results. The guys on the classiccmp mailing list have tried this in the past.

This here has a linux driver and some slight information on connecting it to a computer (if you follow the link):
http://www.classiccmp.org/pipermail/cct ... 77166.html

ethan

31 Dec 2013, 21:30

Compgeke wrote:Doing a web search for "IBM LPFK classiccmp" brings up a few results. The guys on the classiccmp mailing list have tried this in the past.
Yes. I'm part of that thread.
This here has a linux driver and some slight information on connecting it to a computer (if you follow the link):
http://www.classiccmp.org/pipermail/cct ... 77166.html
That's the software I posted the link to above (including the binary clock code I wrote for Phil). It's working for me with a modern (Ubuntu 13.04) laptop and an ordinary USB serial dongle (hacked to push +5V down the 9-pin cable, but ordinary on the USB end).

-ethan

ethan

31 Dec 2013, 21:37

InSanCen wrote:I will have no issues finding 5v for testing purposes, I suspect I can use a 7805 and some Li-Ion cells (of which I have far too many), for a more permanent installation.
This thing draws 500mA when all the LEDs are on. I think your coin cells will be drained rather quickly.

I'd recommend either splicing power from an additional USB cable to the 9-pin end of your LPFK cable (you don't have to hack the dongle - just push +5V from a new USB cable down the 8-pin cable) or finding a 500mA to 1000mA (1A) +5V PSU (like for a cell phone charger or an old ZIP drive) and wiring that to your cable (don't forget to connect ground from the PSU to the wires to LPFK pins 1 and 2). You _can_ power the LPFK from batteries, but you'll need at least 7.5V to have a 7805 work properly (read the datasheet), and you will be using quite a bit of your battery capacity in the regulator.

User avatar
InSanCen

01 Jan 2014, 01:52

Capacity is not an issue. The Lithium-Ion cells I use are Samsung ICR-18650A's, 3.75v nominal, 2,800mAH. I have, quite literally, hundreds of them. I may even put a small balance charger inside if I can find the room. I plan on using 2 with the low dropout version of a 7805 (2940?).

However, until I manage to get *something* out of it,this is all pie-in-the-sky conjecture. I am hoping to find a 9 pin connector in the parts box and have a play tomorrow, as the daughter is out fora few hours at a party, and will not be wanting to "help", which despite being cute as hell, and promising for the future, limits productive work.

User avatar
wheybags

01 Jan 2014, 13:16

Do these speak serial via a ps/2 connector? I ask, because this: http://www.ebay.com/itm/IBM-6094-020-Li ... 4aa2c88269 appears to have a ps/2 connector (thinking of getting one and trying to arduino it, if I can get one cheap :P)

User avatar
InSanCen

02 Jan 2014, 12:09

That's not PS/2 (6 pin mini-DIN), the LPFK uses 8 pin mini-DIN. See this link for a better image of the pins.
http://www.ebay.com/itm/6247480-IBM-Att ... 0558629441

These in black look better to my eye.
http://www.ebay.co.uk/itm/New-IBM-6094- ... 3f2b92d929

Or

http://www.ebay.co.uk/itm/IBM-RS6000-LP ... 5af945aafe

ethan

02 Jan 2014, 21:06

You can use a much more common and much cheaper Sun Type-4/Type-5 keyboard cable ($5 seems to be an ordinary price), but you'll have to shave the plastic corners off of one of the cable ends for it to fit into the LPFK (it took me a few seconds with a pair of diagonal cutters). It's just a straight-through 8-pin mini-DIN cable as used on many devices in the 1990s. No need to hold out for "the" IBM-branded 6094 cable for $50. I also chose to cut that cable in half because I have two LPFKs and it was easier to install a DE-9 on each of the cut ends than to make two mini-DIN8-to-DE9 adapters to plug into the computer end, but there's nothing wrong with a straight cable and an 8-pin-to-9-pin adapter, especially if you already have the 8-pin cable and don't want to cut it. A more extreme option (requiring good desoldering skills) if you don't have a mini-DIN cable and don't want to pay for one, is to open the LPFK (6 screws) and remove the mini-DIN cable from the inside and install a dedicated DE9 serial cable, made from scratch or by chopping one end off of an old modem cable (since those are free or nearly free when you can find one). I didn't want to alter my LPFK and I had the cable, so that's the route I took.

User avatar
InSanCen

16 Jan 2014, 01:10

I can get 8 pin Mini Din plugs and sockets easily enough, so I'll make up a dedicated cable is needed.

Thanks though.

MMcM

17 May 2021, 08:40

Here's what the PCB looks like, with and without the rubber domes.
IBM-LPFK-1.jpg
IBM-LPFK-1.jpg (467.6 KiB) Viewed 1078 times
IBM-LPFK-2.jpg
IBM-LPFK-2.jpg (541.21 KiB) Viewed 1078 times
And here's a modern converter using a Teensy LC and MAX3232 into a (big) macropad with (single color / no PWM) LED matrix.
IBM-LPFK-converter.jpg
IBM-LPFK-converter.jpg (262.46 KiB) Viewed 1078 times

User avatar
raoulduke-esq

17 May 2021, 15:21

MMcM wrote:
17 May 2021, 08:40
And here's a modern converter using a Teensy LC and MAX3232 into a (big) macropad with (single color / no PWM) LED matrix.
Nice! Any instructions/parts list/firmware/etc. associated with this image?

MMcM

18 May 2021, 02:31

raoulduke-esq wrote:
17 May 2021, 15:21
MMcM wrote:
17 May 2021, 08:40
And here's a modern converter using a Teensy LC and MAX3232 into a (big) macropad with (single color / no PWM) LED matrix.
Nice! Any instructions/parts list/firmware/etc. associated with this image?
I think the initialization sequence still needs some work to reliably enable communication.

User avatar
raoulduke-esq

18 May 2021, 02:55

MMcM wrote:
18 May 2021, 02:31
I think the initialization sequence still needs some work to reliably enable communication.
Thanks for that! I used to think I was smart and could figure things out, but now with a newborn my capacity for thought is cut in half and my free time is decimated. You’d probably figure out the C3 Maestro firmware in a day but at this rate it will take me a year if I get to it at all.

User avatar
raoulduke-esq

01 Jun 2021, 03:02

MMcM wrote:
18 May 2021, 02:31
raoulduke-esq wrote:
17 May 2021, 15:21
MMcM wrote:
17 May 2021, 08:40
And here's a modern converter using a Teensy LC and MAX3232 into a (big) macropad with (single color / no PWM) LED matrix.
Nice! Any instructions/parts list/firmware/etc. associated with this image?
I think the initialization sequence still needs some work to reliably enable communication.
Tried to put this together based on the picture and I must have done something wrong. The firmware compiles and loads on the teensy just fine. The sockets I found were 90 degree PCB mount with a grid of 8 unmarked pins so I ripped one apart to map the pins and numbered them as match the numbers in my diagram. The pin coming out the back of hole 5 became pin 5 and I connected the 5V VCC to it. I guessed it was a 3v power lead going to + on the MAX3232 so I used the 3v and ground by the reset button. I figured that in the picture the green wires must be for (RX - to kbd) and the yellow would be (TX - from KBD) so I wired it like that to the pins in the sockets I found according to this diagram and put (TX - from KBD) to the serial RX pin on the controller and (RX - to KBD) went to TX pin on the controller. That way yielded nothing so I swapped the TX/RX on the controller. That time I got an endless stream of received key codes in the console.
Screen Shot 2021-05-31 at 9.00.52 PM.png
Screen Shot 2021-05-31 at 9.00.52 PM.png (356.41 KiB) Viewed 481 times
Any idea what I did wrong? Or can you elaborate a bit on the connections?

MMcM

01 Jun 2021, 05:23

Hmm.

The pin numbering looks right. The way to keep from getting messed up by mirror images and male vs. female is that 3 and 4 are closer to one another than 4 and 5.

The table also looks right. 3 to RS-232 pointing into board and out from there to RX. 8 to RS-232 pointing out of board and in from TX.

Yes, 5V from USB to power the keyboard and 3V from Teensy's voltage regularly to power MAX3232 and set its TTL voltage.

Here are some photos of the one here from different angles. Perhaps this will make clear what is different.
IBM-LPFK-converter-2.jpg
IBM-LPFK-converter-2.jpg (266.5 KiB) Viewed 426 times
IBM-LPFK-converter-3.jpg
IBM-LPFK-converter-3.jpg (221.26 KiB) Viewed 426 times
Can you post a picture of your build?

MMcM

01 Jun 2021, 17:36

There isn't any documentation that comes with these cheapo MAX3232 breakout boards. But I have confirmed that the + and - signals are VCC and GND (that is, TTL level power -- which makes sense since the charge pump outputs aren't for use in a circuit) on both left and right. As well as front and back, of course, since the hole goes through. So it shouldn't matter where those connections go.

But there are two separate drivers on the front and back, which is why they only have pads. So it is important to solder across (front-in and front-out or back-in or back-out) for any one signal.

Code: Select all

       HW-027
<- 14 DOUT1     GND   15 |
-> 13 RIN1      VCC   16 +
+  16 VCC       DIN1  11 <-
|  15 GND       ROUT1 12 ->
      RS232 <-> TTL

HW
|  15 GND       DOUT2  7 ->
+  16 VCC       RIN2   8 <-
-> 10 DIN2      VCC   16 +
<-  9 ROUT2     GND   15 |
The silkscreen on the bulkier, slightly more expensive, Sparkfun board is much clearer.

User avatar
raoulduke-esq

02 Jun 2021, 04:04

Thanks for the details MMcM!

Here are some photos of my hideous work. I tried to build it all into a project box on the first try instead of piloting it raw like I usually do... Guess I learned my lesson when it looked like ass and I had to rip it all out. Then I thought I found the problem through rubber duck debugging while I was trying to type this out but...
IMG_0629 copy.jpg
IMG_0629 copy.jpg (3.18 MiB) Viewed 377 times
Working with those little pads is dreadful. I think this generally resembles what you did though. The Yellow on mine is 3v from the Teensy going to the + and the White next to it goes to ground on the Teensy. White on the other side connects to 1 or 2, which are both ground. Green is from 3 and is TX from the keyboard. Blue goes to 8 and is RX for the keyboard.
IMG_0631 copy.jpg
IMG_0631 copy.jpg (2.61 MiB) Viewed 377 times
This is hideous. Green goes to 0 on the Teensy and Blue goes to 1, which should be RX and TX respectively. The on the Teensy bottom to the left of center is 3v and the center pin at the bottom is ground.
IMG_0630 copy.jpg
IMG_0630 copy.jpg (2.76 MiB) Viewed 377 times
This shows the plug a bit better. Red is from 5V and connects to what I identified as 5 when I took the socket apart. Here's where I originally had a mistake... 5V was connected to 8 instead of 5. Hoping I didn't kill my keyboard with this oversight! I tested the fixed version on a spare and it didn't work either, so perhaps I didn't fry it. Anyway, I switched 5V to 5 where it belongs and put Blue to 8 (RX to keyboard) and tried again but still no luck.
IMG_0629 copy.jpg
IMG_0629 copy.jpg (3.18 MiB) Viewed 377 times
IMG_0632 copy.jpg
IMG_0632 copy.jpg (952.31 KiB) Viewed 377 times
There's also this little guy on the back. I've tried it in both positions and had no joy.

Here's the console output when I connect the converter.

Code: Select all

*** HID console connected: QMK IBM LPFK keypad converter (FEED:6094:0001)
  > Keyboard start.
    LEDs: 00000000
I noticed you pushed a new commit to your repo- tried downloading that, replacing what I had, and recompiling.

Code: Select all

Compiling: keyboards/converter/ibm_lpfk/led.c                                                      keyboards/converter/ibm_lpfk/led.c: In function 'flush':
keyboards/converter/ibm_lpfk/led.c:66:9: error: implicit declaration of function 'serial_send' [-Werror=implicit-function-declaration]
         serial_send(buf[i]);
         ^~~~~~~~~~~
cc1: all warnings being treated as errors
 [ERRORS]

MMcM

02 Jun 2021, 05:42

raoulduke-esq wrote:
02 Jun 2021, 04:04
Here are some photos of my hideous work. I tried to build it all into a project box on the first try instead of piloting it raw like I usually do... Guess I learned my lesson when it looked like ass and I had to rip it all out.
It's not so bad. Rework is the name of the game with these one-offs.
raoulduke-esq wrote:
02 Jun 2021, 04:04
Working with those little pads is dreadful. I think this generally resembles what you did though.
If I am not mistaken, the MAX3232 is backwards. That is, the left side with HW silkscreened on it is logic level and the right is RS232. In other words, rather than always being left-to-right, one side of the board is RS232 and the other side is TTL no matter which side is up.

But since this is so easy to get confused about, I wouldn't rely on my memory for this. Take a multi-meter to the pins and those of the chip and compare with the datasheet.
raoulduke-esq wrote:
02 Jun 2021, 04:04
Hoping I didn't kill my keyboard with this oversight!
In this case, I think that's pretty hard to do. The serial lines are connected to a MAX232 (earlier version) so it's prepared to handle moderately high voltages and even negative.
raoulduke-esq wrote:
02 Jun 2021, 04:04
There's also this little guy on the back. I've tried it in both positions and had no joy.
Ouroboros means loopback. In this mode a key press will light the corresponding LED. Nothing else happens, but that should tell you whether it's got 5V and whether switch / lamp type things are working.

Lightning-bolt is remote serial. That's where you want it.
raoulduke-esq wrote:
02 Jun 2021, 04:04
I noticed you pushed a new commit to your repo- tried downloading that, replacing what I had, and recompiling.
Yeah, the May breaking changes includes more rework of the LED matrix support. Some contributor has been doing a lot there, though it seems to still be preparing for something actually interesting. But since the API is now more flexible, I was actually able to do what I wanted more straightforwardly rather than pretending to be a one-deep heat-map with two PWM levels, which was kind of lame.

Once you get yours working, I'm sure you can come up with something more creative to do with all those LEDs.

User avatar
raoulduke-esq

03 Jun 2021, 03:00

Great observation about the MAX3232 having unique orientation. Makes sense. And it's not every day you get to discuss Ouroboros in a keyboard forum!

I tried changing the small chip to the other direction and still struck out. Normally I can put a few wires and some firmware that someone else wrote together successfully but this one continues to elude me.

As calmly as possible I yeeted (as the youths say) into the trash the Teensy and all of the extra chips and sockets I bought. I can't trust any of it now so I'll order again fresh... larger parts this time like that nice Sparkfun one and a socket that's panel mount or at least comes with the PCB if it's gonna be PCB mount.

Once everything comes in again I'll give it another shot. Hoping it's not a cable issue; I have just a regular 8 pin mini din cable from eBay where I had to cut down the rubber that squares off the plug to make it round again so it would fit the socket.

User avatar
raoulduke-esq

Today, 00:22

MMcM wrote:
02 Jun 2021, 05:42
Yeah, the May breaking changes includes more rework of the LED matrix support.
I updated the LED section of my personal keymap and it compiled just fine- thanks!

Ok... So my parts FINALLY came in! Enough parts for 2 LPFKs cost as much as one of the LPFK due to minimum orders, shipping, etc. from those boutique electronics suppliers. Amazon has spoiled me.

I'm as sure as I can be I put it together correctly this time. Same colors as last time. There's only 1 ground terminal on the SparkFun breakout board so I ran the 2nd ground from the connector to the Teensy instead of chaining it to the SparkFun, meaning that 3 ground wires are connected to the Teensy. That's the only difference. Paid close attention to what's TTL and RS232 and what direction.
Spoiler:
IMG_0649 copy.jpg
IMG_0649 copy.jpg (660.2 KiB) Viewed 51 times
IMG_0650 copy.jpg
IMG_0650 copy.jpg (1.46 MiB) Viewed 51 times
IMG_0654 copy.jpg
IMG_0654 copy.jpg (2.54 MiB) Viewed 29 times
IMG_0655 copy.jpg
IMG_0655 copy.jpg (2.64 MiB) Viewed 29 times
IMG_0656 copy.jpg
IMG_0656 copy.jpg (2.32 MiB) Viewed 29 times

Get it all connected up... Nothing. QMK toolbox recognizes the firmware, but that's about it. No LEDs. No keystrokes. Now I'm faced with the possibility that either my cable is bad or my NIB LPFKs are dead. Gonna start with a new 8-pin RS232 cable not from eBay if I can find one. Such disappointment.

Post Reply

Return to “Workshop”