首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Arduino和GSM2Click董事会(Quectel M95)

Arduino和GSM2Click董事会(Quectel M95)
EN

Stack Overflow用户
提问于 2014-04-02 10:15:30
回答 1查看 1.8K关注 0票数 1

我试图将Arduino UNO板与嵌入Quectel M95模块的M95板连接起来。Vcc=5V已由开关正确设置。我用外部直流电源为两块板供电。我已经建立了以下联系:

代码语言:javascript
运行
复制
      ARDUINO pin                   |          GSM pin:
                   3 (TX)                                              RX                                   
                   2 (RX)                                              TX
                   8                                                   STA
                   7                                                   PWK (always high)

gsm2click板似乎是活动的,因为开关电源和网络都是开着的(net正在闪烁)。我试图发送AT命令,但始终得到0作为回答:

代码语言:javascript
运行
复制
#include <SoftwareSerial.h>

const int PWK= 7; // Analog output pin that the LED is attached to
const int STA= 8;
const int RX=2;
const int TX=3;
int STA_value;



SoftwareSerial mySerial(RX,TX); // RX, TX


void setup() {                
  // initialize the digital pin as an output.
  pinMode(PWK, OUTPUT);   // questo pin serve per accendere il dispositivo GSM
  pinMode(STA, INPUT);   

  pinMode(RX,INPUT);
  pinMode(TX,OUTPUT);


  gsmOn();


  Serial.begin(9600);  //Init seriale sw
  Serial.println("Arduino serial initialized!");
  delay(10); 

  mySerial.begin(9600);  //init seriale hw
  Serial.println("Software serial initialized!");
  delay(10); 



}




// the loop routine runs over and over again forever:
  void loop() 
  {

      sendCommand("AT");
      delay(10);

      readSerial();
      delay(1000);         

  }


void sendCommand(char* msg)
{ 
  mySerial.print(msg);
  Serial.println(msg);
  delay(1); 

}

void readSerial()
{
  while(mySerial.available()>0)
  {
    Serial.print(mySerial.read());
    delay(1);  
  }


}



void gsmOn() 
{ 
  // Takes 30 seconds to complete
  digitalWrite(PWK, HIGH);   // turn the Phone on
  delay(2);
}

有什么建议吗?

感谢大家的提前!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-16 11:22:45

下面是您的代码有问题,所以我在修改后粘贴代码,并尝试理解我想告诉您的内容。

代码语言:javascript
运行
复制
#include <SoftwareSerial.h>

const int PWK= 7; // Analog output pin that the LED is attached to
const int STA= 8;
const int RX=2;
const int TX=3;
int STA_value;



 SoftwareSerial mySerial(RX,TX); // RX, TX


 void setup() {                
// initialize the digital pin as an output.
 pinMode(PWK, OUTPUT);   // questo pin serve per accendere il dispositivo GSM
 pinMode(STA, INPUT);   

 //pinMode(RX,INPUT);   //if u want to use this as serial port then don't declare this   I/O
 //pinMode(TX,OUTPUT);


gsmOn();


Serial.begin(9600);  //Init seriale sw
Serial.println("Arduino serial initialized!");
delay(10); 

mySerial.begin(9600);  //init seriale hw
Serial.println("Software serial initialized!");
delay(10); 
 }

 // the loop routine runs over and over again forever:
void loop() 
{
uint8_t answer=0;

// checks if the module is started
answer = sendCommand("AT", "OK", "OK", 2000);
if (answer == 1)
{
Serial.println("OK");
 }
  else
 Serial.println("Not Responding");
  delay(1000);         
  }
 int8_t sendCommand(char* ATcommand, char* expected_answer1, 
    char* expected_answer2, unsigned int timeout){
uint8_t x=0,  answer=0;
char response[100];
unsigned long previous;
memset(response, '\0', 100);    // Initialize the string
delay(100);
while( mySerial.available() > 0)
{
mySerial.read();    // Clean the input buffer
}
Serial.println(ATcommand);    // Send the AT command to serial port 
mySerial.println(ATcommand);    // Send the AT command to gsm module
previous = millis();
// this loop waits for the answer
do{
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if(mySerial.available() != 0){    
        response[x] = mySerial.read();
        x++;
        // check if the desired answer 1  is in the response of the module
        if (strstr(response, expected_answer1) != NULL)    
        {
            answer = 1;
        }
        // check if the desired answer 2 is in the response of the module
        else if (strstr(response, expected_answer2) != NULL)    
        {
            answer = 2;
        }
    }
}
// Waits for the asnwer with time out
while((answer == 0) && ((millis() - previous) < timeout)); 

return answer;
    }
void gsmOn() 
 { 
 // Takes 30 seconds to complete
 digitalWrite(PWK, HIGH);   // turn the Phone on
delay(2);
}

如果你还有什么问题,请留下评论

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22808241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档