arduino uno with shield sim900无法阅读短信

时间:2015-03-31 10:09:23

标签: android arduino-uno

我遇到了一个问题。当我用盾牌sim900向我的arduino板发送短信时,它以数字模式显示我的消息。谁知道这是什么问题?这是我的代码。在底部,我使用串行监视器查看我的消息,并在数字中读取消息。

`

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

char incoming_char=0;

void setup()
{
  Serial.begin(19200); // for serial monitor
  SIM900.begin(19200); // for GSM shield
  SIM900power();  // turn on shield
  delay(25000);  // give time to log on to network.

  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);

  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(1000);
  SIM900.print("AT+CNMI=2,2,0,0,0\r"); 
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(1000);


}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}

void loop()
{
  // Now we simply display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0)
  {
    incoming_char=SIM900.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
    if (incoming_char=='a')
    {
      digitalWrite(4,HIGH);
       Serial.println(incoming_char);
      SIM900.println("AT+CMGD=1,4"); // delete all SMS

       }
       if (incoming_char=='b')
    {
      digitalWrite(4,LOW);
       Serial.println(incoming_char);
      SIM900.println("AT+CMGD=1,4"); // delete all SMS

       }


  }

}

0 个答案:

没有答案