问题描述
我找不到任何使用 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 端口但没有工作) 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\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=\"+201126498473\"\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,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,噪音消失了。