Stokes' ProjBlog

A journal documenting innumerable, mostly terminally in-progress undertakings. Nerdiness abounds.


A display of character(s) December 8, 2009

Filed under: GAMBY,Miscelaneous Projects,New project! — Stokes @ 5:57 pm
Screenshot of my CharEdit tool.

As the W&B soda machine has been unplugged for the winter, I am putting the soda machine hack project on hold for a couple of months. In the meantime, I’m returning to some past projects, several of which I never wrote up in the blog. One such project is a system for handling and displaying an ultra-tiny bitmap font on a little graphic LCD, the sort that were on nearly every 90s cell phone and are currently popular with hobbyists.

There are several examples of little font code on the Internet, but those that I saw were all non-proportional (they have fixed dimensions, e.g. a W is the same width as an I) and/or have legibility problems. The characters were also typically 4×7 or 5×7 pixels, neither of which easily fit a power of two without wasting memory — a vital resource when working on a microcontroller with only a couple thousand bytes of program memory. The system I came up with uses a 5×5 bitmap for the character itself, plus four bits containing the character’s width and three bits containing the character’s vertical offset. These sum to 32 bits, a convenient power of two and a the size of a long number on an Arduino. A 5×5 bitmap was chosen because it is the minimum size to accurately display characters like M or E. The vertical offset allows ‘descending’ characters (like j or y) to actually drop below the other character’s baseline without requiring all non-descending characters to have wasted space below them. The character width allows the text to be crammed in more tightly; in the future, it will also allow for ‘alternate’ characters (like ö and ü) to be created by displaying an accent (an umlaut in this case) with a width of zero pixels followed by an ‘ordinary’ letter; the accent mark will appear over the other letter.

To experiment with this idea, I wrote a tool for creating, editing and displaying such a font: CharEdit. The image above links to a screenshot of CharEdit in action. Written in Processing, the program (or ‘sketch,’ in Processing terminology) provides a reasonably nice environment for drawing the characters and adjusting the with and offset data, as well as ‘exporting’ the font as Arduino-compatible C code. I intend to release CharEdit once it has been cleaned up a bit. This probably won’t happen for a month or two.

A Bare Bones Board (Arduino clone) with a small LCD.

My intention was to implement the font on an Arduino driving a common PCD8544-based display salvaged from an old Nokia cell phone. Since then, I got a small LCD breakout board from my fellow Dorkbot Boston member, Tim. The LCD itself is very similar to the one from the Nokia, but as the breakout board is already breadboard compatible and the LCD is operable on 5V (as opposed to 3.3V), it is much easier to work with. So far, I have basic text display with scrolling; line-wrapping is coming soon. The code is currently in the form of an Arduino sketch; I intend to rewrite it as a library and release it to the public. This is also likely to be several months off.

This work is also setting the stage for another project of mine, which I am keeping under wraps for the moment. More information as it comes closer to reality.


Leave a Reply

You must be logged in to post a comment.