【问题标题】:How to run Ai Thinker A9G gps module using arduino uno & Arduino IDE?如何使用 arduino uno 和 Arduino IDE 运行 Ai Thinker A9G gps 模块?
【发布时间】:2021-02-10 08:37:43
【问题描述】:

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

【问题讨论】:

  • 我做了一些研究,看到这个链接有所有的说明。观看视频它有所有的细节create.arduino.cc/projecthub/akarsh98/…
  • 感谢亲爱的回复,但我已经看过视频,那里没有显示任何与 arduino 相关的东西。我正在使用带有 AT 命令的 arduino 搜索该模块将在其中工作的资源。
  • 如果您要询问与设备的“连接”,那 不属于这里。阅读您的数据表或在电子论坛/网站上发帖。

标签: arduino connection gsm


【解决方案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 会给出正确的读数,否则会给出旧读数。

【讨论】:

  • 你能解释一下你是怎么做到的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 2018-09-09
相关资源
最近更新 更多