Forum >GPS/GPRS/GSM simple code
ArduinoGeneral

GPS/GPRS/GSM simple code

userHead maxpat 2012-08-06 13:06:37 14065 Views19 Replies
Hi, I am trying to write a simple code to start using GSM function with my Arduino UNO. But without success...


[code]byte gsmDriverPin[3] = {
3,4,5};
int test=0;

void setup(){
InitGsmMode();
Serial.begin(115200); // I tried with 9600
delay(500);
}

void InitGsmMode(){
//Init the driver pins for GSM function
for(int i = 0 ; i < 3; i++){
pinMode(gsmDriverPin[i],OUTPUT);
}

digitalWrite(3,LOW);//Enable the GSM mode
digitalWrite(4,HIGH);//Disable the GPS mode
//Output GSM Timing
digitalWrite(5,HIGH); delay(1500); digitalWrite(5,LOW);
}

void loop()
{
while (test<1) {
Serial.println("waiting 5 s.");
delay(5000);
Serial.println("AT");delay(10000);

SendTextMessage();
Serial.println("Finished ?");
test++;
};
Serial.println("End");
}

///SendTextMessage() ///this function is to send a sms message
void SendTextMessage()
{
Serial.write("AT+CMGF=1");Serial.write("\r"); //Because we want to send the SMS in text mode
delay(5000); // I put 5 s to be sure that the module has time to respond.
Serial.write("AT + CMGS = \"098415719\"");Serial.write("\r"); //send sms message,
delay(5000);
Serial.write("A test message!");Serial.write("\r");//the content of the message
delay(5000);
Serial.write(0x1A);Serial.write("\r"); //the ASCII code of the ctrl+z is 26 - I tried also with print(char(26))
delay(5000);

}
[/code]

I tried with write, print, println.. nothing happen, except that I get my command to the serial monitor.

Can you help me starting right ?

Thanks !
2013-04-23 04:37:30 Hello,

i'm trying to get working the DFROBOT GPS GPRS GSM shield with my Arduino Duemilanove.

It's rev 3.0.

I'm trying to call from the shield to my cell, but it always says "NO CARRIER".

There is no PIN code on the SIM card in the shield ...

CAn you help me ?

I'm using this code :

[code]// #
// # Editor    : Lauren from DFRobot
// # Date      : 23.05.2012
// # E-Mail : [email protected]

// # Product name: GPS/GPRS/GSM Module V2.0
// # Product SKU : TEL0051
// # Version    : 0.1

// # Description:
// # The sketch for driving the gsm mode via the USB interface

// # Steps:
// #        1. Turn the S1 switch to the EN(right side)
// #        2. Upload the sketch to the Arduino board
// #        3. Turn the S1 switch to the communication mode(left side)
// #        4. Turn the S2 switch to the USB side(left side)
// #        5. send AT commands via the Arduino Serial monitor

// #        wiki link- https://www.dfrobot.com/wiki/index.php?title=GPS/GPRS/GSM_Module_V2.0

byte gsmDriverPin[3] = {
  3,4,5};//The default digital driver pins for the GSM and GPS mode
//If you want to change the digital driver pins
//or you have a conflict with D3~D5 on Arduino board,
//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!


void setup(){
  InitGsmMode();
}

void InitGsmMode(){
  //Init the driver pins for GSM function
  for(int i = 0 ; i < 3; i++){
    pinMode(gsmDriverPin[i],OUTPUT);
  }

  digitalWrite(3,LOW);//Enable the GSM mode
  digitalWrite(4,HIGH);//Disable the GPS mode
  //Output GSM Timing
  digitalWrite(5,HIGH);
  delay(1500);
  digitalWrite(5,LOW); 
}

void loop(){
  delay(100);
}[/code]

The jumpers J10, J11, J12 are in place on the shield

Can you help me ?
userHeadPic carmelo42
2013-04-23 04:37:30 Hello,

i'm trying to get working the DFROBOT GPS GPRS GSM shield with my Arduino Duemilanove.

It's rev 3.0.

I'm trying to call from the shield to my cell, but it always says "NO CARRIER".

There is no PIN code on the SIM card in the shield ...

CAn you help me ?

I'm using this code :

[code]// #
// # Editor    : Lauren from DFRobot
// # Date      : 23.05.2012
// # E-Mail : [email protected]

