Pages: 1 [2] 3   Go Down
Author Topic: Thermal printer isn't Printing Images  (Read 3716 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

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

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, if you only use a single =,
Sorry the '==' was written here by mistake. Ofcourse I am using single ' ='. .. .
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...smiley-sad
The code is in next reply.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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.
« Last Edit: February 13, 2013, 12:57:04 pm by Coding Badly » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.. smiley-sad
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output produced is smiley-small..... smiley-sad


* test.jpg (90.33 KB, 928x320 - viewed 35 times.)
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Norfolk UK
Offline Offline
Edison Member
*
Karma: 66
Posts: 2482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
DC2 * r n [d1…dn]
but to do the equivalent command with your printer is
Code:
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:
GS * n1 n2 d1…dk
to store the bitmap (deleting all user defined characters) and then use
Code:
GS / n
to print the downloaded image.
« Last Edit: February 12, 2013, 08:26:21 am by Riva » Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Norfolk UK
Offline Offline
Edison Member
*
Karma: 66
Posts: 2482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley

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:
  // 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 - downloaded 22 times.)
* Adafruit_Thermal.cpp (16.23 KB - downloaded 28 times.)
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Norfolk UK
Offline Offline
Edison Member
*
Karma: 66
Posts: 2482
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did the modified library work okay?
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Pages: 1 [2] 3   Go Up
Jump to: