Go Down

Topic: Printing in landscape through ethernet shield on port 9100 (Read 1 time) previous topic - next topic


Apr 07, 2011, 10:06 am Last Edit: Apr 07, 2011, 10:08 am by MHDfo Reason: 1
Hi everyone,

I'm using a Arduino mega with a modified ethernet shield to send data to a printer (actually through a Jetdirect module)...

It's working quite fine except i didn't find the way to setup the printer an print in landscape instead of portrait.

Is anyone had an idea about it ?



Interesting, can you post your code?

HP printers have escape codes to set attributes:  Landscape = 27 38 108 49 79 (decimal values

A complete (printer dependant) list can be found on: - http://www.dragon-it.co.uk/links/hp_pcl_codes.htm


Rob Tillaart

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


Apr 07, 2011, 12:06 pm Last Edit: Apr 07, 2011, 12:10 pm by MHDfo Reason: 1
All the code is based the pachatube tutorial and on someone's else work found on the net  but i didn't note whom and where... sorry for that

I just post here the code for printing something over 9100 port. My full  program is useless for people I think.

/!\ you need  PCL 5E compatible printer or something like that ( Meaning printer which use proprietary protocol should not work)

/*              test                                                                     */
/*      mac de la carte    byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xXX, 0xXX };          */
/* */
/* */

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xXX, 0xXX };
byte ip[] = { 192, 168, 1, XXX }; // IP of our arduino
byte server[] = { 192, 168, 1, YYY}; // IP of our printer

Client client(server, 9100);

long lastConnectionTime = 0;       
boolean lastConnected = false;     
const int postingInterval = 30000; 

void setup()
  Ethernet.begin(mac, ip);

void loop()
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
   // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();

void sendData() {
    // if there's a successful connection:
    if (client.connect()) {
    client.println("Hello Word");
    // note the time that the connection was made:
    lastConnectionTime = millis();
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");



I have try different way with differents representation but my main problem is how to give parameters to printer.
The xxx.print() , xxx.println() and xxx.write() are just print like other text.

The printer didn't interpret the code, it just print it out.

Any clue for me ?


Maybe try this way....

Code: [Select]

    client.print("\033&l10");    // [ESC] & l 1O to go to Landscape
    client.println("Hello Word");

I am actually used to controlling landscape/portrait via a job ticket that comes before the main print job.  This escape sequence is pretty old-school, but likely works.


Thanks for answering but unfortunately it doesn' t work. Anyway that the first time the printer don't print the code.

It prints : "ello Word"

with the write() or print()
println() just print "Hello Word" but still in portrait mode at least the printer seem to read something

I will try some other combinaison but other ideas are welcome


You might test printing the escape sequences byte per byte: 27 38 108 49 79 (decimal values


followed by print("hello");

get the idea?

What exact printertype is it?
Its interpreter might slightly differ.. or just not support landscape;    URL manual?
Rob Tillaart

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

Go Up