Thermal printer isn't Printing Images

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 ' ='. .. .

I will need to look over the library some more. I haven't had the time, unfortunately. The datasheet is not really great at explaining the various modes, etc... but I am not sure that you are accessing the modes properly.

BTW, you can change the adafruit library directly. It has the main structure that you want, you just have to modify the parts that are different.

Retroplayer:
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.

I have got another code which is not using any specific Library. Its simply working on POS Commands... I used to send bitmap commands under //bitmap routine if you see.
The output is same yet...:frowning:
The code is in next reply.

#include <SoftwareSerial.h>
SoftwareSerial Thermal(2, 3); 

int zero=0;

int heatTime = 80;
int heatInterval = 255;
char printDensity = 15; 
char printBreakTime = 15;

static PROGMEM prog_uchar my_data [] = {
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};//I am skipping the data but the format is same..
void setup() 
{
  Serial.begin(57600); // for debug info to serial monitor
  Thermal.begin(115200); // to write to our new printer
  initPrinter();
}

void initPrinter()
{
  //Modify the print speed and heat
  Thermal.write(27);
  Thermal.write(55);
  Thermal.write(7); //Default 64 dots = 8*('7'+1)
  Thermal.write(heatTime); //Default 80 or 800us
  Thermal.write(heatInterval); //Default 2 or 20us
  //Modify the print density and timeout
  Thermal.write(18);
  Thermal.write(35);
  int printSetting = (printDensity<<4) | printBreakTime;
  Thermal.write(printSetting); //Combination of printDensity and printBreakTime
  Serial.println();
  Serial.println("Printer ready"); 
}

void loop()
{
  // underline - one pixel
  Thermal.write(27);
  Thermal.write(45);  
  Thermal.write(1);
  Thermal.println("Underline - thin");
  Thermal.println("01234567890123456789012345678901");    
  Thermal.write(10);

  // underline - two pixels
  Thermal.write(27);    
  Thermal.write(45);
  Thermal.write(2);    
  Thermal.println("Underline - thick");
  Thermal.println("01234567890123456789012345678901");    
  Thermal.write(10);  

  // turn off underline
  Thermal.write(27);    
  Thermal.write(45);
  Thermal.write(zero);
  delay(3000);
  Thermal.write(10);  

  // bold text on
  Thermal.write(27);    
  Thermal.write(32);
  Thermal.write(1);
  Thermal.println(" #### Bold text #### ");
  Thermal.println("01234567890123456789012345678901");    
  delay(3000);  

  // bold text off
  Thermal.write(27);    
  Thermal.write(32);
  Thermal.write(zero);
  Thermal.write(10); //Sends the LF to the printer, advances the paper
  delay(3000);  

  // height/width enlarge
  Thermal.write(29);    
  Thermal.write(33);
  Thermal.write(255);
  Thermal.println("ABCDEF");
  Thermal.println("012345"); 
  delay(3000);  

  // back to normal
  Thermal.write(29);    
  Thermal.write(33);
  Thermal.write(zero);
  delay(3000);
   
  Thermal.write(10);
  Thermal.println("Back to normal...");
 // Bitmap routine
  Thermal.write(27);
  Thermal.write(42);
  Thermal.write(1);
  Thermal.write(250);
  Thermal.write(2);
    for(int i=0; i<1024; i++)
    {
    Thermal.write(adalogo_data[i]);
    }
  Thermal.write(29);
  Thermal.write(47);
  Thermal.write(1);
  Thermal.println("Image ...");
  
 
  Thermal.write(10);
  Thermal.write(10);  
  do { } while (1>0); // do nothing
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Retroplayer:
BTW, you can change the adafruit library directly. It has the main structure that you want, you just have to modify the parts that are different.

I have modified it according to the datasheet of printer. One more thing I have done is that I have made private functions accessable publically. Then I tried sending commands as in datasheet. I could see the commands working fine. Even the bitmap command also runs but couldn't produce a bitmap unfortunately.. :frowning:

The output produced is :...... :frowning:

Your code looks like it should work, except this part when it starts the GS mode.

Thermal.write(29);
Thermal.write(47);
Thermal.write(1);
Thermal.println("Image ...");

"This command is ignored if a downloaded bit image has not been defined."

"GS * n1 n2 d1…dk Define downloaded bit image"

I think you may be using different kinds of modes. There are a few different ones. The GS /n mode requires you to have defined the image, but that is not what you have done yet.

"GS v 0 p wL wH hL hH Print raster bit image" I think this is the one you want to print a raw Bitmap.

I am not positive that I am right. The datasheet is a bit confusing and have several modes. Unfortunately since I cannot experiment with it, you must. :slight_smile:

I think the first mode is just defining a space in buffer for the image, not the actual image.

Having had a quick look at the printer manuals and the Adafruit library the problem looks like difference in commands sent to printer to print raster images.
The Adafruit printer does bitmaps with

DC2 * r n [d1…dn]

but to do the equivalent command with your printer is

GS v 0 p wL wH hL hH [d1…dk]

You either need to write a new printBitmap function in the Adafruit library to allow for the extra parameters or maybe modifying the existing code to use

GS * n1 n2 d1…dk

to store the bitmap (deleting all user defined characters) and then use

GS / n

to print the downloaded image.

I have no idea what I'm doing but have attempted to modify the library to print your bitmaps. It compiles but that's as far as I can test it. The library should really be re-written to suit your printer but that's probably beyond my abilities and attention span. :slight_smile:

To test it download the attached .h & .cpp files and replace the current ones then alter the Adafruit example to replace printBitmap with printBitmap2. You may need to delete the old library pre-compiled stuff & restart the IDE first.

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

  // Print the 135x135 pixel QR code in adaqrcode.h
  printer.printBitmap2(adaqrcode_width, adaqrcode_height, adaqrcode_data);

Fingers crossed.

Adafruit_Thermal.h (3.65 KB)

Adafruit_Thermal.cpp (16.2 KB)

1 Like

Did the modified library work okay?

Riva:
Did the modified library work okay?

I must say thankyou to you... Its working fine.. Thanks