0

Connecting a printer to an Arduino?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Connecting a printer to an Arduino?

by copiertalk on Sat Sep 04, 2010 8:32 pm

uberhund wrote:So you used an ethernet shield on the Arduino to address the printer through a URI of some sort?


port 9100 is a simple protocol. The device will print anything it gets on that port. You can simply send your data and it will print.

Yes, with an ethernet sheild. I
copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm
Location: Texas

Re: Connecting a printer to an Arduino?

by uberhund on Sat Sep 04, 2010 8:51 pm

I'm intrigued by this. Could you post a sketch that you actually know works?
Hacking is an addiction. Arduino is the gateway drug.

uberhund
 
Posts: 142
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

by copiertalk on Sat Sep 04, 2010 9:21 pm

I bet I can work something up to show functionality. :D
copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm
Location: Texas

Re: Connecting a printer to an Arduino?

by copiertalk on Sun Sep 05, 2010 1:05 pm

here you go, its not pretty but will send a message to the printer with my website.

Code: Select all | TOGGLE FULL SIZE

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 33 }; // IP of our arduino
byte server[] = { 192, 168, 2, 32 }; // IP of our printer

Client client(server, 9100);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
 
  delay(1000);
 
  Serial.println("connecting...");
 
    Serial.println("connected");
    client.println("Courtesy Copiertalk.com");
     client.println();
 
  if (client.connect()) {
    Serial.println("connected");
    client.println("Courtesy Copiertalk.com");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}



8)
copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm
Location: Texas

Re: Connecting a printer to an Arduino?

by copiertalk on Sun Sep 05, 2010 1:19 pm

This is probably too big but oh well.

Image

:D

I can resize it later if need be.
copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm
Location: Texas

Re: Connecting a printer to an Arduino?

by uberhund on Sun Sep 05, 2010 1:48 pm

Outstanding, copiertalk. I would not have guessed this would work. Many thanks for taking the trouble to provide the code segment. I look forward to trying it on my next printer implementation.
Hacking is an addiction. Arduino is the gateway drug.

uberhund
 
Posts: 142
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

by copiertalk on Sun Sep 05, 2010 1:54 pm

I hope to clean it up and develop it a little more. With more and more devices becomming network ready I feel this can and will be used more and more by the arduino community.

I am not sure where to expand or what can take place put it can be done and implemented. I just need to work a little more on the "look and feel" so to speak.
copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm
Location: Texas

Re: Connecting a printer to an Arduino?

by Naili on Tue Sep 21, 2010 8:38 am

Hi thank you very much

I didn't updated but my problem seems to come from the newsoftserial lib wich is not compatible with Arduino Mega
Naili
 
Posts: 1
Joined: Tue Sep 21, 2010 8:35 am

Re: Connecting a printer to an Arduino?

by short on Fri Sep 02, 2011 11:05 am

I know, this is a pretty old thread, but I'll continue it anyways, as I am glad that Google found it for me.

Has anyone been able to run a Epson TM-T88 at the CuteDigi-RS232-Shield? If so, what is the setup of your printer (Handshake, Parity, etc.) and could you please post your sketch? AFAIK the shield sorts out all Voltage problems, so it should basically be like plug-the-shield-onto-the-arduino-plug-in-the-printer-and-you-are-ready-to-go-solution. Well it turns out, it is not.

After I made the modifications mentioned by UberHund, I am now trying this sketch, but without ANY response from the printer:

Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>
#define out_pin 7
#define in_pin 6
SoftwareSerial printer =  SoftwareSerial(in_pin, out_pin);
void setup()
{
  pinMode(in_pin, INPUT);
  pinMode(out_pin, OUTPUT);
  printer.begin(19200);
  delay(1000);
  printer.print(0x1B, BYTE);
  printer.print('@'); // ESC(HEX 1B) @ is supposed to initialize the printer
  printer.print("hello world");
  printer.print(0xA, BYTE); // print buffer and line feed
}

void loop() {
  printer.print("hello world");
  delay(2000);
 }



Couldn't get it to print anything or respond at all, so I'd be glad for any hints, what could be the issue here.



Cheers,

short
short
 
Posts: 5
Joined: Fri Sep 02, 2011 10:20 am

Re: Connecting a printer to an Arduino?

by uberhund on Fri Sep 02, 2011 1:16 pm

