Home Creators Posts Import Register Favorites Logout

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.

Comments

Nick Scott

I have been using this for a while and suddenly it’s gone weird. It used to just print the typed phrase. Now it also prints out “Received over MQQT:” And Received MQQT PRINT:”

Alastair Aitchison

Now, I don't quite understand how, but apparently your Arduino has started sending both those messages to the printer. Which. Is. Baffling. The serial connection should be on pins 0 and 1, whereas the printer is on pins 2 and 3. So, it takes quite something to send it to the wrong output! I guess the "quick fix" first solution to try would be to simply comment out any lines that start with "Serial.print()..." or "Serial.println()..." , leaving only those that begin with printer.println(). Does that fix it?

Dave B

This looks great but no matter which nodes I install there are still missing ones or incompatible ones. Please can you list the nodes installed on your node-red to create this. Thanks!

Timothy Riseborough

Hi Alastair, Im trying to install the src/ThermalPrinter library using the link for github - when I try to include it as a .zip file it says 'Specified folder/zip file does not contain a valid library' - Any idea what I am doing wrong? Thanks

James Bloodworth

Hi Alistair, first of all, I'm loving the work! I've got everything working for the thermal printer connected with a Demos Mini D1 and NodeRED except for printing the image, even without trying to load one of my own images, just using the stock code the NodeRED dashboard either displays nothing or a broken link and if I hit "Print Image" then it prints out whatever is in the custom text field, any ideas? Also, would it be possible to add a couple of line feeds after each text has been printed? Thanks..

Timothy Riseborough

Hi Alastair, I return to this project 8 months later!!! Time flies!! I wonder if I could pick your brains... I have the printer and 3 push buttons running on the same Wemos D1 Mini, so I have slightly altered your code for this puzzle. My issues I am having are 1) When the thing starts up, it prints a load of rubbish - about 8 inches worth (I have put a picture in the google drive as an example), then after this it prints the 'Welcome to Flee The Farm' message as it should. This is workable but Id rather not waste the paper - save the planet and all that. 2)Secondly, the feed function doesnt seem to work via MQTT. If I push the physical button on the machine, it feeds but not if I send a '3' to the correct topic via MQTT Are either of these things that you have encountered before and do you have any suggestions please. I have put my code that Im using in a google drive folder if that helps. https://drive.google.com/drive/folders/1G_T6kuZfwJEYsdEHIbKa7iExl9DG0ftB?usp=sharing

Euan Hair

Hi Alastair, I'm having a similar issue with using the FEED command on either MQTT or SERIAL. I tried checking the ThermalPriner.cpp file but I can't figure out what needs amended. I’m using the GOOJPRT QR204 and every time I send the serial write for adjusting the heat time it’s interpreting it as a character ‘P’ the prints are also very faint and poor quality. Do you know why this may be?