Thermal Printer Project Resources (Patreon)
Content
Hello lovely Patreons,
You can find the Arduino sketch, Fritzing project, Wiring diagram and Node-RED flow at the following Google Drive link: https://drive.google.com/drive/folders/1OMwNfHp_I6P5sbmstMUSePZApQiv_wmn?usp=sharing
The exact model of printer I'm using doesn't seem to be available from the supplier any more, but this one looks identical, and for almost exactly the same price: https://www.ebay.co.uk/itm/GOOJPRT-QR204-58mm-Mini-Embedded-Receipt-Thermal-Printer-TTL-USB-M7A3/293662363160
The eagle-eyed among you will notice a slight modification in the code here compared to the one I demonstrated in the video, which relates to the ability to print pictures (which was a late addition to the project after I had already recorded the code section - Doh!). This functionality is already included in the code above so you don't need to worry about the details, but in retrospect, this provides me with a good opportunity to explain the steps involved, and how you could further modify the code yourself.
So, firstly, there's a new #include "Image.h"line near the top of the code. This includes the image data (the cipher code) that's saved in a separate file in the same directory as the main .ino file in the code download. It's a big byte array that represents a monochrome bitmap. As noted in the comments in that file, you can create this array from a regular bitmap file using online tools such as https://javl.github.io/image2cpp/ or using the Windows "LCD Assistant" app at http://en.radzio.dxp.pl/bitmap_converter/
There's some notes in the Image.h file itself as to the settings to use, but basically you want to copy the output created by either of those programs into the array defined in that file, and also amend the image_height and image_width variables as appropriate. (The maximum width of a thermal printer is 384 pixels, for reference).
In the globals section, I've increased the size of the cmdSerialCallback to include 4 elements rather than 3, and in the setup function I've registered a new callback for the "PRINTIMAGE" action, which is the command we'll send when we want the picture to be printed. When this happens, this calls the printImage() callback at the bottom of the code, which simply calls the printBitmap() function in the thermal printer library and passes it the bitmap data from the Image.h array.
If you like, you could define several different arrays of different image data (called, say, Image1, Image2, Image3 etc.), and select which one to print by passing a parameter to the PRINTIMAGE function, in exactly the same way as a parameter is sent to the PRINT command to specify a text string to be printed.
One thing to bear in mind is that the image_data occupies quite a lot of memory, and might strain a device like an Arduino Nano or UNO. Another reason to love the ESP32 for this project (besides the multiple serial interfaces and the built-in WiFi) is that it has much more built-in memory and so can easily handle more, larger images!
Sorry for any confusion at the end there, but let me know if you have any questions! Cheers.