// # Product name: GPS/GPRS/GSM Module V2.0
// # Product SKU : TEL0051
// # Version    : 0.1

// # Description:
// # The sketch for driving the gsm mode via the USB interface

// # Steps:
// #        1. Turn the S1 switch to the EN(right side)
// #        2. Upload the sketch to the Arduino board
// #        3. Turn the S1 switch to the communication mode(left side)
// #        4. Turn the S2 switch to the USB side(left side)
// #        5. send AT commands via the Arduino Serial monitor

// #        wiki link- https://www.dfrobot.com/wiki/index.php?title=GPS/GPRS/GSM_Module_V2.0

byte gsmDriverPin[3] = {
  3,4,5};//The default digital driver pins for the GSM and GPS mode
//If you want to change the digital driver pins
//or you have a conflict with D3~D5 on Arduino board,
//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!


void setup(){
  InitGsmMode();
}

void InitGsmMode(){
  //Init the driver pins for GSM function
  for(int i = 0 ; i < 3; i++){
    pinMode(gsmDriverPin[i],OUTPUT);
  }

  digitalWrite(3,LOW);//Enable the GSM mode
  digitalWrite(4,HIGH);//Disable the GPS mode
  //Output GSM Timing
  digitalWrite(5,HIGH);
  delay(1500);
  digitalWrite(5,LOW); 
}

void loop(){
  delay(100);
}[/code]

The jumpers J10, J11, J12 are in place on the shield

Can you help me ?
userHeadPic carmelo42
2012-08-09 21:35:38 I used a 7.4v power supply, my borad works well. userHeadPic vector
2012-08-09 21:35:38 I used a 7.4v power supply, my borad works well. userHeadPic vector
2012-08-09 20:37:15 The command AT+CSCA is not needed sometimes, however,you should set it for safety. you can also check it with the the code gsmUsbSketch posted on WIKI. userHeadPic vector
2012-08-09 20:37:15 The command AT+CSCA is not needed sometimes, however,you should set it for safety. you can also check it with the the code gsmUsbSketch posted on WIKI. userHeadPic vector
2012-08-09 20:30:08 hi,maxpat:
as you problems,i am also puzzled....but you can try to restart you uno borad, the beta version posted by lauren haven't check whether the AT commands  are successful executed.
at last, the right format of set PIN is AT+CPIN=0000, No colon ”.
userHeadPic vector
2012-08-09 20:30:08 hi,maxpat:
as you problems,i am also puzzled....but you can try to restart you uno borad, the beta version posted by lauren haven't check whether the AT commands  are successful executed.
at last, the right format of set PIN is AT+CPIN=0000, No colon ”.
userHeadPic vector
2012-08-08 18:02:07 Good news and bad news !
1) It's working well with my wife ANTEL SIM (I am from Uruguay)
2) It' NOT working with my ANTEL SIM - Same contract. I can send SMS from coolterm :
Call Ready
AT OK
AT+CSCA? +CSCA: "+59899998932",145

OK
AT+CMGF=1 OK
AT+CMGS="098415711" > test
>
+CMGS: 96
OK
but with your program, nothing happen. I check the CSCA, it's the same (normal)

What did I dfrobot ?

With another SIM, from Claro, I can send SMS from my phone but not from coolterm or your program.

The 3 do not have PIN. Speaking of PIN, what could be the text ? I tried with

char CMD_PIN[]={'A','T','+','C','P','I','N','=','"','0','0','0','0','"'}; with ou without " but i doesn't work.

Many thanks for you help.
userHeadPic maxpat
2012-08-08 18:02:07 Good news and bad news !
1) It's working well with my wife ANTEL SIM (I am from Uruguay)
2) It' NOT working with my ANTEL SIM - Same contract. I can send SMS from coolterm :
Call Ready
AT OK
AT+CSCA? +CSCA: "+59899998932",145

OK
AT+CMGF=1 OK
AT+CMGS="098415711" > test
>
+CMGS: 96
OK
but with your program, nothing happen. I check the CSCA, it's the same (normal)

What did I dfrobot ?

With another SIM, from Claro, I can send SMS from my phone but not from coolterm or your program.

The 3 do not have PIN. Speaking of PIN, what could be the text ? I tried with

char CMD_PIN[]={'A','T','+','C','P','I','N','=','"','0','0','0','0','"'}; with ou without " but i doesn't work.

