Question

I was trying to connect the Arduino UNO board with the GSM2Click board that has an Quectel M95 module embedded on. Vcc=5V already set by the switch correctly. I powered both the board with an external DC supply. I've made the following connection:

      ARDUINO pin                   |          GSM pin:
                   3 (TX)                                              RX                                   
                   2 (RX)                                              TX
                   8                                                   STA
                   7                                                   PWK (always high)

The gsm2click board seems to be active because both the switch power and network are on (net led is blinking). I'm trying to get send the AT command but always get a 0 as answer:

#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);
}

Any suggestion?

Thanks to everybody in advance!

Was it helpful?

Solution

here is some thing wrong with your code so i am pasting code after modified this and try to understand what i want to tell u

#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);
}

and if still you have any issue please leave comment

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top