Counting is fun. When I was young, I counted up to over 10,000 over the course of several months. Every night I'd count myself to sleep (not sheep, mind you, just numbers), and every morning I'd write down the highest number. When making change, I mentally convert the value to binary, both for fun and to keep the skill sharp. Sudoku is just 2d counting in puzzle form. I got addicted to Sudoku after idly playing it in a friend's newspaper one lazy afternoon, and have been looking for a way to satisfy this "fix" ever since. On line play is Ok, but I much prefer dead tree format for portability and handiness with marking up. I don't get the newspaper, so I lack that route, didn't have a printer at the time I started this project, and I'm too cheep to buy a book, so I was stuck with copying the board longhand or getting yesterday's paper from work. Matt's father (who's basement collection of spare parts is talked about with no small amount of awe) came up with a DPU-411 to whomever at the house had the will to use it, and it's been mouldering in the basement for some time. One day, while searching for a decent Linux sudoku board, it struck me that it would be easy enough to convert a board to ASCII graphics and print it out via the thermal printer.
The printer works with either serial or parallel, prints a selectable 40/80 width column on 112mm thermal paper. Online research states that there's an internal battery, but mine's quite dead. Not a significant issue, as I don't plan on bringing it on the road with me. The printer lacks an automatic paper cutter, and is rather slow, but it suits my purpose well enough. What makes it eminently suited for the role, though, is that it's free, and I'm poor.
I couldn't find any vendor supplied information on the printer, only information on how to interface it with specific products. The most useful site I found was for interfacing with Commtest equipment, which had a list of dip switches and an overview of what they did. It wasn't enough to know how to set the baud rate to an arbitrary value, but 9600 bps is perfectly usable. Testing via `cat >/dev/ttyS0`, I discovered two important things: firstly, that the printer only prints when it receives a newline, and secondly, although the printer can receive 9600 bytes per second, it can only print a line every few seconds, and will discard all extraneous data received during this time. Request/Clear to send did nothing, and experiments with the dip switches yielded no positive results. A very small python script that automatically inserts 2.5 second delays between lines was whipped up to solve the problem. The next test that I did was to print out the various international character sets (3 bits = up to 8 sets) to discover what the options were. The settings that suited the job the best were all three pins off, which is fairly close to ASCII, only missing some of the graphics characters and with a slightly incomprehensible lowercased R.
While testing the printer, I ran through the one roll that came with the printer. Buying a single roll of thermal paper is both inconvenient and uneconomical, and I didn't want to buy a bulk lot and end up not using it. Heavy investment during early testing of a project with no certainty of success is never the best of ideas. Fortunately, work provides roles of thermal paper for free, unfortunately, these rolls are only 80mm wide, and the roll is far to thick to fit in the paper port. They still work, with some caveats. I had to build a stand out of coat hanger wire to hold the paper so it could spin freely, as the feed system couldn't pull the paper with the roll unsupported. On 80 columns mode, only about 50 columns can be printed, and the first several lines after having a strip torn off are generally off kilter. The 50 column limit is fine for now, and since the paper self-rights it's self after a few lines, it's easy to compensate in software.
Enough of the hardware. The software consists of sudoku.py, a python program that scrapes Web Sudoku for puzzles and uses the PySerial module to control the output. Web scraping uses psxml.py, a simple XML parsing module I wrote for a separate project and am using here. sudoku.py has an optional terminal output that prints the puzzle to stdout. The program has two arguments, both optional. The first is a number indicating the difficulty level (defaults to zero), and the second, if present, indicates which serial port to use (0 = ttyS0, 1 = ttyS1, etc). If no second argument is present, it prints the puzzle to stdout. The program was developed on and for linux, but PySerial is windows compatible and I know of no reason it wouldn't work for windows.
If you wish to comment on this mod, either send me an email at email@example.com, or post on the official Second Page Media topic for this project.Return to index.
All works on this page is copyright 2009 Patrick Tait. Some rights reserved: