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

问题描述 投票:0回答:2

我找不到任何使用 Arduino IDE 连接和运行 A9G Ai thinker GSM/GPRS GPS 模块与 Arduino Uno 的博客或解决方案。只找到一个视频,但显示了 A9G 使用 USB 转 TTL 转换器的连接。但我需要 Arduino uno 和 A9G 的正确连接详细信息。 如何连接它们? (让我通知一下,我将A9G rx与arduino tx连接,tx与arduino rx以及GRnd和Vcc(5v+)连接并使用SMAD端口,但不起作用) A9G必须使用哪个板卡和端口作为IDE才能使用A9G? 如何使用arduino代码将AT命令放入IDE中。 预先感谢您。

arduino connection gsm
2个回答
1
投票

经过研究,我成功使用 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 将给出正确的读数,否则它会给您旧的读数。


0
投票

我正在使用arduino uno和A9G模块制作无线跟踪器。我可以在 arduino 上刷新空代码并将波特率设置为 115200 来使用和检查 AT 命令。但是当我尝试运行代码时,a9g 模块似乎没有响应 AT 命令。我为两者使用单独的电源,并使用 arduino 的引脚 0 和 1 连接到 a9g 模块的 tx 和 rx。

© www.soinside.com 2019 - 2024. All rights reserved.