项目作者: gdsports

项目描述 :
Print pictures on a USB thermal receipt printer
高级语言: C
项目地址: git://github.com/gdsports/print-pics.git
创建时间: 2019-07-12T21:02:15Z
项目社区:https://github.com/gdsports/print-pics

开源协议:MIT License

下载


Arduino MKR and M5Stack Printing on Portable 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.

M5Stack Core + USB host module

M5Stack printing on portable thermal printer

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.

Hardware

Libraries

Arduino MKR board

MKR board printing on portable thermal printer

Hardware

  • Arduino MKR WiFi 1010 (SAMD21)
  • Lithium battery
  • USB OTG to host cable (red cable in picture)
  • USB cable for printer (black cable in picture)
  • USB thermal receipt printer, 58mm wide, battery powered

Libraries

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.

Portable receipt printer

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.

Convert picture to include file

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

  1. #define bitmap_width 384
  2. #define bitmap_height 258
  3. #define bitmap_density 2
  4. const uint8_t bitmap_data[] PROGMEM = {
  5. 0, 0, 0, 72, 16, 36, 2, 66, 0, 16, 0, 72, 65, ...
  6. ...
  7. };

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.

Arduino upload failure

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

Battery Power On Failure

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.