Thermal printer isn't Printing Images

Hello,
I am using a 2 inch thermal printer with arduino uno r3. I used adafruit library for thermal printer i.e. "Adafruit_Thermal.h". With this library the text (Strings)
are printing fine, but when there comes a bitmap image, the printer just prints some garbage dots. Guide me how to fix it.
Thanks

You're probably going to need to post your code.

Quick5pnt0:
You're probably going to need to post your code.

Code is as follows:

#include "SoftwareSerial.h"
// If you're using Arduino 23 or earlier, uncomment the next line:
//#include "NewSoftSerial.h"

#include "Adafruit_Thermal.h"
#include "adalogo.h"
#include "adaqrcode.h"
#include <avr/pgmspace.h>

int printer_RX_Pin = 5;  // This is the green wire
int printer_TX_Pin = 6;  // This is the yellow wire

Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);

void setup(){
  Serial.begin(115200);
  pinMode(7, OUTPUT); digitalWrite(7, LOW); // To also work w/IoTP printer
  printer.begin();

  // The following function calls are in setup(), but do not need to be.
  // Use them anywhere!  They're just here so they're run only one time
  // and not printed over and over.
  // Some functions will feed a line when called to 'solidify' setting.
  // This is normal.

  // Test inverse on & off
  printer.inverseOn();
  printer.println("Inverse ON");
  printer.inverseOff();

  // Test character double-height on & off
  printer.doubleHeightOn();
  printer.println("Double Height ON");
  printer.doubleHeightOff();

  // Set text justification (right, center, left) -- accepts 'L', 'C', 'R'
  printer.justify('R');
  printer.println("Right justified");
  printer.justify('C');
  printer.println("Center justified");
  printer.justify('L');
  printer.println("Left justified");

  // Test more styles
  printer.boldOn();
  printer.println("Bold text");
  printer.boldOff();

  printer.underlineOn(); 
  printer.println("Underlined text ");
  printer.underlineOff();

  printer.setSize('L');     // Set type size, accepts 'S', 'M', 'L'
  printer.println("Large"); // Print line
  printer.setSize('M');
  printer.println("Medium");
  printer.setSize('S');
  printer.println("Small");

  printer.justify('C');
  printer.println("normal\nline\nspacing");
  printer.setLineHeight(50);
  printer.println("Taller\nline\nspacing");
  printer.setLineHeight(); // Reset to default
  printer.justify('L');

  // Barcode examples
  printer.feed(1);
  // 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);

  // Print the 75x75 pixel logo in adalogo.h
  printer.printBitmap(adalogo_width, adalogo_height, adalogo_data);

  // Print the 135x135 pixel QR code in adaqrcode.h
  printer.printBitmap(adaqrcode_width, adaqrcode_height, adaqrcode_data);
  printer.println("Adafruit!");
  printer.feed(1);

  printer.sleep();      // Tell printer to sleep
  printer.wake();       // MUST call wake() before printing again, even if reset
  printer.setDefault(); // Restore printer to defaults
}

void loop() {
}

The output print iss attached...
Text is fine but image is returned as garbage dots... :frowning:

Moderator edit "You're probably going to have to post your code with tags"

What thermal printer are you using?

Retroplayer:
What thermal printer are you using?

Its chinese made printer. Model number is PT-48b.

Do you have a link to the datasheet?

What I am looking for is whether this printer supports graphic characters. You may be getting garbage because it doesn't.

Retroplayer:
Do you have a link to the datasheet?

Thanks. The PDF icon doesn't work, but it did lead me to another question. Are you driving the signal levels on that flat cable directly with your arduino or using an interface board in between? Your code doesn't look like it is driving everything directly.

Retroplayer:
Are you driving the signal levels on that flat cable directly with your arduino or using an interface board in between?

A interface board is available which is actually the logic level translator between printer and arduino.

Retroplayer:
The PDF icon doesn't work.

Here the manual is attached.

PT486FMB-enl.pdf (305 KB)

A thermal printer is readily capable of printing images, but the software controlling it may not me.

In fact, any printer can print images, except the ones based on typewriter technology which have
actual metal printing elements representing the letters and numbers.

Nauman048:
Here the manual is attached.

Thank you. I see that it has a bit image mode, now just need to look at the adafruit library to make sure it is compatible and putting this into the correct mode.

Thankyou so very much...

Looking at the datasheet and looking at the adafruit library, it doesn't look like the library is directly compatible with your board. To get into bitmap mode, you need to send a specific command. The reason it works with everything else is because the printer is set at defaults at power up and accepts your text.

Page 14 of the datasheet describes how to use the bitmap mode. You have to send ESC (27) then * (42) then a mode of 8 or 24 dots, and then your actual bitmap information. I don't see the library sending all those commands.

This was only a quick look, but I don't see it controlling the printer in the same way as the datasheet. However, some of the commands are the same, but those are for text stuff. The barcode and bitmap routines are not doing things the same way.

Can you tell me how to send the command???
I am sending the commands as:
printer.writeBytes(27,42,1);//ESC * m
printer.writeBytes(100,2);//n1 n2
for(int i==0;i<=200;i++)
printer.writeBytes(data*);//d1 d2 .... dk*
where the data is stored in program memory in the same format as in adafruit library example.
The code is successfully compiled and uploaded on arduino but the output is same as I have shown you above.(The data is also same)
I am stuck here... :frowning:

for(int i==0;i<=200;i++)

you mean
for(int i=0; i<200; i++) // 0..199 == 200 bytes

robtillaart:
for(int i==0;i<=200;i++)

you mean
for(int i=0; i<200; i++) // 0..199 == 200 bytes

Yes , if its the data of 200 bytes then I am sending it in this way. But its not working fine. The output is still meaningless dots.

I also have tried in this way:
for(int i=200; i>=0; i--)
{
printer.writeBytes(data*);*

  • }*
    This made the location of dots changed but meaningless yet.

What he is saying is "==" is not the same as "=". The double equal signs means "is it equal to?" and the single equal signs means it IS equal to. So, if you only use a single =, i will always equal 200. It will not count.

Retroplayer:
So, if you only use a single =,

Sorry the '==' was written here by mistake. Ofcourse I am using single ' ='. .. .