Microprinter Sparklines

Ever since Tom Taylor inspired quite a few of us to play with printers, I’ve been seeing what I can get mine to do. So far: barcodes were pretty quick. More recently, daily digests, twitter updates and even printing an entire a book. What’s next?

Microprinter Sparklines

Sparklines turned out to be fairly easy. I’ve written a basic Java library for talking to the printer, which I’ve shared on Github. The latest version of Microprinter.java connects over USB to the microprinter_sketch.pde Arduino sketch which then simply relays whatever you send to it on to the printer.

The Java library contains a method called printSparkline(), which takes a label and an array of data. Here’s how you’d use it to create the printout shown above:

int[] sawBytes = new int[256];
int current = 0;
boolean flip = true;
for (int i = 0; i < 256; i++) {
   if ((current >= 7 && flip) || (current <= 0 && !flip)) flip = ! flip;
if (flip) {
   current++;
} else {
   current--;
}					
   sawBytes[i] = current;
}				
microprinter.printSparkline("saw............", sawBytes);

int[] sineArray = new int[256];
for (float i = 0; i < 256; i++) {
   sineArray[(int) i] = (int) (Math.sin(i / 5) * 1000);
}				
microprinter.printSparkline("sin............", sineArray);

Please feel free to adapt and improve. If you make any serious changes I'd love to see them, and don't forget to get involved on the microprinter wiki.

2 Comments »

RSS feed for comments on this post.

  1. As today’s National Pedant Day, may I just point out that sawBytes[] holds a triangle wave, and not a sawtooth wave. :-) http://en.wikipedia.org/wiki/Triangle_wave http://en.wikipedia.org/wiki/Sawtooth_wave

    Comment by Ralph Corderoy — August 9, 2010 #

  2. Hi,

    Inspired by this (and Tom Taylor, Colm McMullan and uncle tom cobbleigh and all) I’ve spent a bit of time figuring out a Verifone 250 receipt printer and am at the point of controlling some basic formatting and getting it to print from a basic Python script.

    Next up is to combine the two and get some website parsing going on!

    Cheers

    Comment by Dan — December 2, 2010 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions.