A9G GSM/GPS module outputs garbage

Hi,
I am evaluating the A9G GSM/GPS module.
I am using a ATMEGA328PB to communicate with the A9G module.
When I connect a FTDI cable directly to the AT_TX / AT_RX ports of the A9G and use a terminal software on the PC, I can talk to the A9G with no problem.
Using this setup, if I send the AT command "AT", the A9G responds with "OK", which is correct.

However, when I wire the A9G to the ATMEGA328PB, using Serial1 connected to the AT_TX / AT_RX ports of the A9G and send the attached sketch, I receive garbage on the Serial Monitor in the Arduino IDE.

Serial Monitor Log:

BOOT
Now turning A9G ON.
Using sendData()
AUH
⸮j5
Using sendATcmd()
Result:FAILED

This should output:

BOOT
Now turning A9G ON.
Using sendData()
OK
Using sendATcmd()
Result:DONE

My Sketch:

int PWR_KEY = 4;
boolean AT_cmd_result = false;

#define DEBUG true

static int  success = 0, failed = 0;
bool        status;
char        buffer[30];

void setup()
{
  Serial.begin(115200);
  Serial.println("BOOT");
  Serial1.begin(115200);

  // TOGGLE A9G POWER
  pinMode(PWR_KEY, OUTPUT);
  digitalWrite(PWR_KEY, HIGH);
  delay(3000);
  digitalWrite(PWR_KEY, LOW);
  delay(3000);
  digitalWrite(PWR_KEY, HIGH);
  delay(2000);

  //Check A9G is Ready
  Serial.println("A9G switched ON.");

  Serial.println("Using sendData()");
  sendData("AT", 5, DEBUG);

  Serial.println("Using sendATcmd()");
  status = sendATcmd("AT", 5, "OK");
}

void loop() {

}

// sendData
String sendData(String command, const int timeout, boolean debug)
{
  String response = "";

  Serial1.println(command);
  delay(20);
  long int time = millis();
  while ((time + timeout) > millis())
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      response += c;
    }
  }
  if (DEBUG)
  {
    Serial.print(response);
    delay(100);
  }
  return response;
}

// sendATcmd
bool sendATcmd(String AT_cmd, int AT_cmd_maxTime, char readReplay[])
{
  int   trycnt = 0;
  bool  status = false;

  while (trycnt < AT_cmd_maxTime) {
    Serial1.println(AT_cmd);

    if (Serial1.find(readReplay)) {
      AT_cmd_result = true;
      break;
    }
    ++trycnt;
  }

  Serial.print(F("Result:"));
  if (true == AT_cmd_result) {
    Serial.println(F("DONE"));
    status = true;
  } else {
    Serial.println(F("FAILED"));
  }
  AT_cmd_result = false;
  return status;
}

In the sketch, I use two different scenarios:
sendData("AT", 5, DEBUG);
and
status = sendATcmd("AT", 5, "OK");

I cannot see what I am doing incorrectly.
I have confirmed that both the ATMEGA328PB and the A9G baud rates are set to 115200

The ATmega328PB has only one UART and one serial port. What Arduino module are you actually using?

I am using the A-Star 328PB Micro board from Pololu.

My mistake. The "PB" does indeed have two UARTs.

The GSM module is the prime suspect, but a brief search revealed datasheets only in Chinese. Were you able to find full documentation in English?

Hi,
I managed to overcome this by changing the baud rate in the A9G module

I have confirmed that both the ATMEGA328PB and the A9G baud rates are set to 115200

Change the baud rate of A9G to 9600

Could you please share the diagram of the PWR_KEY part? Do you connect the mcu pin to pwr_key pin of A9G?

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