Connecting a printer to an Arduino?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm

Re: Connecting a printer to an Arduino?

Post by copiertalk »

I bet I can work something up to show functionality. :D

copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm

Re: Connecting a printer to an Arduino?

Post by copiertalk »

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

Code: Select all


#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

Re: Connecting a printer to an Arduino?

Post by copiertalk »

This is probably too big but oh well.

Image

:D

I can resize it later if need be.

User avatar
uberhund
 
Posts: 154
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

Post by uberhund »

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.

copiertalk
 
Posts: 6
Joined: Sat Aug 21, 2010 1:58 pm

Re: Connecting a printer to an Arduino?

Post by copiertalk »

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.

Naili
 
Posts: 1
Joined: Tue Sep 21, 2010 8:35 am

Re: Connecting a printer to an Arduino?

Post by Naili »

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

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

Re: Connecting a printer to an Arduino?

Post by short »

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

#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

User avatar
uberhund
 
Posts: 154
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

Post by uberhund »

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

#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);
}

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

Re: Connecting a printer to an Arduino?

Post by short »

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

User avatar
uberhund
 
Posts: 154
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

Post by uberhund »

I'm using the identical settings, Short. Wish I could be of more help.

User avatar
richms
 
Posts: 558
Joined: Tue Jan 20, 2009 3:05 am

Re: Connecting a printer to an Arduino?

Post by richms »

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.

User avatar
uberhund
 
Posts: 154
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

Post by uberhund »

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.

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

Re: Connecting a printer to an Arduino?

Post by short »

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

User avatar
uberhund
 
Posts: 154
Joined: Tue Dec 02, 2008 4:06 pm

Re: Connecting a printer to an Arduino?

Post by uberhund »

Yes, my "cable" is based on the traditional 3-wire solution as well:

CuteDigi Pin..........Epson Pin.........(color as shown in photos)
2..............................3.......................Yellow
3..............................4.......................Green
5..............................1.......................Red

Not shown is a common ground shared through the power supply.
Attachments
RS232 EpsonSide.jpg
RS232 EpsonSide.jpg (63.71 KiB) Viewed 2216 times
RS232 CuteDigiSide.jpg
RS232 CuteDigiSide.jpg (83.37 KiB) Viewed 2216 times
Last edited by uberhund on Mon Sep 05, 2011 8:41 am, edited 1 time in total.

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

Re: Connecting a printer to an Arduino?

Post by short »

uberhund, thanks a lot for all your help! It now all works quite fine :D


Cheers,

short

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”