Hi ! I am having trouble printing bitmap on my thermal printer bought on Aliexpress ::
https://fr.aliexpress.com/i/4000782512644.html
The Adafruit library tet sketch works well for text and barcode but the Bitmap returns chinese characters. I did some digging online and found a tutorial that helps print bitmap without the adafruit library.
I need some help working out the tech documentation - as I am able to reproduce a bitmap and have the same resutl as the tutorial posted above but I cannot manage to understand
- how to change the width :
- Why the width is equivalent to the height on the print (The logo is printed horizontaly instead of verticaly)
https://dfimg.dfrobot.com/nobody/wiki/0c0a789684349c93a55e754f49bdea18.pdf
Thanks for your help
Code
/*------------------------------------------------------------------------
Example sketch for Adafruit Thermal Printer library for Arduino.
Demonstrates a few text styles & layouts, bitmap printing, etc.
IMPORTANT: DECLARATIONS DIFFER FROM PRIOR VERSIONS OF THIS LIBRARY.
This is to support newer & more board types, especially ones that don't
support SoftwareSerial (e.g. Arduino Due). You can pass any Stream
(e.g. Serial1) to the printer constructor. See notes below.
You may need to edit the PRINTER_FIRMWARE value in Adafruit_Thermal.h
to match your printer (hold feed button on powerup for test page).
------------------------------------------------------------------------*/
#include "Adafruit_Thermal.h"
#include "adalogo.h"
#include "adaqrcode.h"
// Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ----
// If using hardware serial instead, comment out or remove these lines:
#include "SoftwareSerial.h"
#define TX_PIN 11 // Arduino transmit YELLOW WIRE labeled RX on printer
#define RX_PIN 10 // Arduino receive GREEN WIRE labeled TX on printer
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.
// Here's the syntax for hardware serial (e.g. Arduino Due) --------------
// Un-comment the following line if using hardware serial:
//Adafruit_Thermal printer(&Serial1); // Or Serial2, Serial3, etc.
// -----------------------------------------------------------------------
void setup() {
// This line is for compatibility with the Adafruit IotP project pack,
// which uses pin 7 as a spare grounding point. You only need this if
// wired up the same way (w/3-pin header into pins 5/6/7):
pinMode(7, OUTPUT); digitalWrite(7, LOW);
// NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page.
mySerial.begin(9600); // Initialize SoftwareSerial
//Serial1.begin(19200); // Use this instead if using hardware serial
printer.begin(); // Init printer (same regardless of serial type)
// The following calls are in setup(), but don't *need* to be. Use them
// anywhere! They're just here so they run one time and are not printed
// over and over (which would happen if they were in loop() instead).
// Some functions will feed a line when called, this is normal.
// Barcode examples:
// CODE39 is the most common alphanumeric barcode:
printer.printBarcode("ADAFRUT", CODE39);
printer.setBarcodeHeight(100);
// Print UPC line on product barcodes:
printer.printBarcode("123456789123", UPC_A);
mySerial.write(show,823); //Send “print bitmap instruction” to printer
printer.sleep(); // Tell printer to sleep
delay(3000L); // Sleep for 3 seconds
printer.wake(); // MUST wake() before printing again, even if reset
printer.setDefault(); // Restore printer to defaults
}
void loop() {
}
The bitmap
unsigned char show[] = {
0x1B,0x2A,0x20,0xFA,0x00, //Bitmap size: 24*250, revise parameter with the reference of general instruction set 34 and 35 < 24 is actualy the height & 250 the widht when printed ???
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0xFE,0x00,0x00,0xFE,0x00,0x01,0xFF,
0x00,0x01,0xFF,0x80,0x03,0xFF,0x80,0x03,0xEF,0x80,0x07,0xEF,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xE0,0x0F,0x83,0xE0,
0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x81,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,
0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,
0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x1F,0x01,0xF0,0x0F,0x81,0xF0,0x0F,0x83,0xE0,
0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0xC7,0xE0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,0xC7,0xC0,0x07,
0xEF,0xC0,0x03,0xEF,0x80,0x03,0xFF,0x80,0x01,0xFF,0x80,0x01,0xFF,0x00,0x00,0xFE,0x00,0x00,0xFE,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xFF,0x80,0x03,0xFF,0xC0,0x03,0xFF,0xC0,0x03,0xFF,0xC0,0x03,0xFF,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,
0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,
0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x0F,0xE7,0xF0,
0x1F,0xE7,0xF8,0x1F,0xE7,0xF8,0x1F,0xE7,0xF8,0x1F,0xC3,0xF8,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0xC1,0xF0,0x07,0xC3,0xE0,0x07,
0xC3,0xE0,0x07,0xC3,0xE0,0x07,0xC3,0xE0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x03,0xE7,0xC0,0x01,0xFF,0x80,0x01,0xFF,0x80,0x01,0xFF,
0x80,0x01,0xFF,0x80,0x00,0xFF,0x80,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x7F,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,
0x00,0x7E,0x00,0x00,0x3C,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x03,0xFF,0xC0,0x07,0xFF,0xC0,0x07,0xFF,0xE0,0x07,0xFF,0xE0,
0x07,0xC3,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,
0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF8,0x0F,0x80,0xF8,0x0F,0x80,0xF8,0x0F,0x80,0xF8,0x0F,0x80,0xF8,0x0F,0x81,0xF8,0x0F,0x81,0xF0,0x0F,0x81,
0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,
0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,
0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,
0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xF0,0x0F,0x81,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x0F,0x83,0xE0,0x07,0xC3,0xE0,0x07,0xFF,0xE0,0x07,0xFF,0xE0,
0x07,0xFF,0xC0,0x03,0xFF,0xC0,0x01,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x0a,
0x1B,0x40,
0x1b,0x2a,0x00,0x0C,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //Print a division line
0x1B,0x33,0x00,
0x0A,
0x1D,0x2F,0x30 //Print bitmap instruction
};