Arduino Sim900 没有回声但发送了短信 [英] Arduino Sim900 with no echo but SMS was sent out

查看:32
本文介绍了Arduino Sim900 没有回声但发送了短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚买了一个新的 Sim900 并连接到了 Arduino Uno.我使用下面的代码向自己发送文本.我在我的手机上收到了文本,但我的串行监视器上没有收到任何回声(即OK").我曾尝试交换 RX/TX 引脚和不同的波特率,但没有成功.

I just got a new Sim900 and connected to an Arduino Uno. I used the code below to send a text to myself. I received the text on my cell, but I did not receive any echo on my serial monitor (ie. "OK"). I have tried swapping the RX/TX pins and different baud rates with no success.

void setup()
{
  Serial.begin(9600);  //Baud rate of the GSM/GPRS Module 
  Serial.println("");
  delay(2000);                  
  Serial.println("AT+CMGF=1");    
  delay(1000);
  Serial.println("AT+CMGS=\"+120########\"");    //Number to which you want to send the sms
  delay(1000);
  Serial.print("This is a test.");   //The text of the message to be sent
  delay(1000);
  Serial.write(0x1A); // send CTRL - z to end message
  Serial.write(0x0D); // Carriage Return
  Serial.write(0x0A); // Line Feed
  delay(5000); 
 }

void loop()
{
}

推荐答案

正如@hlovdal 所说,在消息之间使用延迟是一个坏主意.您必须等待每个命令的回答并根据回答(或因为超时)采取行动.

As @hlovdal says, using delay between messages is a bad idea. You have to wait the answer of each command and take actions depending on the answer (or because a timeout).

假设这就是您的全部代码,您将跳过读取串行端口的部分.就像你做serial.write一样,你必须使用serial.read来获取传入的字符.也许这就是原因,因为您没有收到任何东西.

Assuming that that's all your code, you're are skipping the part of reading the serial port. Just like you do serial.write, you have to use serial.read to get the incoming characters. Maybe this is the reason because you're not receiving anything.

最后,Arduino UNO 有一个 UART 端口,所以如果你想有一个串口监视器进行调试,你必须使用 SoftwareSerial 与 SIM900 通信.

Finally, Arduino UNO's got one UART port, so if you want to have a serial monitor for debugging, you'll have to use SoftwareSerial to communicate with the SIM900.

这篇关于Arduino Sim900 没有回声但发送了短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