【发布时间】:2020-05-14 17:12:02
【问题描述】:
我的目的是使用GSM SIM800L coreboard 和 Arduino UNO 发送短信。这是代码
#include <SoftwareSerial.h>
//Create a software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(115200);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(115200);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CMGS=\"+ZZxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print("TEST"); //text content
updateSerial();
mySerial.write(26);
}
void loop()
{
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
这是串行监视器输出
22:31:19.430 -> Initializing...
但是,当我运行代码时,我的手机收到了短信,但是I can't see any AT commands in the serial monitor. It only outputs "Initializing..." 。 所有的连接和波特率都可以,检查了一千次。已将 2A、4.4v 电源连接到 GSM 核心板并缩短电线,并确保没有坏焊点。 GSM 模块红色 LED 每 3 秒闪烁一次。再一次,我收到短信到我的手机。所以这意味着问题出在 Arduino 串行监视器或代码上,而不是硬件上。我需要查看 AT 命令,因为我需要通过串行监视器输入更多命令,我尝试输入并单击发送,但它没有显示任何内容。您能提供的任何帮助将不胜感激。
【问题讨论】:
-
您正在通过另一个串行连接发送 AT 命令。
-
什么意思?
-
是的,我正在使用另一个串行通信,但两者都应该显示在同一个串行监视器中,因为我看到的每个 youtube 视频和论坛,它们都通过同一个串行监视器发送命令,用于正常打印事物。这是我关注的示例视频link
-
您将看到 AT 命令,但前提是您发送到的设备启用了回显。尝试向您的设备发送“ATE1”以启用回显。
-
SoftwareSerial in Arduino Uno 不支持 115200 bade rate 并在循环中使用 while (Serial.available()) 和 while(mySerial.available())
标签: arduino gsm at-command serial-communication sim800l