#include <HardwareSerial.h>
HardwareSerial ecSerial(1); // Use UART1 for EC200U
#define EC_TX 19 // ESP32 TX → EC200U RX
#define EC_RX 18 // ESP32 RX → EC200U TX
// Function to send AT command and return the response
String sendAT(String command, int timeout = 2000) {
ecSerial.println(command);
unsigned long start = millis();
String response = “”;
while (millis() - start < timeout) {
while (ecSerial.available()) {
char c = ecSerial.read();
response += c;
}
}
Serial.println("AT CMD: " + command);
Serial.println("Response: " + response);
return response;
}
void setup() {
Serial.begin(115200);
ecSerial.begin(115200, SERIAL_8N1, EC_RX, EC_TX);
delay(3000); // Wait for modem to power up
Serial.println(“=== Initializing EC200U GPS ===”);
sendAT(“AT”); // Test communication
sendAT(“ATE0”); // Echo off
//
SELECT GPS + BeiDou SYSTEMS
sendAT(“AT+QGPSCFG="gnssconfig",5”); // Use GPS + BeiDou
sendAT(“AT+QGPSCFG="outport","none"”); // No continuous NMEA output
sendAT(“AT+QGPSEND”); // Just in case GPS was running
delay(1000);
sendAT(“AT+QGPSDEL=1”); // Cold restart to clear previous fixes
delay(1000);
String gpsStart = sendAT(“AT+QGPS=1”); // Start GNSS
if (gpsStart.indexOf(“OK”) != -1) {
Serial.println(“GPS Started Successfully”);
} else {
Serial.println(“Failed to start GPS”);
}
delay(10000); // Wait for GPS to get fix (can take longer outdoors)
}
void loop() {
String response = sendAT(“AT+QGPSLOC=0”, 3000);
if (response.indexOf(“+QGPSLOC:”) != -1) {
Serial.println("
Location: " + response);
} else if (response.indexOf(“516”) != -1) {
Serial.println(“
Still waiting for GPS fix…”);
} else {
Serial.println("
Other error: " + response);
}
delay(10000); // Try every 10 seconds
}
i am getting
Still waiting for GPS fix…
AT CMD: AT+QGPSLOC=0
Response:
+CMS ERROR: 516