Passing AT commands from ESP32 to GSM via UART2

Hi all,

I am trying to interface a GSM module to ESP32 ( using ESP32-WROOM-32), for which libraries are not available, As ESP32 have 3 UARTs, i have connected my RX and TX of my module to esp32 TX2 and RX2 (17,18). I am trying to pass a 'AT' cmnd via serial communication to the GSM and read the response from the GSM as 'OK' and print in Serial monitor. There were few tutorials which speaks about using the HardwareSerial.h, Serial.Begin2(115200) etc. But i am not able to acheive my Goal. If any experts have any idea, please do post your thoughts here.. Here is my code

 #include <HardwareSerial.h>
 
 #define RXD2 16
 #define TXD2 17
 void setup() {
   Serial.begin(115200);
   Serial2.begin(115200)
   delay(1000);
   Serial.println("Loopback program started");
   delay(5000);
 }
 void loop() {
   //if(Serial.available()){
     Serial2.write("AT");
     //Serial2.write(Serial.read());  
   //}
   if(Serial2.available()){
     //Serial.write(".");
     Serial.println(Serial2.read());  
   }
   delay(6000);
 }

Welcome

Try print instead of write

Also remove delay(6000); but don't spam Serial2.print("AT");, only send when necessary

Edit: and more importantly you didn't initialize Serial2 correctly
Serial2.begin( 115200, SERIAL_8N1, RXD2, TXD2 );

@bala_s , your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

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