Arduino Sim900 with no echo but SMS was sent out

2019-09-10 00:21发布

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()
{
}

2条回答
三岁会撩人
2楼-- · 2019-09-10 00:22

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).


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.


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.

查看更多
一夜七次
3楼-- · 2019-09-10 00:39

You should never, never, ever use delay as a substitute for reading and parsing the response sent back from the modem. Now, I do recognize that this is a bit ironic advice since the problem is that you do not get any response, but never the less you should throw away this code using delay the very moment you get response working, not a second later.

Just to emphasise this point, after sending an AT command line to the modem you should not send anything before the modem responds with a final result code. The V.250 standard says:

A final result code indicates the completion of a full DCE action and a willingness to accept new commands from the DTE.

If you send anything before receiving the final result code you will abort the currently executing command!


I do not know this sim900 modem, but notice that modems in general can be configured to not echo characters and suppress result codes (ATE and ATQ commands), so unless you know absolutely for sure that the modem is configured to echo characters and print result codes this should be your first thing to check.

All this is described in the V.250 standard, which is a really important document. Read all of chapter 5 and also pay close attention to chapter 6.2 DTE-DCE interface commands.


Mobile phone related commands are generally specified in the 27.007 standard, although sms message related commands are specified in 27.005 standard. Do pay close attention to the fact that for AT+CMGS in particular you need to wait to receive `"\n\r> " before sending the sms payload (see also the first part of this answer).

查看更多
登录 后发表回答