Tag Archives: thermal printer

Image dithering


I had to convert images to black or white points. This post is a summary of my tests and learning. My main source is the nice ‘Dither’ Wikipedia page. The major issue I had to face is when converting an image with an undefined length coming from a scanning process.



To print pictures on thermal paper with reasonably good rendering, they should be converted according the printer limitations. It’s quite simple, it can be printed only black pixels (and whites as the paper is usually white).

The first step consists to get a gray-scale image. There is plenty well known method, from the simplest averaging of the Red/Green/Blue channels to advanced ones where the pixel intensity is scaled to a color wavelength to simulate a particular response (such as black & white films).

michelangelo27s_david_-_bayermichelangelo27s_david_-_floyd-steinbergThe second step could be achieved by several algorithms. To convert gray-scale pixels to only black or white, a rather easy method is the Ordered Dithering. But it there is noticeable patterns on the resulting image. Another common method is the error diffusion, and in particular the Floyd-Steinberg dithering algorithm. It is this last one that I choose to study as I found the resulting image interesting.


The codes we can find over Internet usually rely on a buffer to store and propagate the errors of each converted pixel. This buffer have the same size of the image and is completed during the iteration over all the image lines.

As receipt thermal printer use paper roll, there is virtually no image length limit. If we want to convert on the fly the image and strait print it, we cannot rely on a fixe full image sized buffer. That’s why I experimenting conversion algorithm based on Floyd-Steinberg, but with only a small rotating buffer. The size of this ‘line’ buffer could be as small as a line size plus one.

Other than the code itself, I try to explain the principle with this Gif :



And the Java code use to generate it :


Very good readings about dithering :

8918261459861376809 (1)

Icebreaker Game


12026610_10207455771046540_1864584773_nAfter experimenting with the small receipt thermal printers and manage to make a portable camera, my brother came up with a very clever idea. He is organizer of a juggling convention, and he looked for a kind of funny game around beer selling and their receipt. The aim was to entertain and offer a beer every lets say 50 sold. He said we can do more than print pseudo randomly a winning ticket based on certain ratio.

The idea.

beerWe imagined a machine standing on a bar, with on the client side a camera pointing at you, a screen showing the camera output and few instructions. On the back side, a single button allowing the barman to launch the lottery for one ticket. What the machine do once you press the front big button (I really love these Adafruit massive buttons!), is taking a picture of you. And then there is two possibilities. If you loose, a souvenir receipt is printed with the picture of your face and a random funny quote. If you win, a winning receipt with the face of someone else is printed, and instructions telling you that if you find the random guy on the printed picture, you both won a free beer.

The printer.

2321The printer choice should consider reliability, speed and print
quality. Even if the last one is relative to what we can expect for black or white thermal printing. I moved from the affordable and small serial Adafruit 58mm printer to a more professional one. After some non conclusive test with a cheap 80mm Chinese printer, I finally get an Epson point of sale printer. The TM-T20 is USB and commands are very well documented on their website. If not set to the maximum print speed, they could make surprisingly good prints for bitmap pictures. It depends a bit of the paper quality as well. I get very nice results with BPA-free recycled paper roll.

The system.

Raspi_Colour_ROnce again, the raspberry pi is a nice card and of course perfectly capable of doing such a process. There is the official camera module, even if a basic webcam would make it as well, USB ports for the printer, HDMI for a screen, GPIO for buttons and leds. But most importantly, I can reuse a lot of code form the Polapi.

The software is written in Java and uses two external libraries. One for GPIO – Pi4J and an other one for USB – usb4JavaIn addition, the native raspbian program raspividyuv is used to get the camera frames. The camera output is on top of everything and always visible on the screen. The all Java software part is hosted on github. The runnable Jar file must be launch on the Raspbian LXDE environment and could be easily auto-launched. There is some logs here, but I must complete them a bit.

The case.

In the view to avoid yet another device taking dust in the garage, I made the case looks like an arcade. I just have to exchange the front panel to have a raspberry pi Mame machine ! (That will instead probably take the dust of the attic, but with style, surrounded by retro consoles)

Wood sawing 

Case filling

Resulting device


It was quite a success on the Juggling convention, it brought fun and few free beers ! It ran smoothly without any reboot despite I expected some bugs.

After being used on a week-end for around 500 prints, it will be used on a Hackathon in Geneva with a slightly different mode.



Instant-Printing-Point-and-Shoot camera

polapi01Here another project finally finished ! The Bluetooth thermal printer was fun. Unfortunately I didn’t get it work with apple i-stuff. A stand alone camera, as the Polaroid is in fact even more fun !
I used brass angle rods, glass fiber plates and screws for the case. A raspberry pi 2, this time with its own camera module. A TFT screen, the thermal printer, and a lipo battery. More details here:



During a party, the 3.6Ah lipo was able to keep running the raspberry pi for around 6h, plus around 100 prints !
I found a large aperture CCTV lens to get maximum sensibility. The counter part is it need to be manually focused.

It is worth to mention few facts about the paper. Thermal paper is very cheap and could be easily found without BPA, but it is sensible to sunlight and heat. Exposed to sun, the prints will fade with time.