如何运行 Ai Thinker A9G gps 模块使用arduino uno & Arduino IDE?

How to run Ai Thinker A9G gps module using arduino uno & Arduino IDE?

我找不到任何博客或解决方案来连接和 运行 A9G Ai thinker GSM/GPRS GPS 模块与 Arduino Uno 使用 Arduino IDE。只找到一个视频,但显示使用 USB 到 TTL 转换器连接 A9G。但我需要 Arduino uno 和 A9G 的正确连接细节。 如何连接它们? (告诉我,我将 A9G rx 与 arduino tx 连接,tx 与 arduino rx 和 GRnd 以及 Vcc (5v+) 连接,并使用 SMAD 端口但没有用) IDE 必须使用哪个主板和端口才能使用 A9G? 如何使用 arduino 代码将 AT 命令放入 IDE。 提前谢谢你。

经过研究,我成功地使用 Arduino Uno 实现了 A9G,代码如下:

#include <SoftwareSerial.h> // Library for using serial communication
SoftwareSerial SIM900(7, 8); // Pins 7, 8 are used as used as software serial pins

String incomingData;   // for storing incoming serial data
//String message = "";   // A String for storing the message
//int relay_pin = 2;    // Initialized a pin for relay module
char msg;
char call;
void setup()
{
  Serial.begin(115200); // baudrate for serial monitor
  SIM900.begin(115200); // baudrate for GSM shield
  

  Serial.println("GSM SIM900A BEGIN");
  Serial.println("Enter character for control option:");
  Serial.println("h : to disconnect a call");
  Serial.println("i : to receive a call");
  Serial.println("s : to send message");
  Serial.println("c : to make a call");  
  Serial.println("e : to redial");
  Serial.println("l : to read location");
  Serial.println();
  delay(100);

  
  /*SIM900.println("AT+GPS=1");
  delay(100);
  SIM900.println("AT+GPSRD=5");
  delay(5000);*/
  
  // set SMS mode to text mode
  SIM900.print("AT+CMGF=1\r");  
  delay(100);
  
  // set gsm module to tp show the output on serial out
  SIM900.print("AT+CNMI=2,2,0,0,0\r"); 
  delay(100);
}

void loop()
{
  
  receive_message();


if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'c':
      MakeCall();
      break;
    case 'h':
      HangupCall();
      break;
    case 'e':
      RedialCall();
      break;
    case 'i':
      ReceiveCall();
      break;
    case 'l':
      ReadLocation();
      break;
  }
       
}

void receive_message()
{
  if (SIM900.available() > 0)
  {
    incomingData = SIM900.readString(); // Get the data from the serial port.
    Serial.print(incomingData); 
    delay(10); 
  }
}

void SendMessage()
{
  SIM900.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  SIM900.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
  delay(1000);
  SIM900.println("sim900a sms");// The SMS text you want to send
  delay(100);
   SIM900.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

void ReceiveMessage()
{
  SIM900.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
  delay(1000);
  if (SIM900.available()>0)
  {
    msg=SIM900.read();
    Serial.print(msg);
  }
}

void MakeCall()
{
  SIM900.println("ATD+201020516469;"); // ATDxxxxxxxxxx; -- watch out here for semicolon at the end, replace your number here!!
  Serial.println("Calling  "); // print response over serial port
  delay(1000);
}


void HangupCall()
{
  SIM900.println("ATH");
  Serial.println("Hangup Call");
  delay(1000);
}

void ReceiveCall()
{
  SIM900.println("ATA");
  delay(1000);
  {
    call=SIM900.read();
    Serial.print(call);
  }
}

void RedialCall()
{
  SIM900.println("ATDL");
  Serial.println("Redialing");
  delay(1000);
}
void ReadLocation(){

  SIM900.println("AT+GPS=1");
  delay(1000);
  SIM900.println("AT+GPSRD=5");
  delay(1000);
  
  }

设置串口监视器波特率为115200 并在 MakeCall 函数中替换您的号码

编辑: 我在使用波特率 11500 时遇到串行监视器中的噪音问题,将其替换为 9600 后噪音消失了。

编辑: 重要注意事项 如果天线在开阔区域并且模块与外部电源连接,gps 将给出正确的读数,否则它会给你旧的读数。