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 replies on “Microprinter Sparklines”

  1. 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

Comments are closed.