程序正在执行,但串行监视器中未显示 AT 命令
Program is executing but AT commands not showing in serial monitor
我的目的是使用 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...
但是,当我 运行 代码时,我的手机 phone 收到了短信,但是 I can't see any AT commands in the serial monitor. It only outputs "Initializing..." 。
所有的连接和波特率都没有问题,检查了一千次。已将2A、4.4v电源接入GSM核心板,并缩短线材,焊点无不良。 GSM 模块红色 LED 每 3 秒闪烁一次。再一次,我收到了我的 phone 的短信。所以这意味着问题出在 Arduino 串行监视器或代码上,而不是在硬件上。我需要查看 AT 命令,因为我需要通过串行监视器输入更多命令,我尝试输入并单击发送,但它没有显示任何内容。如果您能提供任何帮助,我们将不胜感激。
你的逻辑在updateSerial()
函数中是相反的。
实际上,您正在 setup
函数中通过 mySerial
发送 AT
命令,然后您需要等待该对象 mySerial
中的答案.
因此,您应该执行 while (!mySerial.available()) ;
才能从中读取内容。此循环结束后,您可以从 mySerial
.
读取
但是,你想将它转发到串口监视器,所以你还需要检查 Serial
是否可以写入,这就是你等待它的原因,导致 while (!mySerial.available() || !Serial.available()) ;
.
一旦您确定两个连续出版物都可用,您可以从一个读取并将刚刚读取的内容写入另一个:Serial.Write(mySerial.read())
.
此外,我认为 mySerial.write(Serial.read())
调用没有任何必要,因为 Serial
仅用于转发您从 SIM800L 接收的内容,因此,您可以简单地删除它部分。
因此,更正您的函数将导致:
void updateSerial()
{
delay(500);
while (!mySerial.available() || !Serial.available())
;
Serial.write(mySerial.read());
}
因此,有了这个,您从 SIM800L 收到的所有信息都会转发到串行监视器。
我的目的是使用 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...
但是,当我 运行 代码时,我的手机 phone 收到了短信,但是 I can't see any AT commands in the serial monitor. It only outputs "Initializing..." 。 所有的连接和波特率都没有问题,检查了一千次。已将2A、4.4v电源接入GSM核心板,并缩短线材,焊点无不良。 GSM 模块红色 LED 每 3 秒闪烁一次。再一次,我收到了我的 phone 的短信。所以这意味着问题出在 Arduino 串行监视器或代码上,而不是在硬件上。我需要查看 AT 命令,因为我需要通过串行监视器输入更多命令,我尝试输入并单击发送,但它没有显示任何内容。如果您能提供任何帮助,我们将不胜感激。
你的逻辑在updateSerial()
函数中是相反的。
实际上,您正在 setup
函数中通过 mySerial
发送 AT
命令,然后您需要等待该对象 mySerial
中的答案.
因此,您应该执行 while (!mySerial.available()) ;
才能从中读取内容。此循环结束后,您可以从 mySerial
.
但是,你想将它转发到串口监视器,所以你还需要检查 Serial
是否可以写入,这就是你等待它的原因,导致 while (!mySerial.available() || !Serial.available()) ;
.
一旦您确定两个连续出版物都可用,您可以从一个读取并将刚刚读取的内容写入另一个:Serial.Write(mySerial.read())
.
此外,我认为 mySerial.write(Serial.read())
调用没有任何必要,因为 Serial
仅用于转发您从 SIM800L 接收的内容,因此,您可以简单地删除它部分。
因此,更正您的函数将导致:
void updateSerial()
{
delay(500);
while (!mySerial.available() || !Serial.available())
;
Serial.write(mySerial.read());
}
因此,有了这个,您从 SIM800L 收到的所有信息都会转发到串行监视器。