Print pictures on a USB thermal receipt printer
Print pictures from Flash on a portable USB thermal printer. The printer and
the MKR and M5Stack boards are running from their own batteries.
This option is a nicely packaged ESP32 with battery and display. The optional
M5Stack USB module provides the USB host interface for the printer. The USB
module is based on the MAX3421E USB chip which is supported by the USB Host
Shield 2.0 library.
The MKR board is powered by the battery shown. The printer is powered by its
internal battery so the battery in the picture is not powering the printer.
This example program does not use the WiFi network so a MKR Zero should also
work.
The printer has two identical mini USB sockets. Be sure use the one labelled
USB. The one labelled COM is an RS-232 port. The voltage is not compatible
with USB and may damage the MKR or M5Stack board.
Links to shopping websites tend die so to find a similar printer, try the
search term “portable thermal receipt printer” on your favorite shopping
website. Unfortunately, it is not possible to tell if a printer is compatible
with the ESC POS library so some changes may be necessary. Different printers
implement different subsets of the ESC POS commands.
mkpic.sh converts any image file supported by ImageMagick convert to a C
include file. The image is resized to fit on a 384 dot wide printer. Colors are
converted to dithered black and white dots. To preview the result, view output
file bitmap.png. The other output file is the image name with “.h” appended.
$ ./mkpic.sh wave.png
bitmap.png is a black and white version of the wave.png file.
wave.png.h is a C include file with the black and white image processed
for printing using the ESC * command. The Python program bitmapband.py
converts bitmap.png to a C include file transposing rows and columns as
needed.
Example output
#define bitmap_width 384
#define bitmap_height 258
#define bitmap_density 2
const uint8_t bitmap_data[] PROGMEM = {
0, 0, 0, 72, 16, 36, 2, 66, 0, 16, 0, 72, 65, ...
...
};
If the result is too light or dark, use a paint program such as PhotoShop or
GIMP to adjust the image before running mkpic.sh.
I found installing a 1 uF capacitor between GND and RST helps a lot. See
the link for more discussion.
http://community.m5stack.com/topic/55/simple-fix-when-upload-fails
When running on battery, the M5Stack does not turn on when the USB host module
is installed. The M5Stack works fine running on battery but once it is turned
off, it can only be turned on by plugging in power via the USB jack.
The M5Stack power on works correctly when the USB host module is removed.