MAX232 RX Problem

Hello,

I Would like to use a thermal printer with my Arduino mega using a MAX232 IC, attached my schematic circuit.
I can print normally, Here is my sketch :

#include <SoftwareSerial.h>
#include <Console.h>

// ASCII codes used by some of the printer config commands:
#define ASCII_TAB '\t' // Horizontal tab
#define ASCII_LF  '\n' // Line feed
#define ASCII_FF  '\f' // Form feed
#define ASCII_CR  '\r' // Carriage return
#define ASCII_DLE  16  // Data Link Escape
#define ASCII_EOT  4  // End Of Transmission
#define ASCII_DC2  18  // Device Control 2
#define ASCII_ESC  27  // Escape
#define ASCII_FS   28  // Field separator
#define ASCII_GS   29  // Group separator

#define rxPin 8
#define txPin 9

SoftwareSerial Thermal(rxPin, txPin);

void setup()
{
 pinMode(txPin, OUTPUT);
 pinMode(rxPin, INPUT);
 
   Thermal.begin(115200);
  // initialize serial communication:
  Bridge.begin();
  Console.begin();
}

void loop()                     // run over and over again
{
  
//Thermal.getPaperStatus();   // get the current status of the Thermal printer
Thermal.write(ASCII_DLE);
Thermal.write(ASCII_EOT);
Thermal.write(21);
while (Thermal.available())
{
Console.println(Thermal.read(), HEX);
}
delay(1000);                  // waits for a second

if (Console.available() > 0) {
 char c = Console.read(); 
 Console.println(c);
 if (c == '\n') {
              
                Thermal.println("Hello World!");
                Thermal.write(ASCII_FS);
                Thermal.write(0xC0);
                Thermal.write(0x34); //cut&feed
                }
}


}

here is the user manual:
TG2460H

and the commands manual:
TG2460H commands manual

The problem is I can't read data from the printer although the RX Led blinks.

I tested the printer with a windows application and I could read data normally.

I do not know where is the problem, thank you for your help.

kiman26:
Hello,

I Would like to use a thermal printer with my Arduino mega using a MAX232 IC, attached my schematic circuit.
I can print normally, Here is my sketch :

#include <SoftwareSerial.h>

#include <Console.h>

// ASCII codes used by some of the printer config commands:
#define ASCII_TAB '\t' // Horizontal tab
#define ASCII_LF  '\n' // Line feed
#define ASCII_FF  '\f' // Form feed
#define ASCII_CR  '\r' // Carriage return
#define ASCII_DLE  16  // Data Link Escape
#define ASCII_EOT  4  // End Of Transmission
#define ASCII_DC2  18  // Device Control 2
#define ASCII_ESC  27  // Escape
#define ASCII_FS   28  // Field separator
#define ASCII_GS   29  // Group separator

#define rxPin 8
#define txPin 9

SoftwareSerial Thermal(rxPin, txPin);

void setup()
{
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);

Thermal.begin(115200);
 // initialize serial communication:
 Bridge.begin();
 Console.begin();
}

void loop()                     // run over and over again
{
 
//Thermal.getPaperStatus();   // get the current status of the Thermal printer
Thermal.write(ASCII_DLE);
Thermal.write(ASCII_EOT);
Thermal.write(21);
while (Thermal.available())
{
Console.println(Thermal.read(), HEX);
}
delay(1000);                  // waits for a second

if (Console.available() > 0) {
char c = Console.read();
Console.println(c);
if (c == '\n') {
             
               Thermal.println("Hello World!");
               Thermal.write(ASCII_FS);
               Thermal.write(0xC0);
               Thermal.write(0x34); //cut&feed
               }
}

}




here is the user manual:
[TG2460H](http://www.custom.biz/scarica/2/scarica.php?file=560-762000000014_2.50.pdf)


and the commands manual:
[TG2460H commands manual](http://forum.arduino.cc/index.php?action=dlattach;topic=405348.0;attach=169850)


The problem is I can't read data from the printer although the RX Led blinks.

I tested the printer with a windows application and I could read data normally.

I do not know where is the problem, thank you for your help.

Which actual Arduino board are you using? YUN?

If you are actually using a MEGA just connect the MAX232 to SERIAL1 (rx->19,tx->18)

Your adapter wiring looks possible, but How have your wired the RS232 to the printer,
and how is JP1 connected to your MEGA?

And, you need to read the limitations of Software Serial:

Limitations

The library has the following known limitations:

    If using multiple software serial ports, only one can receive data at a time.
    Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
    Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
    On Arduino or Genuino 101 the current maximum RX speed is 57600bps
    On Arduino or Genuino 101 RX doesn't work on Pin 13 

If your project requires simultaneous data flows, see Paul Stoffregen's AltSoftSerial library. AltSoftSerial overcomes a number of other issues with the core SoftwareSerial, but has it's own limitations. Refer to the AltSoftSerial site for more information.

If you are actually using the MEGA, your RX on pin 8 is your failure point.

Chuck.

Thank you very much chuck it's working with pin 11 & 12, but no with 18 & 19 ? :frowning:

I use a Dragino yun shield with an arduino mega, normally it's contain 3 hardware uart port, I can not use their RX port at the same time is that right?

meantime I reading about AltSoftSerial.

Thank you

kiman26:
Thank you very much chuck it's working with pin 11 & 12, but no with 18 & 19 ? :frowning:

I use a Dragino yun shield with an arduino mega, normally it's contain 3 hardware uart port, I can not use their RX port at the same time is that right?

meantime I reading about AltSoftSerial.

Thank you

I just looked at the Dragino Yun shied users manual, It only uses Serial(), So, Serial1(),Serial2(),Serial3() should be available.

Don't use Software Serial, Just Substitute Serial1() everywhere you have Thermal().

Serial1.begin(115200);

Serial1.write();
Serial1.read();
Serial1.available();

Chuck.

Thank you very much chuck it's solved !