Printing from a Thermal Printer with Arduino

Hi community,

I am new to Arduino so I apologise if I’m making some rookie errors.

I have been following this youtube tutorial (see: How to connect a thermal printer to the Arduino | Small Project - YouTube) on printing from a 2nd hand thermal printer with Arduino.

I am using a TSC tdp-225 printer that works perfectly well when plugged in via USB to my laptop. It prints like a regular printer.

For my project, I want to connect it to my Arduino UNO (and eventually my ESP32 Fire Beetle) and print using Arduino commands. But, so far, I have been having difficulty.

Firstly, please see my circuit diagram. I am connecting the printer’s serial port via a D9 male to male adapter and RS232 Serial Converter. This is then connected to the Arduino UNO. All up, it is a pretty straightforward circuit.

The code I am using has been directly copy and pasted from the video. I can link this if you would like. In my opinion, a lot of the commands are superfluous at this stage. Something as simple as this (see below) should instruct the printer to print “Test”:

void setup() {
  Serial.begin(9600);
  Serial.println("Test");
}

void loop() {
}

I believe data is being transferred to the rs232 converter as its TX LED flashes whenever I press the reset button on the UNO. But, after that, nothing happens.

I have found this document (see: https://fs.tscprinters.com/system/files/31-0000001-00_tspl_tspl2_programming.pdf) which outlines the TSC programming language. I have tried using some of these commands (e.g. Serial.println(“SELFTEST”)) but also have had no luck. It simply won’t print.

I am pretty close to calling it quits and buying the Thermal Printer from the store here. I bet it’ll be a lot easier to work with.

Any help would be much appreciated!

Regards,

Liam

Can you connect the printer to the PC using USB and configure it with the manufacturer’s configuration utility? You should also use that utility to confirm that the machine is printing properly.

Serial communication will not be enabled by default - you will need to select it in the configuration. You will probably also have to set the serial baud rate (9600 for your code) and handshaking (none). Then you need to double check the TX and RX wiring - you can’t rely on the labelling because manufacturers use the terms differently. It is unlikely that a simple ‘println(“Text”);’ will work as the printer will need to be initialised with some setup commands, but the SELFTEST command you mention should give you a result that will confirm it is communicating OK.

I assume that you are disconnecting the PC to run the test - you can’t use UART0 (pins 0, 1) at the same time as USB. You may be better off connecting using Software Serial and some other pins, so that UART0 is available for communication with the PC. You can write a simple ‘serial pass thru’ sketch to test the printer direct from the PC.

2 Likes

Hi @Jeff105671, thanks for getting back to me!

  1. I have configured the printer via USB with the TSC console software. I printed a ”configuration page” which worked fine. Here, under RS232 Settings, it spat out the following: BAUD: 9600, PARITY: NONE, DATA BIT: 8, STOP BIT: 1, which is equivalent to the values in the video. I did not have to change these values, but I can in the console. I also opened something called the “CommTool” which basically let me communicate with printer with the TSC programming language. I entered “SELFTEST”, sent the command, and it printed the configuration page again. I could not find anything about handshaking.

  2. I have also updated the code and changed the serial pins as you suggested. Again, no luck printing.

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

// Set up a new SoftwareSerial object
SoftwareSerial mySerial (rxPin, txPin);

void setup()  {  
    // Set the baud rate for the SoftwareSerial object
    mySerial.begin(9600);
    // Print data to the transmit pin
    mySerial.println("SELFTEST");
}

void loop() {
}

I don’t have a way to connect the printer’s serial port directly to a PC (via USB or otherwise), but I suppose it could be worth trying, just to test if that port is working?

If you have any other tips, it would be greatly appreciated!

Liam

1 Like

If handshaking wasn’t mentioned in the configuration for the serial port then you can ignore it. The setting of 8, None, 1 matches the Arduino default.

The examples in the Arduino IDE includes a MultiSerial sketch in the communications tab that shows how to create a ‘pass-thru’ application that will make debugging from the console much easier.

So it gets down to your original point - the issue is almost certainly in the actual serial link. The usual way to handle this would be with a RS232 breakout. You can do the same thing with a logic analyzer.

Failing that sort of equipment, you can simply try each possible combination of Tx and Rx to see whether you have them the right way around.

1 Like

Hi Liam, welcome to the forum!

This is what I’d recommend too, just to make sure every link in the chain is working as expected:

As Jeff mentioned, some manufacturers flip the TX and RX lines (i.e. they are from the perspective of the host device rather than the slave), two TX lines driving “into” each other can actually kill one or both of them, so perhaps test that each part works in isolation first to confirm.

I’m not sure about control signals, could you share more info on your RS232 converter, maybe just a link to where you got it from?

1 Like

Hi @James & Jeff105671,

Thanks for your support and warm welcome.

I got the RS232 converter from the Core Electronics store: RS232 to Serial Converter | Core Electronics Australia

As suggested, I had a go at the “serial pass thru”.

I set up my arduino, rs232 converter, and d9 as stipulated. I used this diagram to connect the TX pin (3) on the d9 adapter to the RX pin (2) also on the adapter.

RS232-9-pin-pinout-explained

This was the code I gave my Arduino.

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial mySerial (rxPin, txPin);

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

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

  if (Serial.available()) {
    int inByte = Serial.read();
    mySerial.write(inByte);
  }
}

