Hello everyone!
I'm having some issues trying to send AT commands from my ESP32 to an A7670SA module. I have set up my connection with the module, but when sending the AT commands, I do not receive responses, and sometimes, the module.
Here is my setup:
- The A7670SA module is powered by a 3.7V 1800mAh battery.
- My ESP32 is connected to my PC.
- The connections are as follows: A7670SA's TX, RX, and GND are connected to ESP32's TX, RX, and GND respectively.
I have verified that the A7670SA module works correctly using SSCOM; it responds to commands without any issues. However, when trying to communicate with it through my ESP32, these issues arise.
I am attaching the code I am using:
#include <SoftwareSerial.h>
#define a7670sa_RX 16
#define a7670sa_TX 17
SoftwareSerial a7670saSerial(a7670sa_RX, a7670sa_TX); // RX, TX
int LED_PIN = 2;
void setup() {
pinMode(LED_PIN, OUTPUT); // Establece el pin del LED como salida
digitalWrite(LED_PIN, HIGH); // Enciende el LED inicialmente
Serial.begin(115200); // Inicializa la comunicación serial con el Monitor Serie de Arduino IDE
a7670saSerial.begin(115200, SWSERIAL_8N1); // Inicializa la comunicación SoftwareSerial con el módulo a7670sa
a7670saSerial.write(static_cast<char>(0x00)); // Envía un carácter nulo para limpiar cualquier dato pendiente
Serial.println("Initializing...");
delay(1000);
}
void loop() {
if (a7670saSerial.available()) {
String response = a7670saSerial.readStringUntil('\n');
Serial.println("Respuesta de a7670sa: " + response);
}
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
if (command == "AT") {
sendATCommand("AT", "Comando AT");
} else {
Serial.println("Comando no reconocido.");
}
}
}
void sendATCommand(String command, String commandName) {
Serial.print("Enviando comando: ");
Serial.println(commandName);
digitalWrite(LED_PIN, LOW); // Apaga el LED
// Limpia el búfer serial
while (a7670saSerial.available() > 0) {
a7670saSerial.read();
}
// Envía el comando
a7670saSerial.println(command);
unsigned long startTime = millis();
String response;
do {
while (a7670saSerial.available() > 0) {
response = a7670saSerial.readStringUntil('\n');
Serial.println(response);
if (response.startsWith("OK")) {
Serial.println(); // Imprime una nueva línea después de la respuesta
digitalWrite(LED_PIN, HIGH); // Enciende el LED
return; // Sale del bucle y la función
}
if (response.startsWith("ERROR")) {
Serial.println("\nError en la respuesta de a7670sa.");
digitalWrite(LED_PIN, HIGH); // Enciende el LED
return; // Sale del bucle y la función
}
}
// Si no hay respuesta aún, imprime puntos
Serial.print(".");
delay(500); // Espera medio segundo
} while (millis() - startTime < 5000); // Tiempo de espera de 5 segundos
// Si se alcanza el tiempo de espera
digitalWrite(LED_PIN, HIGH); // Enciende el LED
Serial.println("\nTiempo de espera alcanzado.");
}
Thats i what see on the serial port






