【问题标题】:Arduino gsm shield not responding. gsmAccess.begin() doesnt workArduino gsm 屏蔽没有响应。 gsmAccess.begin() 不起作用
【发布时间】: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);

}

我希望这段代码能够让我接收消息,我可以修改它以将消息存储在变量中

【问题讨论】:

    标签: arduino gsm


    【解决方案1】:

    你的问题可能是接线。

    您的开发板 (Arduino UNO R3) 有它的 UART(当您在引脚 0 RX1 TX 上定义 Serial.begin(9600) 时打算使用的那个。请参阅 here 以获取下面的示意图和图片(右上角带有标签 TX 和 RX)。

    软件模拟串行工作,因为您将引脚 7 和 8 定义为模拟 UART TX 和 RX 信号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多