Thermal printer isn't Printing Images

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

Nauman048:

Riva:
Did the modified library work okay?

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

That's good to know, I may be temped to review the rest of the library in my spare time.

LucidTronix has a tutorial on printing full color images and binary bitmaps on their site: lucidtronix.com - lucidtronix Resources and Information.. They have sample code, images, and a demo video.

Try the tutorial for printing bitmaps stored on an SD Card on a thermal printer available at lucidtronix.com - lucidtronix Resources and Information.. Their library automatically thresholds the image if it is in color and has a print scanline function that prints the image row by row.

Hi Riva,

hope you are still around, I have tried the attached files as well as bringing in your additions to the new Adafruit libraries, however they seem to have added a few additional lines that now cause the additions to bomb out.

Any chance you would be willing to relook at this?

I have the exact same issue where i need to use the GS v function instead of DC2, :slight_smile:

Adafruit-Thermal.h

   writePrintMode();

	// Riva addition
    writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, uint8_t g, uint8_t h);

    setPrintMode(uint8_t mask),
    unsetPrintMode(uint8_t mask),
    writePrintMode();

Error

In file included from A_printertest.ino:14:0:
C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:209:102: error: ISO C++ forbids declaration of 'writeBytes' with no type [-fpermissive]
writeBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, uint8_t g, uint8_t h);
^
C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:210:30: error: ISO C++ forbids declaration of 'setPrintMode' with no type [-fpermissive]
setPrintMode(uint8_t mask),
^
C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:210:5: error: 'int Adafruit_Thermal::setPrintMode(uint8_t)' cannot be overloaded
setPrintMode(uint8_t mask),
^

Bobbo:
Hi Riva,

hope you are still around, I have tried the attached files as well as bringing in your additions to the new Adafruit libraries, however they seem to have added a few additional lines that now cause the additions to bomb out.

Any chance you would be willing to relook at this?

I have the exact same issue where i need to use the GS v function instead of DC2, :slight_smile:

A couple of questions first.
If you delete the Adafruit libraries and use the libraries I supplied does it print graphics okay? I'm trying to work out if the printer has changed and/or just the libraries.

Can you supply links to the printer your using (along with any manuals you can find) and link to the AdaFruit library your talking about just in case it's not the same as the ones I can find.

Initially I just renamed the original files and copied your into the folder, after restarting the IDE it came up with the similar errors.

I then reloaded the library from the Lib manager and checked if it compiled, which it did, I then went through and added the code you highlighted "//Riva Additions" into the newer libraries.

I was on a similar track last night in trying to modify the Libraries but came unstuck on some of the more complex code, :slight_smile:

The printer i managed to get my hands on is a Digipos DS-800: http://support.epostraders.co.uk/support-files/documents/1/NUS-DigiPoS_DS800_PrinterManual.pdf

They don't refer to a DC2 command, however I see they do support the GS v command so i'm hopeful that the device is capable of printing simple bmps.

Replacing the .h and .cpp in the library gives me the following errors relating to the SoftwareSerial function:

A_printertest:26: error: no matching function for call to 'Adafruit_Thermal::Adafruit_Thermal(SoftwareSerial*)'
A_printertest.ino:26:35: note: candidates are:
In file included from A_printertest.ino:14:0:
C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:51:3: note: Adafruit_Thermal::Adafruit_Thermal(int, int)
Adafruit_Thermal(int RX_Pin, int TX_Pin);
^
C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:51:3: note: candidate expects 2 arguments, 1 provided
C:\Users\Administrator\Documents\Arduino\libraries\Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:47:7: note: Adafruit_Thermal::Adafruit_Thermal(const Adafruit_Thermal&)
class Adafruit_Thermal : public Print {

sorry, missed this. This is the Adafruit Lib I'm using that appears to have been updated since your previous edit.

Update: Fixed it - got to do with the way the IDE has removed the prog_* types

Updated library attached if anyone going forward comes across this thread.

Adafruit_Thermal.cpp (19.2 KB)

Adafruit_Thermal.h (6.67 KB)

1 Like

Bobbo:
Update: Fixed it - got to do with the way the IDE has removed the prog_* types

Updated library attached if anyone going forward comes across this thread.

Glad you got it sorted out. Are the libraries the old original ones or the latest AdaFruit ones? I just happened to still have the old AdaFruit libs and they compiled fine for me using IDE 1.0.6 so I guess the problem is the newer IDE's