我找不到任何博客或解决方案来使用Arduino IDE连接和运行Arduino Uno的A9G Ai thinker /GPRS GPS模块。只找到一个视频,但它显示了使用USB到TTL转换器的A9G连接。但是我需要Arduino uno和A9G的正确连接细节。如何连接它们?(让我告诉你,我用arduino rx连接A9G rx,用arduino tx连接tx,用arduino rx连接GRnd和Vcc (5v+),并使用SMAD口,但不起作用)哪个板和端口必须使用集成开发环境才能使用A9G?如何使用arduino代码将AT命令放入IDE中。提前谢谢你。
发布于 2021-04-23 19:22:47
经过研究,我成功地用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=\"+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,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将给出正确的读数,否则它会给你旧的读数。
https://stackoverflow.com/questions/66133431
复制相似问题