This is an example program to print with a portable BLE thermal printer using a WeMos D1 mini ESP32.
The thermal printer I used.
This example is using the Thermal_Printer library.
The ID on my printer did not match with any of the ones preset in the library, so I had to add it manually to the szPrinterIDs[].
In order to print any arbitrary image you need to convert it to a bitmap with 1 bit per pixel.
Using GIMP I was able to convert the picture into a bitmap:
Bitmap Creation: Image > Mode > Indexed > Use black and white (1-bit) palette
Bitmap Export: File > Export > <name>.bmp
Tip
Play around with the Color-dithering setting to get the best conversion.
In order to use this bitmap in our program it needs to be converted, once more, into a C byte array.
To get the actual byte information out of a bitmap file a hex editor can be used, in my case I used Okteta.
Using Okteta to open the BMP file and export as C array:
Open BMP: File > Open > <name>.bmp
C Array Export: File > Export > C Array > Data Type: unsigned char
Byte Array:
static uint8_t bitmap[2110] =
{
0x42, 0x4d, 0x3e, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
...
};Important
- Make sure you change the type declaration from
unsigned chartouint8_tin order for it to work with the library! - Change the
widthandheightconstants to the width and the height of the image you used!
No printer found
The library connects successfully only to printers which IDs have been registered in szPrinterIDs[].
Make sure your printer's ID is registered.
If you'd like to find out the ID of your printer, enable the DEBUG_OUTPUT to see all clients (and their IDs) that were found during the Bluetooth scan.

