Hello everyone,
I’m trying to get my ESP32-S3 working with a Waveshare A7670E-4G module, but I can’t get it to respond correctly over UART using Arduino. I’m quite new to Arduino, so please bear with me. I’ve done several tests and I’m a bit stuck. I’m hoping for advice or tips from anyone who has experience with this module.
Hardware:
ESP32-S3
A7670E-4G module (U8 version)
Pins connected for UART1:
MAIN_TXD → GPIO43
MAIN_RXD → GPIO44
Power: 5V 3A stable supply
Module control pins:
POWER_ON
RESET
PWRKEY
Current setup:
USB DIP switch: OFF
4G DIP switch: ON
I’ve tried with USB ON as well.
Software / tools:
Arduino IDE with HardwareSerial (UART1)
Tested AT commands using Tera Term → module responds correctly over USB.
What I’ve tried:
Power on the module with PWRKEY sequence and delays (15s boot wait).
Send basic AT command "AT" → sometimes nothing, even after boot.
Check SIM: AT+CPIN? → shows READY in Tera Term, but not over ESP32 UART.
Check signal: AT+CSQ → works in Tera Term.
Network registration: AT+CREG?, AT+CGREG?, AT+CEREG? → OK in Tera Term.
PDP context: AT+CGDCONT=1,"IP","free" → works in Tera Term.
MQTT sequence using AT commands (CMQTTSTART, CMQTTACCQ, CMQTTCONNECT…) → nothing happens over ESP32 UART.
Differences between my working Tera Term setup and Arduino code:
Pins: UART1 GPIO43/44 vs USB TTL
USB ON vs OFF → module only powered via external 5V + PWRKEY
Delays after commands (Arduino may be too short)
Problem:
With USB OFF and 4G ON, the module does not respond to AT commands from ESP32-S3 at all, although it works fine in Tera Term over USB. I suspect it’s something related to power-on sequence, PWRKEY, or UART timing.
Request:
I’m quite new to Arduino, so I would really appreciate step-by-step guidance. Does anyone have a working Arduino example for ESP32-S3 + A7670E-4G with USB OFF and 4G ON? Or tips on correct pins, power sequence, and timing to get AT commands working over UART?
Thanks in advance for any advice!
Code: Select all
#include <Arduino.h>
#include <HardwareSerial.h>
HardwareSerial simSerial(1); // UART1
#define SIM_RX 43
#define SIM_TX 44
String APN = "free";
String BROKER = "IP";
int PORT = 1883;
String TOPIC = "test/esp32";
// -------------------- Fonctions AT --------------------
String sendAT(String cmd, unsigned long timeout = 2000) {
simSerial.println(cmd);
unsigned long start = millis();
String response = "";
while (millis() - start < timeout) {
while (simSerial.available()) {
char c = simSerial.read();
response += c;
}
}
Serial.println("AT Response: " + response);
return response;
}
// Boucle pour attendre "OK"
bool waitForATReady(int retries = 10) {
for (int i = 0; i < retries; i++) {
String resp = sendAT("AT");
if (resp.indexOf("OK") != -1) return true;
delay(1000);
}
return false;
}
// -------------------- Vérifications --------------------
bool checkSIM() {
String resp = sendAT("AT+CPIN?");
if (resp.indexOf("READY") != -1) {
Serial.println("SIM OK");
return true;
}
Serial.println("SIM not ready");
return false;
}
bool checkSignal() {
String resp = sendAT("AT+CSQ");
int rssiIndex = resp.indexOf("+CSQ:");
if (rssiIndex != -1) {
int rssi = resp.substring(rssiIndex + 6).toInt();
Serial.println("RSSI = " + String(rssi));
if (rssi == 99) return false;
return true;
}
return false;
}
bool checkNetwork() {
String cs = sendAT("AT+CREG?");
String ps1 = sendAT("AT+CGREG?");
String ps2 = sendAT("AT+CEREG?");
if (cs.indexOf(",1") != -1 || ps1.indexOf(",1") != -1 || ps2.indexOf(",1") != -1) {
Serial.println("Network registered");
return true;
}
return false;
}
bool checkService() {
String resp = sendAT("AT+CPSI?");
if (resp.indexOf("NO SERVICE") != -1) {
Serial.println("No network service");
return false;
}
return true;
}
// -------------------- PDP Context --------------------
bool setupPDP() {
sendAT("AT+CGDCONT=1,\"IP\",\"" + APN + "\"");
sendAT("AT+CGACT=1,1");
String resp = sendAT("AT+CGACT?");
if (resp.indexOf("1,1") != -1) {
Serial.println("PDP active, IP assigned");
return true;
}
return false;
}
// -------------------- MQTT --------------------
bool mqttPublish(String topic, String payload) {
sendAT("AT+CMQTTSTART"); // activer MQTT
delay(2000);
sendAT("AT+CMQTTACCQ=0,\"ESP32-S3\",0"); // config client
delay(2000);
sendAT("AT+CMQTTCONNECT=0,\"tcp://" + BROKER + ":" + String(PORT) + "\",60,1"); // connect broker
delay(10000);
// Préparer topic
simSerial.printf("AT+CMQTTTOPIC=0,%d\r\n", topic.length());
delay(500);
simSerial.println(topic);
delay(500);
// Préparer payload
simSerial.printf("AT+CMQTTPAYLOAD=0,%d\r\n", payload.length());
delay(500);
simSerial.println(payload);
delay(500);
// Publier message
sendAT("AT+CMQTTPUB=0,1,60");
delay(3000);
Serial.println("Published: " + payload);
return true;
}
// -------------------- Setup --------------------
void setup() {
Serial.begin(115200);
simSerial.begin(115200, SERIAL_8N1, SIM_RX, SIM_TX);
Serial.println("\n=== ESP32-S3 + A7670E MQTT ===");
if (!waitForATReady()) {
Serial.println("Module not responding to AT commands. Halting.");
while(1);
}
while (!checkSIM()) delay(2000);
while (!checkSignal()) delay(2000);
while (!checkNetwork()) delay(2000);
while (!checkService()) delay(2000);
while (!setupPDP()) delay(2000);
Serial.println("\nModule ready, publishing first message in 5s...");
delay(5000);
mqttPublish(TOPIC, "Hello!");
}
// -------------------- Loop --------------------
void loop() {
static uint32_t last = 0;
if (millis() - last < 10000) return;
last = millis();
int r = random(1,101);
String payload = String(r);
mqttPublish(TOPIC, payload);
}