Arduino sitting between a source and a printer via RS232 connection

Hi all,

I currently have a source (i.e. a POS system) connected to a ESC/P2 thermal printer via an RS232 serial connection. I wanted to place an arduino uno between the source and the thermal printer. Its main objective is to monitor what is sent to the printer and based on a condition (i.e. a flag, a certain string in the data, etc), it determines whether a print is required. I have a MAX232/RS232 DB9 shield to adjust the voltages, but i'm not sure if my source will be able to see my arduino as a printer and thus even allow a print job to occur.

The source is compatible with all ESC/P2 thermal printers.

EDIT: My questions are:

  1. How do i configure my arduino to allow the source to print to it?
  2. Can I hook up two RS232 connections to the arduino (one for input and the other for output)?

Welcome on the forum,

And the question is?

answer: (guessing the question)

  1. yes this is possible
  2. don't know

robtillaart:
Welcome on the forum,

And the question is?

answer: (guessing the question)

  1. yes this is possible
  2. don't know

Haha thank you! I completely missed that :stuck_out_tongue:

I edited the original post to reflect the question.

You can pass any data that comes in from the POS directly to the printer and any data that comes from the printer directly through to the POS using a very simple piece of code in the Arduino. That way neither the POS nor the printer will realise that they are not connected directly.

You can use e.g. an Uno with one hardware serial port and use a software serial port to connect to the two devices.
There are also Arduinos with 2 or more hardware serial ports which may be preferred if timing is critical.

The below code is basically the Software Serial Example and passes any data from POS to printer and from printer to POS; 9600 baud, 8N1. You can read the documentation (Software Serial and Hardware Serial) if you need to change it.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  
}

void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

You may find it easier to do what you want with an Arduino with a second Hardware Serial Port - for example a Mega or a Leonardo or Micro.

The Mega would probably be best because it could receive the data on (say) Serial1 and send it out again on Serial2 while leaving Serial available for communication with your PC while you develop the program.

With an Uno you will need to receive the data with HardwareSerial and send it out again with SoftwareSerial.

I am assuming you want a system where the Arduino can affect what is printed rather than simply monitor it.

You will need code in the Arduino to receive the data and the examples in Serial Input Basics should get you started.

...R

Also check this thread, contains a printer module