The Stubborn Strobe
Well. That have been interesting 10 hours or so. I came to my studio today to have a bit of nonsense fun. Recently I started to fiddle around with some ESP microcontrollers, namely the ESP8266 and the ESP32, both fun and cheap devices (with pretty cheap devkits available at your typical electronics tinker stores) that have built in wifi capabilities.
To do something “useful-not-useful” with them, I started to look around for the most useless project I could do with them. And then, during a bit of cleanup at home, I stumbled over (not literally, luckily) my old 24 pin printer I used with my AMIGA in the 1990's. I thought to myself “how hard can it be to drive an old centronics interface from a modern microcontroller” and thought it would be a fun project to add a web api (as I have no interest in implementing one of the standard network printer interfaces) to an old 1990's printer.
So here's more or less what I did today:
- I unpacked the printer, inspected it and after it made a couple of stalling noises when I powered it up, I had to clean the rail that carries the printer head and lube it (preliminary with some WD40, this needs some real grease, though). After that, no more stalling noises.
- I connected it to my RaspberryPi with a USB-to-Parallel adapter. Apart from the usual udev access control fubar (you need to be a member of the “lp” group as I learned), this worked fine and I was able to print stuff by simply doing
echo "Hello World" >> /dev/usb/lp0. The printer ribbon is, surprisingly, not totally dead (I already looked for replacements – They can be found, but are, at this point, a tad expensive. Not sure how much more hassle it will be to try to “refill” it myself, though.
- I started to build a simple setup on a bread board to be able to drive the printer from my ESP8266. That was my first mistake. I had a sketch for an Arduino I found on The Forum and I should have tested it on an Arduino Uno or something comparable first. That would have given me some useful info.
- Instead, I quickly noticed that I was running out of IO ports on the ESP8266. I was suspecting as such and so I started to rummage through my IC collections to see if I could find a serial-to-parallel shift register. Luckily I found some 74HC595's. Using a shift register actually simplified the code a bit, so I wasn't even mad.
- I knew going in that my main issue was going to be that the Centronics port wants TTL levels (0/5V) and the ESP runs on 3.3V. I did recently buy some level shifters and so I was hoping that this would be a non issue. Well.
- I connected all of that up, having the level shifter driving the shift register, so that I didn't have to shift all 8 data lines. Testing with some LED's that seemed to work fine, so it was time to wire in the actual parallel interface. In preparation of this project I bought a Sub-D-25-Pin breakout board that has some nifty screw terminals for all 25 pins of the “Computer” side of a Printer cable. Luckily I found some old printer cables in my basement.
- Nothing works. I am checking all signals but nothing works. I start playing around with the timings, but none of these things should matter, according to the specs. I double check the wiring, I try to follow the signals with a cheap logic analyzer and one of these toy memory oscilloscopes but literally nothing works. The printer does not care about any of the signals I send to it, the BUSY and ACK lines stay silent from all I can tell.
- I finally did what I should have done in the first place, wire the parallel port up with an Arduino that runs on 5V and use the before mentioned sketch and that bloody effin printer prints on first try. I am happy and angry at the same time.
- I rewire and rewrite the Arduino version a bit to incorporate the shift register, to make sure it would work with one. Apart from a wiring mistake I made that made the printer print all kinds of fun crap this worked fine, too. The good news is: This works in principle. The bad news: There is something going on with the level shifting and that's the part where I am the least experienced. I am not an electronical engineer. Nope.
- I rewire everything with the ESP and still nothing works. I find a couple of problems with my wiring but still no response from the printer. I play with the timings again. Suddenly, the printer does print something. I play a bit more. I remember that sending an ASCII code of 7 to the printer should make it beep which is good for debugging. I play a bit more with the timings and things get a bit more stable, but it's still very broken
- I suspect some problem with the return signals and add another (unidirectional, this time) level shifter in the form of a 74HC4050 for the return signals. Things get worse.
- After a couple of hours of debugging with all the tools, I finally try the logic analyser again and finally I see something my memory scope didn't want to show me: The Strobe signal, that technically should just go low for a couple of microseconds, flips around like no tomorrow. Interesting. Looks like the printer pulls up the signal and for some reason the combination of the ESP and the level shifter can't do what the Arduino was able to do: pull down the signal reliably. Hmmmmmmm.
- I tried a couple of things (but don't take this as advice, as I said, I'm completely out of my depth here and probably need professional advice) and what seems to work fine is a 470 Ohm pull down resistor at the output of the level shifter.
- After fixing all the timings I messed so much with, I now seem to have a setup that works reliably and so as soon as I have refueled the lost energy of today, I can start writing some code for all the network stuff for this project. Right now I am tired and I need to do something completely different :)
(Images, schematics etc. will hopefully appear on a more upbeat post I will write after this project is “done”)
I now replaced the level shifters I used with a simpler component – The ones I used are based on a TXS0108E by TI and are probably a bit too clever for their own good, or rather, built for a different purpose. I've now replaced them with a simple, transistor based level shifter and this now seems to work without any pull down.
Now I need to get back to the software :)