I wanted to document some of the troubleshooting steps that I took to get the cat printer printing images from MEMENTO. It would have been lovely if everything had "just worked" but it took some sleuthing and experimentation.
First off I compiled the example in the CatGFX library for MEMENTO and tested to see if it could connect to the printer and successfully print at all. The example prints text and some circles.
After that success I brought in the PyCamera library and added in some button presses to initiate printing. This worked for printing text and shapes. Next was trying to get images printing.
Since thermal printers print in black and white, I initially tried converting the default framebuffer to a grayscale bitmap and sending that to the printer on a button press. This resulted in printing glitchy lines.
What I needed to do was capture a grayscale image from the start. Luckily Jeff Epler had implemented a "gboy" Gameboy-style filter in bitmaptools in CircuitPython. Since it was written in C, it was very straightforward to bring into Arduino. I added a simple refresh()
function to the PyCamera library to allow the screen to update with the bitmap generated with the filter.
Now the moment of truth: would the bitmap print? And on the first try it was a success! I was so excited. But then, it was terrible. It would stop printing halfway thru an image. The printer would connect properly, it would receive the buffer to print, it would start printing but would stop before completing the task. The MEMENTO would think it was still printing and essentially be frozen, requiring a reset. The percentage that printed was different every time.
I tried a few different things to solve this. I experimented with the BLE connection settings, adjusted the buffer size, implemented hard resets after printing, tried a different thermal printer library with cat printer support, used drawPixel
rather than drawBitmap
but alas, the same behavior always occurred. It being a Friday, I collected my various scraps of half-printed thermal paper and I committed my progress with notes, making peace with the fact that this project probably wouldn't work.
On Monday it was suggested that I try adding in some delays to the CatGFX library, since there is nothing in the library to account for failed or delayed BLE packets. Adding in over the top 1 second delays between almost every command resulted in a successful, although comically slow, print. Cautiously optimistic, I worked to reduce the delays and dialed in a compromise between speed and reliability, getting the delays down to about 5 ms
where needed. This modified version of the library is included in the code in the code repository and was used to compile the UF2.
Text editor powered by tinymce.