Though I don't see anything obviously missing from Short's code, here is a sample sketch that I find works well with *my* Epson receipt printers (of the U220 generation), and the serial shield from CuteDigi modified as I described a few posts earlier:

Code: Select all | TOGGLE FULL SIZE
#include <NewSoftSerial.h>
//Though not necessary, these useful formatting escape codes are available on the Epson Web site and elsewhere
char emphasisON[] ={0x1b, 0x45, 0x01};
char emphasisOFF[]={0x1b,0x45,0x00};
char fontA[]={0x1b,'M', 0x00};
char fontB[]={0x1b,'M',0x01};

char justLeft[]={0x1b,'a',0x00};
char justCenter[]={0x1b,'a',0x01};
char justRight[]={0x1b,'a',0x02};
char selectRed[]={0x1b,'r',0x01};
char selectBlack[]={0x1b,'r',0x00};
char lineFeeds2[]={0x1b,0x64,0x02};
char sPaperCut[]={0x1d, 0x56, 0x01};

NewSoftSerial receiptPrinter(2,3);   //I've attached the TX and RX of the Epson printer these pins of the Arduino,
//jumpered through pins 0 and 1 of the CuteDigi board

void setup()
{
  Serial.begin(9600);           // start serial for output to debugging monitor
  Serial.println("Setting up...");

  receiptPrinter.begin(9600);  //set up the printer stream
  formatPrinter(fontB);          //optional - selects a nice font,

}

void loop()
{
  formatPrinter(lineFeeds2);
  printOUT("Hello Epson Printer!");
  formatPrinter(lineFeeds2);
  formatPrinter(lineFeeds2);
 
  receiptPrinter.println("1234567890123456789012345678901234567890");
  printOUT(sPaperCut);

  delay(60000);

}

void formatPrinter(char *pFormatString){

  for(int i=0; i<3;i++)
    receiptPrinter.print((char)*(pFormatString++));

}

void printOUT(char sPrint[48]){
    receiptPrinter.println(sPrint);
}
Hacking is an addiction. Arduino is the gateway drug.

uberhund
 
Posts: 142
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

by short on Fri Sep 02, 2011 3:57 pm

Thanks for the sketch, tried it, still nothing. I am starting to think that either my cable (came along with the printer...) or the shield isn't working. What seems odd is the TX light, which is flickering without any reason (no data being sent) from time to time. Probably not right.

Can you shed some light on your printers defaults (start it, hold the feed button). My settings are:

Baud Rate: 9600bps
Data bits: 8 bits
Parity: none
Stop bit: 1bit or more
Handshaking: DTR/DSR
Buffer Capacity: 4k
Handshaking Operation (busy condition): Off line or receive buffer full



Thanks again for your help,

short
short
 
Posts: 5
Joined: Fri Sep 02, 2011 10:20 am

Re: Connecting a printer to an Arduino?

by uberhund on Sat Sep 03, 2011 3:21 pm

I'm using the identical settings, Short. Wish I could be of more help.
Hacking is an addiction. Arduino is the gateway drug.

uberhund
 
Posts: 142
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

by richms on Sun Sep 04, 2011 6:25 am

When I was connecting a prolific USB-Serial to the printer I had to do all sorts of connections before it would work, handshaking etc lines. I got a parallel interface to replace it so dont recall what it took exactly, but it was not just a case of rx and ground being connected.

richms
 
Posts: 558
Joined: Tue Jan 20, 2009 3:05 am
Location: New Zealand

Re: Connecting a printer to an Arduino?

by uberhund on Sun Sep 04, 2011 8:38 am

Short, I custom-built the cable for my project. I'll post a photo/schematic of it soon. This is now my favorite candidate for the source of your problem.
Hacking is an addiction. Arduino is the gateway drug.

uberhund
 
Posts: 142
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

by short on Sun Sep 04, 2011 3:47 pm

uberhund wrote:Short, I custom-built the cable for my project. I'll post a photo/schematic of it soon. This is now my favorite candidate for the source of your problem.


That'd be great, thanks. I already tried, but the usual Pin2/3/5 (rx/tx/gnd) I found via Google didn't get me any results so far.

I might have to switch to the SparkFun Printer anyways, at least unless there is a way to get the Epson print upside-down, which I need for my projects. But from where I am right now - not printing at all - thats more than the distant future :D


Cheers,

short
short
 
Posts: 5
Joined: Fri Sep 02, 2011 10:20 am

Please be positive and constructive with your questions and comments.