SIMCOM SIM900 Arduino AT回答奇怪的人物

时间:2016-03-05 09:33:16

标签: arduino gsm at-command chars

我一直在测试以下产品 http://thumbs2.ebaystatic.com/d/l225/m/mboWkBZlMUEWh7HE5iTGyAg.jpg

模块已正确注册到移动网络,因为我可以在MSIDSN上响铃。不幸的是我无法成功发送AT命令;当我尝试发送一些东西时,我总是会得到欧元符号的奇怪字符(总是相同的)。 我把电路板的pin0和pin1分别连接到Arduino上的D7和D8。 有人遇到过同样的问题吗? 这是代码:

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);         //7 = TX, 8 = RX
unsigned char buffer[64]; // port
int count=0;     
int i = 0;                         //if i = 0, send SMS.
void setup(){
//delay(10000);
GPRS.begin(19200);               // the GPRS baud rate   
Serial.begin(19200);             // the Serial port of Arduino baud rate.
Serial.print("I'm ready");
Serial.print("Hello?"); 
}

void loop(){
if (GPRS.available()){         // if date is comming from softwareserial               port ==> data is comming from gprs shield

while(GPRS.available()){          // reading data into char array 
  buffer[count++]=GPRS.read();     // writing data into array
  if(count == 64)break;
}
Serial.write(buffer,count);            // if no data transmission ends,           write buffer to hardware serial port
clearBufferArray();              // call clearBufferArray function to clear  the storaged data from the array
count = 0;                       // set counter of while loop to zero


}
if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
  GPRS.write(Serial.read());       // write it to the GPRS shield

  if(i == 0){
GPRS.println("ATD+39xyzt;"); //where xxxxxxxxxx is  a 10 digit mobile number
 delay(10000);
 GPRS.println("ATH"); // end call hangup
  GPRS.print("AT+CMGF=1\r"); //mandando SMS em modo texto
   Serial.println("AT+CMGF=1\r"); //mandando SMS em modo texto
   delay(1000);
    GPRS.print("AT+CMGS=\"+3934xxxxxxxx\"\r"); // numero que vamos mandar o SMS
   Serial.println("AT+CMGS=\"+393xxxxxx\"\r"); // numero que vamos mandar o SMS
   delay(1000);
   GPRS.print("Test di invio messaggio\r"); // corpo da msg
   Serial.println("Test di invio messaggio\r"); // corpo da msg
   delay(1000);
   GPRS.write(0x1A); //equivalente a mandar Ctrl+Z(finaliza corpo do SMS)
delay(1000);
    Serial.println("SMS sent successfully");
    i++;
    }   

  }
  void clearBufferArray(){              // function to clear buffer array
   for (int i=0; i<count;i++){
    buffer[i]=NULL;                  // clear all index of array with comma       nd NULL
   }
  } 

0 个答案:

没有答案