Microprinter Sparklines
Posted by Roo - 18/07/09 at 10:07:28 amEver 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?
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.
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.

Contact
Search
Elsewhere Online
Licence
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 #