I am using an ESP32 (DOIT DevKit V1) and attempting to interface with a SIM7600 over UART.
For some reason, I am not getting responses from the modem on basic "AT\r" commands but if I restart the modem, I get the usual "Ready/Everything is fine" message it sends (I'll show what I mean in the response text)...
I am using VSCode's PlatformIO to write this, not the Arduino IDE if that makes a difference. My pin connections are as follows:
ESP PIN 16 (RX2) -> SIM7600 PIN TXD
ESP PIN 17 (TX2) -> SIM7600 PIN RXD
ESP PIN GND -> SIM7600 PIN GND
Here is my code:
#include <Arduino.h>
char replyBuffer[512];
unsigned long currentMillis;
unsigned long start = 0;
#define TXD_PIN 17
#define RXD_PIN 16
int i = 0;
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
}
void test(String testCommand) {
replyBuffer[0] = '\0';
currentMillis = millis();
if (currentMillis - start > 2000)
{
start = currentMillis;
Serial2.println(testCommand);
}
int idx = 0;
unsigned long timer = millis();
while (millis() - timer < 3000) {
if (Serial2.available()) {
replyBuffer[idx++] = Serial2.read();
}
}
replyBuffer[idx] = '\0';
Serial.println(replyBuffer);
}
void loop() {
test("AT\r");
Serial.println(i++);
delay(1000);
}
Notice the successful modem response due to it completing its checks between 8 and 9 but there isn't any "Ok" or "ERROR" anywhere else as I would expect...
I have never been able to get this code to work on an ESP32 but have seen success on an Arduino Uno variant.
try pulling the PWRKEY pin down to ground - it should RESET the module
I use this for testing a SIM900 - note I use Serial1 on pins 15 and 16
// ESP32 Serial1 test
// for loopback test connect pins 16 and 15
// connect SIM900 TX to ESP32 pin 16 SIM900 RX to ESP32 pin 15
// AT+CGMI returns the manufacturer's name
// AT+CGMM returns the MODEM model number
// AT+CGMR returns details of the software and model revision level
// AT+CGSN returns the MODEM's serial number
#define RXD1 16
#define TXD1 15
void setup() {
// initialize both serial ports:
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, RXD1, TXD1);
Serial.println();
Serial.println("ESP32/ SIM900 serial1 test Rx pin 16 Tx pin 15");
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
//Serial.write(inByte);
Serial1.write(inByte);
}
}
text entered on the Serial Monitor (e.g. AT+CGMM) is transmitted over Serial1 and any response displayed (I have the Serial Monitor line terminator set to Both NL and CR)
e.g. a run gives
RDY
+CPIN: NOT INSERTED
+CFUN: 1
AT
OK
AT+CGMI
SIMCOM_Ltd
OK
AT+CGMM
SIMCOM_SIM900
OK
AT+CGMR
Revision:1137B06SIM900M64_ST_ENHANCE
OK
Edit: looking at the output of post 1 it looks like the SIM7600 is autobauding, i.e. using the sequence of AT AT AT AT to work out the baudrate so it appears to be receiving characters
once it has the baudrate it should respond to AT with OK
Yes, I am expecting an OK response to this command. I do receive this response when I use PuTTy or if I load a program on my Arduino Uno...Which makes no sense...
how did you connect PuTTy and the UNO to the SIM7600?
what particular SIM7600 module are you using?
the UNO uses 5V logic I would have though the SIM7600 uses 3.3V but it is worth checking
did you use a level converter or potential divicer between the UNO and SIM7600?
the ESP32 uses 3.3V logic so should work if the SIM7600 is 3.3V logic
how did you connect the ESP32 to the SIM7600?
Sorry I was never notified of your response...
I connected the SIM to PuTTy using the usb to UART plug in.
When connected to the UNO, I have the SIM powered separately on the USB (not the usb to UART one) plug in to a 5V block, and the UNO is plugged into my computer to monitor serial outputs. The only thing that was connected to both of them was the RX/TX/GND.
I'm using the SIM7600G-H.
As for the ESP to SIM connection, it is the same as the UNO - SIM gets a 5V input to USB plug, ESP going to my computer on the usb, and the SIM to ESP connection is just RX/TX/GND. Are you proposing something different??
i had come across the same issue and searched in all the links leading to esp32 and sim7600 i did not get any answers. however i used sim7672 development board by valetron which had DTR and RI pinouts which i connected to other two gpios of esp32 which is 18 and 19 that did the trick to solve the issue. i have used a total of 5pins of sim7672 tx,rx,dtr,ri,gnd now both side communication is possible try it out. i will put my code which sends two AT commands with a delay.
#include <HardwareSerial.h>
// Define the serial port used to communicate with the SIM7672S module
HardwareSerial simSerial(2);
// Define the DTR and RI pins used for hardware flow control
const int dtrPin = 18;
const int riPin = 19;
void setup() {
// Start the serial ports at the appropriate baud rates
Serial.begin(115200);
simSerial.begin(115200, SERIAL_8N1, 16, 17);
// Set the DTR and RI pins as outputs and initialize them to HIGH
pinMode(dtrPin, OUTPUT);
digitalWrite(dtrPin, HIGH);
pinMode(riPin, OUTPUT);
digitalWrite(riPin, HIGH);
// Wait for the serial ports to initialize
delay(1000);
// Print a message to the Arduino IDE Serial Monitor to indicate that the program is ready
Serial.println("AT command program ready");
}
void loop() {
// Send an AT command to the SIM7672S module and print the response
simSerial.println("AT");
delay(1000);
printResponse();
// Send a second AT command to the SIM7672S module and print the response
simSerial.println("AT+CSQ");
delay(1000);
printResponse();
}
void printResponse() {
// Set the DTR pin LOW to signal the SIM7672S module to start sending data
digitalWrite(dtrPin, LOW);
// Read any available data from the serial port and write it to the Arduino IDE Serial Monitor
while (simSerial.available()) {
Serial.write(simSerial.read());
}
// Set the RI pin HIGH to signal the SIM7672S module that the data has been received
digitalWrite(riPin, HIGH);
}