ESP32 serial2 does not send anything

I have an ESP32 DOIT DEV V1 3.3v:

And I have an SMS hat - 3.3v:


I can confirm that the SMS hat can send and receive AT commands through serial correctly. As discussed here.

I would like to use both hardware serial ports on the ESP32 to debug and talk to the hat at the same time. Serial1 for USB debug, and Serial2 for the SMS hat.

This is the test code I'm using:

#include <HardwareSerial.h>

void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
}

void loop() {
  if (Serial2.available() > 0) {
    Serial.write(Serial2.read());
  }
  if (Serial.available() > 0) {
    Serial2.write(Serial.read());
  }
}

*Unplugged for photo. TX -> TX and RX -> RX is how it's meant to be. Please see here.

esptool.py:

Detecting chip type... ESP32
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: 30:ae:a4:f4:d0:b8
Uploading stub...
Running stub...
Stub running...
Manufacturer: 20
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...

I can receive input through serial, But I can't send anything to the HAT.

Why isn't serial 2 TX working?

Can you try connecting the Tx pin of the ESP32, to the Rx pin of your USB/TTL adapter (and GND to GND), and run the following.

#include <HardwareSerial.h>

void setup()
{
  Serial2.begin(115200, SERIAL_8N1, 16, 17);
}


void loop()
{
  Serial2.println(millis());
  delay(2000);
}

Would be good to understand which side of the ESP32-SIM67600 communication is not working.

OK... I did a bit of playing with an ESP32, and my SIM7600 (the one that works ok).

I used your code and got nothing returned. After a bit of digging I believe the issue is with the way you are declaring the 2nd serial port. Try this version...

#include <HardwareSerial.h>

HardwareSerial SerialPort2 (2);   // This is the key line missing.

void setup()
{
  Serial.begin(115200);
  SerialPort2.begin(115200, SERIAL_8N1, 16, 17);
}

void loop()
{
  while (Serial.available() > 0)
    SerialPort2.write(Serial.read());
    
  while (SerialPort2.available() > 0)
    Serial.write(SerialPort2.read());
}

Interestingly, if I called it "Serial2" instead of "SerialPort2" it fails to compile.

It’s because it’s already there line 108

Noted. Where does this get set?

In here for example

I suppose it depends on your board that one is for esp32s3

Here it is for the standard ESP32

I'm using an ESP32-WROOM-32U... closest board I could find is ESP32-WROOM-DA Module.

However, although Serial2 seems to be defined (and when I print SOC_UART_NUM = 3), the serial port does not work. It only works if I define with a different name ?

What pins did you use ?

In your picture you have TX to TX and RX to RX it should be TX to RX and RX to TX

16 (Rx), 17 (Tx).

No it shouldn't. The pin labels on the HAT refer to the Raspberry Pi, not the SIM7600.

1 Like

OK my bad, thanks for the correction

Sounds right
Did you try with any example?

So the P-TX to RX-3.3v and P-RX to TX-3.3v works with Arduino (5v) but not ESP32 (3.3v) so the UART header is probably right what about the UART voltage selection is that set to 3.3v (default). Can you adjust the UART header and get a response sending AT commands over USB just to take any external module out of the equation.

Edit : the tx rx connections I refer to are the ones at the uart header.

I can't communicate over a 5 volt USB TTL adaptor (RX TX header) to the hat, But I can send AT commands through the Arduino UNO (RX TX header) to the hat, and the Shield's built-in USB port.

Works as expected here:

Output from USB:

37
2038
4037
6037
8037

No Luck from this one. I can't send anything to the HAT, and the USB UART adaptor doesn't work with this either. for some reason

Which doesn't make much sense if I could receive from the last script. But when I boot my 3rd party serial monitor for the USB the TX light gets stuck on. If i disconnect and plug back it it turns off

Ok so can you just confirm what works and what doesn't...

  1. Uno hardware with blank sketch (effectively sending to/from commands from the IDE serial monitor)?
  2. Uno Software serial? Using pass-through sketch?
  3. ESP32 using pass-though sketch ? (using port 0 monitor, and port 2 for SIM7600). You get boot messages but can't send commands?
  4. USB/TTL adapter and your 3rd party monitor doesn't work?

PS. My ESP32 is now working fine using Serial2... don't need to rename as per post #3... but at the time it definitely wasn't so not sure what changed... I should have been more methodical when playing around.

I went back and re-did all of these tests to be sure

:green_square: :yellow_square:

  • 115200 baud
  • UNO can send and relieve data from SMS hat.
  • UNO can't receive data from TX2 on ESP32, but can send data to RX2
    • This is wired TX UNO -> TX2 ESP32 & RX UNO RX2 ESP32

:green_square: :yellow_square:

  • 9600 baud for software serial
  • UNO can talk to the SMS hat perfectly fine
  • UNO can send to the ESP32 Serial2 fine, but cannot receive from it

:yellow_square:

  • 115200 baud
  • Correct, I get the boot and can't send messages
  • The use of HardwareSerial SerialPort2 (2); didn't make a difference. I had trouble getting it to work at all a min ago, so I deleted it and used the code below. Which gets the boot message at least.
#include <HardwareSerial.h>


void setup()
{
  Serial.begin(115200);
  Serial2.begin(115200, SERIAL_8N1, 16, 17);
}

void loop()
{
  while (Serial.available() > 0)
    Serial2.write(Serial.read());
    
  while (Serial2.available() > 0)
    Serial.write(Serial2.read());
}

:red_square:

  • Correct. I can't talk to the hat at all. As soon as I connect on the serial monitor, the TX light on the USB turns solid red even through I'm not sending anything. When resetting the SMS hat, the RX light flashes once for some reason.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.