Go Down

Topic: Thermal printer isn't Printing Images (Read 4898 times) previous topic - next topic

robtillaart


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

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Nauman048



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.

Nauman048

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.

Retroplayer

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.

Nauman048


So, if you only use a single =,

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

Retroplayer

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.

Nauman048


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...:(
The code is in next reply.


Nauman048

#22
Feb 12, 2013, 11:04 am Last Edit: Feb 13, 2013, 06:57 pm by Coding Badly Reason: 1
Code: [Select]
#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: [code] [/code] tags added.

Nauman048


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

Nauman048

The output produced is :...... :(

Retroplayer

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

Retroplayer

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

Riva

#27
Feb 12, 2013, 12:51 pm Last Edit: Feb 12, 2013, 02:26 pm by Riva Reason: 1
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
Code: [Select]
DC2 * r n [d1…dn]
but to do the equivalent command with your printer is
Code: [Select]
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
Code: [Select]
GS * n1 n2 d1…dk
to store the bitmap (deleting all user defined characters) and then use
Code: [Select]
GS / n
to print the downloaded image.

Riva

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

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.
Code: [Select]
  // 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.

Riva

Did the modified library work okay?

Go Up