Many thanks for you help.
userHeadPic maxpat
2012-08-08 05:48:40 Thank's ! I tried it and i worked 1 time ! I have to figure out why !
1 question : AT+CSCA is mandatory ?

Max
userHeadPic maxpat
2012-08-08 05:48:40 Thank's ! I tried it and i worked 1 time ! I have to figure out why !
1 question : AT+CSCA is mandatory ?

Max
userHeadPic maxpat
2012-08-08 03:02:17 Here's a sketch for using GSM shield and a button to send message to the target phone.
This is the beta version.

[code]

// #
// # Date      : 07.08.2012
// # Version    : Beta
// # Compatible with the Arduino IDE 1.0

// # Description:
// # The sketch for sending message by using GSM/GPRS/GPS shield
// #


#define S_PIN 8 //set the pin ,you can change according you situation;

char CMD_SetMess[]="AT+CMGF=1";  // for more details about the command meaning, please search in the AT command document
char CMD_SetMessCenter[]={'A','T','+','C','S','C','A','=','"','1','3','8','0','0','2','1','0','5','0','0','"'};
//set China Mobile SMS center number;you can change according actual situation ,Here we take Shanghai as an example .
char CMD_SendMessage[]= {'A','T','+','C','M','G','S','=','"','1','0','0','8','6','"'};
    //set the target phone Number - e.g. AT+CMGS="133911xxxxx"
char Message_Con[]="Test message from DFrobot!";//The content of message;
byte gsmDriverPin[3] = {3,4,5};

void setup()
{
  Serial.begin(19200);
  InitGsmMode();          // Initial Gsm-Module
  Serial.println("AT");  // Init serial to Gsm shield
  delay(200);
  Serial.print(CMD_SetMess);
  Serial.write(0x0D);
  Serial.print(CMD_SetMessCenter);
  Serial.write(0x0D);
  delay(20);
 
}
void loop()
{
  if(digitalRead(S_PIN)==HIGH)  // use a button to trigger the function and send the message
  {
    delay(20);// To eliminate jitter
    if(digitalRead(S_PIN)==HIGH)    // if pressed the button, run the next step
    {
      while(digitalRead(S_PIN)==HIGH);  // if released the button, run the next step
      Serial.print(CMD_SendMessage);
      Serial.write(0x0D);
      Serial.print(Message_Con);
      Serial.write(0x1A);
    }
  }
  delay(200);
}
//-----------------Initial GSM Module Part---------------//
void InitGsmMode()
{
  for(int i = 0 ; i < 3; i++)
  {
    pinMode(gsmDriverPin[i],OUTPUT);
  }
  digitalWrite(3,LOW);//Enable the GSM mode
  digitalWrite(4,HIGH);//Disable the GPS mode
  digitalWrite(5,HIGH);
  delay(1500);
  digitalWrite(5,LOW);
  delay(1500);
}
[/code]
userHeadPic Lauren
2012-08-08 03:02:17 Here's a sketch for using GSM shield and a button to send message to the target phone.
This is the beta version.

[code]

// #
// # Date      : 07.08.2012
// # Version    : Beta
// # Compatible with the Arduino IDE 1.0

// # Description:
// # The sketch for sending message by using GSM/GPRS/GPS shield
// #


#define S_PIN 8 //set the pin ,you can change according you situation;

char CMD_SetMess[]="AT+CMGF=1";  // for more details about the command meaning, please search in the AT command document
char CMD_SetMessCenter[]={'A','T','+','C','S','C','A','=','"','1','3','8','0','0','2','1','0','5','0','0','"'};
//set China Mobile SMS center number;you can change according actual situation ,Here we take Shanghai as an example .
char CMD_SendMessage[]= {'A','T','+','C','M','G','S','=','"','1','0','0','8','6','"'};
    //set the target phone Number - e.g. AT+CMGS="133911xxxxx"
char Message_Con[]="Test message from DFrobot!";//The content of message;
byte gsmDriverPin[3] = {3,4,5};

void setup()
{
  Serial.begin(19200);
  InitGsmMode();          // Initial Gsm-Module
  Serial.println("AT");  // Init serial to Gsm shield
  delay(200);
  Serial.print(CMD_SetMess);
  Serial.write(0x0D);
  Serial.print(CMD_SetMessCenter);
  Serial.write(0x0D);
  delay(20);
 
}
void loop()
{
  if(digitalRead(S_PIN)==HIGH)  // use a button to trigger the function and send the message
  {
    delay(20);// To eliminate jitter
    if(digitalRead(S_PIN)==HIGH)    // if pressed the button, run the next step
    {
      while(digitalRead(S_PIN)==HIGH);  // if released the button, run the next step
      Serial.print(CMD_SendMessage);
      Serial.write(0x0D);
      Serial.print(Message_Con);
      Serial.write(0x1A);
    }
  }
  delay(200);
}
//-----------------Initial GSM Module Part---------------//
void InitGsmMode()
{
  for(int i = 0 ; i < 3; i++)
  {
    pinMode(gsmDriverPin[i],OUTPUT);
  }
  digitalWrite(3,LOW);//Enable the GSM mode
  digitalWrite(4,HIGH);//Disable the GPS mode
  digitalWrite(5,HIGH);
  delay(1500);
  digitalWrite(5,LOW);
  delay(1500);
}
[/code]
userHeadPic Lauren
2012-08-07 09:56:33 Hi,
I just got this module, though mine says v2.1.
Attached this to an Arduino.
As soon as I plugged in the 12v supply to the Arduino, one of the capacitor on the GSM board sparked and smoked.
The ratings say that it is capable of handling 6-12v. Any issues reported on the new version boards?
Some advice here would be helpful as I have another 3 of these. Would like to know about any issues before plugging in any power supply.

Thanks,
Utsav
userHeadPic utsavdrolia
2012-08-07 09:56:33 Hi,
I just got this module, though mine says v2.1.
Attached this to an Arduino.
As soon as I plugged in the 12v supply to the Arduino, one of the capacitor on the GSM board sparked and smoked.
The ratings say that it is capable of handling 6-12v. Any issues reported on the new version boards?
Some advice here would be helpful as I have another 3 of these. Would like to know about any issues before plugging in any power supply.

Thanks,
Utsav
userHeadPic utsavdrolia
2012-08-06 23:02:25 Hi,

We're preparing the Arduino sketch for driving the GSM shield to send message. Tomorrow, I'll post the beta version sample. You could take a look.

;)
userHeadPic R2D2C3PO
2012-08-06 23:02:25 Hi,

We're preparing the Arduino sketch for driving the GSM shield to send message. Tomorrow, I'll post the beta version sample. You could take a look.

;)
userHeadPic R2D2C3PO
2012-08-06 13:06:37 Hi, I am trying to write a simple code to start using GSM function with my Arduino UNO. But without success...


[code]byte gsmDriverPin[3] = {
  3,4,5};
int test=0;

void setup(){
  InitGsmMode();
  Serial.begin(115200);    // I tried with 9600
  delay(500);
}

void InitGsmMode(){
  //Init the driver pins for GSM function
  for(int i = 0 ; i < 3; i++){
    pinMode(gsmDriverPin[i],OUTPUT);
  }

  digitalWrite(3,LOW);//Enable the GSM mode
  digitalWrite(4,HIGH);//Disable the GPS mode
  //Output GSM Timing
  digitalWrite(5,HIGH);  delay(1500);  digitalWrite(5,LOW); 
}

void loop()
{
    while (test<1) {
    Serial.println("waiting 5 s.");
    delay(5000);
    Serial.println("AT");delay(10000);

    SendTextMessage();
    Serial.println("Finished ?");
    test++;
    };
    Serial.println("End");
}

///SendTextMessage()      ///this function is to send a sms message
void SendTextMessage()
{
  Serial.write("AT+CMGF=1");Serial.write("\r");    //Because we want to send the SMS in text mode
  delay(5000);  // I put 5 s to be sure that the module has time to respond.
  Serial.write("AT + CMGS = \"098415719\"");Serial.write("\r");  //send sms message,
  delay(5000);
  Serial.write("A test message!");Serial.write("\r");//the content of the message
  delay(5000);
  Serial.write(0x1A);Serial.write("\r"); //the ASCII code of the ctrl+z is 26 - I tried also with print(char(26))
  delay(5000);
 
}
[/code]

I tried with write, print, println.. nothing happen, except that I get my command to the serial monitor.

Can you help me starting right ?

Thanks !
userHeadPic maxpat