Serial printer command

Hi all, I am trying to print using thermal printer (ESC POS printer) by sending data directly from Arduino mega2560. I use serial1 Arduino mega2560 to send signal to the printer. I have been successfully printing by using this simple code:

void setup(){
Serial1.begin(19200);
}

void loop(){
Serial1.println("hello word");
}

The question is, how do I change the font of the font size?
I have been trying to send ESC command like this: Serial1.print("ESC @") or Serial1.write("ESC @") and the result is just printing that command on the paper.

I found some example that uses something like : Thermal.print(27,BYTE) however for some reason my arduino software is always fail to compile (ERROR: 'BYTE' was not declared in this scope)

Can anyone help me with this problem? Thank you in advance for any suggestions.... cheerss

All the Serial.println() does, is quite literally push whatever you ask it to console.

Sounds like your printer uses some sort of proprietary protocol for sending the commands? Do you have a data sheet on this?

You also mentioned Thermal.print. Sounds like you might have a library for the printer?

Just found a sheet containing all the commands for it. You are right, ESC command is flagged with a byte of 27. so do this:

Serial.write( 27 );

You then follow this with the additional information depending on what command you want to set. Also using write instead of print. write sends data in its raw form, print sends the ascii equivalent of any values.

thank you for the info tammytam....

Could you post the webpage regarding the information just now ?
Still struggling as it does not do anything even though I send data using write command T_T

mura1ma:
I found some example that uses something like : Thermal.print(27,BYTE)

That just means Thermal.print(27, yourNumber)

in other words replace the word BYTE by the appropriate number.

...R

This is a list for epson printers. - http://www.lprng.com/DISTRIB/RESOURCES/PPD/epson.htm -

write first two (or more ) helpers

void ESC(byte b)
{
  Serial.write(27);
  Serial.write((char)b);
};

void ESC(byte b, byte c)
{
  Serial.write(27);
  Serial.write((char)b);
  Serial.write((char)c);
};

and then you wrap it by function e.g.

27 45 48 ESC - 0 Cancel underlining
27 45 49 ESC - 1 Select underlining

void underLineOn()
{
  ESC(45, 49);  // ESC - 1
};

void underLineOff()
{
  ESC(45, 48);  // ESC - 0
};

Hi
Please help me out. I am currently using POS 76 II printer that i need to interface with arduino. I used MAX232 in between DB9 and Arduino Mega2560 for level shifting. I need to transfer data from arduino to printer and take print from printer. No reverse communication(from printer to arduino). I am using simple Serial.print("HI"); command to print but nothing happens on printer . Don't know why. Please help me.

Thank you
Arpit Gupta

Post a diagram showing how the Mega is connected to the printer.

Post your program.
And please use the code button </>so your code looks like thisand is easy to copy to a text editor

...R