These were my results:

-When I had the RX pins to the TX pins: the TX LED flashed on the RS232 converter when sending commands via the Serial Monitor. Nothing was returned.
-When I swapped the cables and had the RX pin to the RX and the TX to the TX: the RX LED flashed on the RS232 converter when sending commands via the Serial Monitor. Again, nothing was returned.

-I adjusted the code and defined the RX and TX pins as 0 and 1 respectively. I then connected the RX pin on the RS232 converter to the 0 on the UNO, and the TX pin on the RS232 to 1 on the UNO. Both the RX and TX LEDs flashed on the converter when sending data. Interestingly, on this occasion, data was returned, but in a jumbled state. E.g. “test” returned “t�)”, and “hello” returned “hؽ)”.

-Swapping the cables (so TX ran to RX) returned nothing. This time no LED flashed on the RS232.

As I said, I’m pretty new to this so I’m not sure what I should do with this information.

Unfortunately, I don’t have a RS232 breakout or a logic analyzer.

Maybe this makes sense to one of you?

Liam

Note: changing the baud rates in the code result in different return values for when I have the TX and TX pins as 0 and 1.

I wonder if there is a baud rate that returns the text as it was sent? and that making the printer’s baud rate this value will allow me to communicate with it?

Okay, ignore the results from above. I incorrectly hooked up the D9 serial adapter. Didn’t have the pins connected.

Now hooking up the RX and TX pins on the RS232 converter to the 0 and 1 pins on the UNO cause no LED flash on the RS232 converter and no return in the Serial Monitor.

I can get a dual flash on the RX and TX LEDs on the RS232 converter when I have the RX to pin 2 and TX to pin 3 on the UNO. But, sadly, no data is returned to the Serial Monitor.

Pins 0 and 1 on the Arduino are used for the USB communication to the console. Defining them for software serial will not work, so the results you got doesn’t tell you anything useful. The response you got was the result of trying to use the same pins for two purposes - the data stream got mixed.

The actual baud rate you use doesn’t matter - for this test all that matters is that both the UART serial and software serial use the same baud rate. As you have already configured the printer for 9600 baud you may as well leave everything at 9600bd.

I will dig out some old RS232 devices and see if I can set up a configuration to match yours and find out what is happening. Do you have any LEDs available that you could use as a test indicator?

In the meantime you should look for other resellers with that same converter who may have published more detail about the device (Google image match is an effective way to search). Depending on how it is wired to the MAX3232 you might need to drive some of the control signals such as DSR or CTS.

What information do you have about the signal levels for the printer interface? If it’s TTL logic levels rather than genuine RS232 then you don’t need the converter, and that would make things a lot simpler.

Okay, thanks for clarifying.

Yes, I do have LEDS that I can use for testing purposes.

I did read a bit online about the MAX3232 which seems more complicated than the RS232 model I have (mine has no DSR or CTS pins). Starting to think I need a different converter.

In regards to your last question (signal levels for the printer interface… TTL vs RS232), I’m afraid I’m wading into an space that I don’t have the best technical understanding of. If I had to make a guess, I would say it is genuine RS232. Is there a way to work this out?

Once again, thanks for your help! It’s been great having someone here to troubleshoot with.

Liam

The MAX3232 is a bit more complex than you need, but AFAICT from documentation for modules that appear to be the same none of that extra complexity is used in your device. So a simple loopback should work.

The signal path should be:
Console input to MCU via USB is received by a Serial.read()
mySerial.write() sends the byte to pin txPin (3 in your example)
MCU txPin (Pin 3) is connected to Converter Header RXD
Converter Header RXD is connected to MAX3232 pin 11 (T1IN/DIN1)
MAX3232 pin 11 (T1IN/DIN1) is connected to pin 14 (TXD/DOUT)
MAX3232 pin 14 (TXD/DOUT) is connected to Converter DB9 (Female) pin 2 Tx
Converter DB9 (Female) pin 2 Tx is connected to Printer DB9 (Male) pin 2 Rx

You can test loopback at the connection of MCU to converter, converter to printer cable and printer cable to printer.

That last connection I don’t have details for - I assume you are using a straight-through M/F cable to connect the adapter to the printer. If you can get the loopback to work by connecting 2 and 3 at the converter pins, plug in the printer cable and do the same thing at the end of that cable. But that won’t tell you whether or not pins 2 and 3 are getting swapped inside the cable. For that you would need a breakout box. I would not expect them to be swapped, but it is possible. If you can get a loopback at the end of that cable to work then there’s not much other possibility.

The other uncertainty is the labelling of TX and RX on the converter module. If you can trace the path from the headers to the MAX3232 then you could confirm you are connecting to MAX pin 11.

One change you might like to consider is using a number of different commands to test the printer. The documentation is not clear, but some commands might involve sending some acknowledgement or response back to the MCU, and if that process gets hung up for some reason it could look like the command was never received.

2 Likes