Wednesday, May 30, 2012

TwitterMatrixTicker Dot Matrix Tweet Printer

 At the beginning of this month, at the Silicon Valley Flea Market, I managed to pick up an old Star NP-10 dot matrix printer in relatively good shape for $5.  Due to other circumstances, I've also found myself in possession of just shy of two cases of tractor feed paper.  I figured I would need to find a reasonable application for these two wonderful events.
Demo Video:
 I present... the TwitterMatrixTicker!  I currently have it configured to watch for any tweets mentioning me (@KWF), and then having it print each tweet line by line on this great piece of printer history, so feel free to send me tweets and enjoy the thought of them interrupting my evening as they print out on this ridiculous loud monstrosity.
The hardware is relatively straight forward; a BeagleBone (Thanks to TI for giving me one for free!) uses Twitter's API to search for @KWF tweets, then parses out the usernames and text and sends it to the Star NP-10 over a USB-to-Centronics adapter.  I would love to have set up a webcam live-streaming the twitter stream streaming onto my floor, but I'm afraid that local bandwidth limitations make that prohibitive.

I currently have it just printing flat ASCII, but these printers can usually do quick a bit of formatting on their own.  I haven't been able to find a manual for this specific printer, but the Epson FX-80 manual should give you a good idea of the method; while printing text, send "ESCape,command-code" sequences in-line to place the printer into different modes (bold, wide font, underline, higher resolution).  The higher resolution, or "Near Letter Quality" mode is a good one to know, because dot matrix printers literally print via an array of metal pins striking a ribbon to the paper.  After a single pass, the font is... "dotty," and doesn't look very good.  By putting the printer into NLQ mode, it takes a second printing pass slightly off-set from the first, to try and smooth out the final result.
This was all printed in NLQ mode.  Considering that this printer is decades old, and that I didn't have to replace the ink cartridge in it (other than rolling out the next foot of ribbon), I have to say I'm quite impressed with this printer.  Modern printers really are terrible...

Like always, I give you the source code for the shell script I wrote for this:

Just change the user name on the first line, the output file to your printer device, and the timing limits if you want to pound Twitter more often than every 15 minutes, which I have it set up for.  This would probably lend itself well as a cron script, but I felt like writing it as a busy loop to make the dynamic API request intervals easier.

14 comments:

  1. Excellent job! This is so cool.

    ReplyDelete
  2. I just wanted to adapt this script for OSX. After replacing the "tac" command with "tail -n1000 -r" I found out that the "grep" statement seems to need some work, as is results only in lines with "text" in it. I will report back if I'm successful!

    ReplyDelete
    Replies
    1. Hmmmm. My summer job has me porting some of my scripts to OSX as well. Does OSX perhaps not like my several grep expressions on different lines?

      Delete
    2. I think so. Unfortunately I'm far away from being an regexp ninja, so this will be a nice challenge. I'm really surprised, that the data from the twitter api is so rich, I got a couple of ideas after looking at the raw data.

      Delete
    3. So, I finally found some time to fix the grep expressions for OS X and made a fork on github. It works fine with a dummy file simulating a printer.

      Delete
    4. That's awesome. I had forgotten that gists are forkable. I'll merge your edits with some of my tweaks and put a specific license on it.

      Delete
    5. I guess simply merging the two files will break the script on some linux machines, e.g. the version of "tail" on my linux box doesn't recognize the -r option. I also don't have a good idea how to make the script truly platform-independent (check for existing tac and fallback to tail?).
      About the license issue: Any license is fine with me.

      Delete
  3. I used to own a Star NX-10 printer way back. Just searching for it recently (to make sure I remembered the model right) I found the manual for it. In fact, I was even able to locate the manual for the NP-10 printer you have: http://www.star-m.jp/eng/service/usermanual/np10um1.pdf. It's amusing how things have changed so much since then.

    ReplyDelete
    Replies
    1. Sweet! Thanks. My Google-fu was simply failing me at the time.

      Delete
    2. That's actually only part 1. Part 2 is at www.star-m.jp/eng/service/usermanual/np10um2.pdf :)

      Delete
  4. Cool blog buddy.. bookmarked!

    ReplyDelete
  5. Great use of an old dot matrix printer! I can't believe that technology was state of the art not that long ago...

    ReplyDelete
  6. Good Morning KWF,
    sadly Twitter pulled the plug on the search link you used.
    Any Idea of how to use API1.1 in your script?

    nils

    ReplyDelete
    Replies
    1. Figures. I haven't bothered to follow Twitter's API changes recently, so I wouldn't be able to help you. Their documentation tends to be pretty good though, so good luck.

      Delete