【发布时间】:2016-04-30 03:40:46
【问题描述】:
在将此问题标记为重复之前,请注意我已经尝试过this、this & this
我最近买了一个 Arduino UNO R3 和一个 SIM808 GSM/GPS 扩展板。 Shield 的 RX 连接到 Arduino 的 Pin 11,TX 连接到 Pin 10,两个 GND 相互连接。我已经使用 USB 将我的 Arduino 连接到我的计算机,并且屏蔽连接到使用 12V 适配器的外部电源。另外,我已经将 Arduino 的 3.3V 连接到了 shield 的 Vcc。
以下是我使用的草图:
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
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 Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop() {
Serial.print("Enter a mobile number: ");
char remoteNum[20]; // telephone number to send sms
readSerial(remoteNum);
Serial.println(remoteNum);
// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}
/*
Read input serial
*/
int readSerial(char result[]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r') {
result[i] = inChar;
i++;
}
}
}
}
这里的问题与那些链接帖子中提到的问题相同。
条件if (gsmAccess.begin(PINNUMBER) == GSM_READY) 永远不会被执行。 else 部分也不执行。
串行监视器永远不会超过 SMS 消息发送者。
请注意,我使用的是 AirTel India,我有一个完全激活的数据计划,并且 PIN 码已更改为 0000。
如果有人能提出一些有用的建议,我们将不胜感激。
感谢您的宝贵时间!!
【问题讨论】:
标签: arduino gsm arduino-uno arduino-ide