【发布时间】:2019-07-03 07:54:21
【问题描述】:
我正在尝试让我的 arduino GSM shield 使用提供的示例“发送 SMS”代码。但是,当我上传并编译程序时,串口监视器显示“SMS Messages Sender”,没有其他任何反应。
我正在使用 Arduino uno r3 和 gsm sim 900。为 5V 1.5A 供电的 gsm。我已将 arduino 引脚 7 和 8 连接到 gsm 的引脚 7 和 8。我也将gsm接地。
当我使用 SoftwareSerial.h 时,它可以工作。但我希望使用现在不起作用的 GSM.h 库。请帮忙
// include the GSM library
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retrieved from
char senderNumber[20];
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("SMS Messages Receiver");
// connection state
bool notConnected = true;
// Start GSM connection
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
void loop() {
char c;
// If there are any SMSs available()
if (sms.available()) {
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
// An example of message disposal
// Any messages starting with # should be discarded
if (sms.peek() == '#') {
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
while (c = sms.read()) {
Serial.print(c);
}
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}
我希望这段代码能够让我接收消息,我可以修改它以将消息存储在变量中
【问题讨论】: