

the 135px high bitmap would be printed in 3 chunks. I ended up setting a maximum single chunk of a bitmap to 50 lines, i.e. Enabling this flag fixed the printout for me, however using it slows the printing down, so it's not an optimal solution. The printBitmap() (and my file-based variation of it) has the optional LaaT argument - it stands for line-at-a-time and means sending a separate print command for every single line of the bitmap, instead of one command for the whole image. I yet have to figure out whether 2kB is the real maximum limit of bitmap chunk size that the printer accepts.

Printer.printBitmapFromFile(135, 128, '/flash/lib/qrcode')Īpparently, the printer was able to handle smaller bitmaps but failed once the total size exceeded ~120 lines, 17 bytes each – which is 2040 bytes, and it may be meaningful or just a coincidence. Printer.printBitmapFromFile(135, 120, '/flash/lib/qrcode') Printer.printBitmapFromFile(135, 105, '/flash/lib/qrcode') Printer.printBitmapFromFile(135, 85, '/flash/lib/qrcode') Printer.printBitmapFromFile(135, 55, '/flash/lib/qrcode') Printer.printBitmapFromFile(135, 35, '/flash/lib/qrcode') Still suspecting some memory issue, I tried reading only part of the file, limiting the number of lines passed as a second argument to printBitmapFromFile():
#Print logo termal printer code
The QR code as seen by thermal printer – 2017, colorized. In fact, this time I didn't get a memory allocation problem, but this is how the bitmap was printed: This way only a small part of data would be kept in memory at once, effectively allowing for processing the whole bitmap. It would open the file, read it in one-line chunks and send the data to printer. Printer.printBitmapFromFile(135, 135, '/flash/lib/qrcode') # first two args are width and height in pixels I stored the bitmap bytes in a file, and then passed it as an argument to printBitmapFromFile() function like this: I tried streaming a bitmap from a file on disk. Once I fixed it I was able to print the smaller bitmap straight away! But it was still failing to allocate memory when trying to load the big QR code bitmap. When I dug deeper into the code I realized that my printBitmap() function had been a bit buggy. A 75x75px Adafruit logo is a 750B array – 75 lines per 10 bytes (required to code 75 dots), while a 135x135px Adafruit QR is over 2kB of raw data. It turns out that loading so many bytes at once into LoPy's memory is a no-go. The example bitmaps for Python library are defined in the code as arrays of integers. The printer would add line feeds where appropriate, based on the number of rows. Send the bitmap data as a sequence of bytes.Pass the number of columns (the width of the bitmap) in bytes (i.e.Pass the number of lines (the height of the bitmap).Send the appropriate command to start printing bitmap.The simplest one (that was implemented in the original Python library) can be described as follows: The printer's datasheet defines a couple of different mechanisms for printing bitmaps. But because of that, the bitmap can be represented as an array of bits, where 1 means black dot and 0 means blank dot. In fact, it allows for two colors: black and no color. The thermal printer is a rather crude image-printing device when you think of it.
#Print logo termal printer plus
I'll still wait some time for LoPy4 boards, plus it surely is an interesting challenge to try getting it to work on LoPy v1. Now that I have fixed issues around regular text printing, the time has come to do something about bitmaps.

I skipped this feature for the initial version of MicroPython lib and left it for later. by loading the whole bitmap into memory and sending it to the printer. This makes printing bitmaps (including QR codes) a bit problematic, especially the way it had been originally implemented in the Adafruit library, i.e. The printer library itself is quite heavy and once you initialize the printer and set up WiFi connection, you'll have around 36kB available. MicroPython v1.8.6-849-g0af003a4 on LoPy with ESP32Īnd this is with an empty main.py file. While 512kB of RAM looks fine on paper, you get roughly 10 times less right after booting up: I was able to test it with the LoPy version 1 board from Pycom, which is a bit resource-constrained. I recently wrote about a MicroPython library for Adafruit thermal printer.
