Interfacing with a SIM908 Shield

Hi everyone,

This is my first post. I want to send GPS location via SMS with "GSM-GPRS-GPS Shield" using the SIM908 module.

Arduino that I'm using (arduino uno R3 SMD):

Shield that I'm using:

http://www.waveshare.com/wiki/GSM/GPRS/GPS_Shield_User_Manual

What' I have done:

I know that the shield work properly (Sending SMS/ Get GPS) because I used the software TCP232 (provided) that allowed me to send AT command to the SIM908 and I succeed, so that's not the problem.
The documentation provided is adapted for an older version of this shield so the hardware connection instructions are not adapted to the new shield.(documents are accessible here: http://www.waveshare.com/wiki/GSM/GPRS/GPS_Shield). Indeed, they told us to connect:

GSM EN -> D2
GPS EN -> D3

And the code provided is:

double Datatransfer(char *data_buf,char num)//convert the data to the float type
{                                           //*data_buf£ºthe data array                                       
  double temp=0.0;                           //the number of the right of a decimal point
  unsigned char i,j;
 
  if(data_buf[0]=='-')
  {
    i=1;
    //process the data array
    while(data_buf[i]!='.')
      temp=temp*10+(data_buf[i++]-0x30);
    for(j=0;j<num;j++)
      temp=temp*10+(data_buf[++i]-0x30);
    //convert the int type to the float type
    for(j=0;j<num;j++)
      temp=temp/10;
    //convert to the negative numbe
    temp=0-temp;
  }
  else//for the positive number
  {
    i=0;
    while(data_buf[i]!='.')
      temp=temp*10+(data_buf[i++]-0x30);
    for(j=0;j<num;j++)
      temp=temp*10+(data_buf[++i]-0x30);
    for(j=0;j<num;j++)
      temp=temp/10 ;
  }
  return temp;
}
 
char ID()//Match the ID commands
{ 
  char i=0;
  char value[6]={
    '

Note that they write:
digitalWrite(4,LOW);//Enable GPS mode
digitalWrite(3,HIGH);//Disable GSM mode

But it can't work for me by connecting GSM EN to D2 and GPS EN to D3.

When I connect GSM EN to D3 I can easily send/read an SMS but I really don't know how to connect GPS EN to visualize GPS weft (even when I connect GPS RX ->DUINO TX and GPS TX -> DUINO RX or when I connect GPS EN->D2/D4).

This is my code that allow me to send an SMS and, hope so, configure the GPS:

char inChar;
int index;
char inData[200];

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup()
{
 //Init the driver pins for GSM function
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);

 //Output GSM Timing 
 digitalWrite(5,HIGH);
 delay(1500);
 digitalWrite(5,LOW); 

 Serial.begin(9600);
 
 digitalWrite(3,LOW);//enable GSM TX、RX
 digitalWrite(4,HIGH);//disable GPS TX、RX

 delay(20000);

 start_GSM();

 delay(5000);

 //start_GPS();
 Serial.println("AT+CMGS=\"+336XXXXXXXX\"");
 delay(1000);
 Serial.print("My GPS doesn't work");
 delay(1000);
 Serial.write(26);
 delay(5000);

 Serial.println("AT+CGPSPWR=1");
 Serial.println("AT+CGPSRST=1");
 //Serial.println("AT+CGPSIPR=115200");
 delay(5000);

 digitalWrite(4,LOW);
 digitalWrite(3,HIGH);
 inputString.reserve(200);
}
void loop()    
{    
 Serial.println("AT+CGPSINF=0");
 delay(2000);

 if (stringComplete) {
 Serial.println(inputString); 
 // clear the string:
 inputString = "";
 stringComplete = false;

 }

}

void serialEvent() {
 while (Serial.available()) {
 // get the new byte:
 char inChar = (char)Serial.read(); 
 // add it to the inputString:
 inputString += inChar;
 // if the incoming character is a newline, set a flag
 // so the main loop can do something about it:
 if (inChar == '\n') {
 stringComplete = true;
 } 
 }
}

void start_GSM(){
 //Configuracion GPRS Claro Argentina
 Serial.println("AT");
 delay(2000);
 Serial.println("AT+CREG?");
 delay(2000);
}

I've spent a very long time on google/ waveshare/ arduino forum to find a solution but I failed.,'G','P','G','G','A'      };
 char val[6]={
   '0','0','0','0','0','0'      };

while(1)
 {
   if(Serial.available())
   {
     val[i] = Serial.read();
     if(val[i]==value[i])
     {    
       i++;
       if(i==6)
       {
         i=0;
         return 1;
       }
     }
     else
       i=0;
   }
 }
}

void comma(char num)
{  
 char val;
 char count=0;

while(1)
 {
   if(Serial.available())
   {
     val = Serial.read();
     if(val==',')
       count++;
   }
   if(count==num)
     return;
 }

}
void UTC()//get the UTC data -- the time
{
 char i;
 char time[9]={
   '0','0','0','0','0','0','0','0','0'
 };
 double t=0.0;

if( ID())//check ID
 {
   comma(1);//remove 1 ','
   
   while(1)
   {
     if(Serial.available())
     {
       time[i] = Serial.read();
       i++;
     }
     if(i==9)
     {
       i=0;
       t=Datatransfer(time,2);
       t=t-30000.00;
       long time=t;
       int h=time/10000;
       int m=(time/100)%100;
       int s=time%100;

if (h<0)               //UTC-
       {
         h+=24;
       }
       Serial.print(h);
       Serial.print("h");
       Serial.print(m);
       Serial.print("m");
       Serial.print(s);
       Serial.println("s");

return;
     }  
   }
 }
}
void latitude()//get latitude
{
 char i;
 char lat[10]={
   '0','0','0','0','0','0','0','0','0','0'
 };

if( ID())
 {
   comma(2);
   while(1)
   {
     if(Serial.available())
     {
       lat[i] = Serial.read();
       i++;
     }
     if(i==10)
     {
       i=0;
       Serial.println(Datatransfer(lat,5)/100.0,7);
       return;
     }  
   }
 }
}
void lat_dir()//get dimensions
{
 char i=0,val;

if( ID())
 {
   comma(3);
   while(1)
   {
     if(Serial.available())
     {
       val = Serial.read();
       Serial.write(val);
       Serial.println();
       i++;
     }
     if(i==1)
     {
       i=0;
       return;
     }  
   }
 }
}
void longitude()//get longitude
{
 char i;
 char lon[11]={
   '0','0','0','0','0','0','0','0','0','0','0'
 };

if( ID())
 {
   comma(4);
   while(1)
   {
     if(Serial.available())
     {
       lon[i] = Serial.read();
       i++;
     }
     if(i==11)
     {
       i=0;
       Serial.println(Datatransfer(lon,5)/100.0,7);
       return;
     }  
   }
 }
}
void lon_dir()//get direction data
{
 char i=0,val;

if( ID())
 {
   comma(5);
   while(1)
   {
     if(Serial.available())
     {
       val = Serial.read();
       Serial.write(val);
       Serial.println();
       i++;
     }
     if(i==1)
     {
       i=0;
       return;
     }  
   }
 }
}
void altitude()//get altitude data
{
 char i,flag=0;
 char alt[8]={
   '0','0','0','0','0','0','0','0'
 };

if( ID())
 {
   comma(9);
   while(1)
   {
     if(Serial.available())
     {
       alt[i] = Serial.read();
       if(alt[i]==',')
         flag=1;
       else
         i++;
     }
     if(flag)
     {
       i=0;
       Serial.println(Datatransfer(alt,1),1);
       return;
     }  
   }
 }
}
void setup()
{
 pinMode(3,OUTPUT);//The default digital driver pins for the GSM and GPS mode
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
 digitalWrite(5,HIGH);
 delay(1500);
 digitalWrite(5,LOW);

digitalWrite(3,LOW);//Enable GSM mode
 digitalWrite(4,HIGH);//Disable GPS mode
 delay(2000);
 Serial.begin(9600);
 delay(5000);

Serial.println("AT");  
 delay(2000);
 //turn on GPS power supply
 Serial.println("AT+CGPSPWR=1");
 delay(1000);
 //reset GPS in autonomy mode
 Serial.println("AT+CGPSRST=1");
 delay(1000);

digitalWrite(4,LOW);//Enable GPS mode
 digitalWrite(3,HIGH);//Disable GSM mode
 delay(2000);

Serial.println("$GPGGA statement information: ");
}
void loop()
{
 while(1)
 {
   Serial.print("UTC:");
   UTC();
   Serial.print("Lat:");
   latitude();
   Serial.print("Dir:");
   lat_dir();
   Serial.print("Lon:");
   longitude();
   Serial.print("Dir:");
   lon_dir();
   Serial.print("Alt:");
   altitude();
   Serial.println(' ');
   Serial.println(' ');
 }
}


Note that they write:
digitalWrite(4,LOW);//Enable GPS mode
digitalWrite(3,HIGH);//Disable GSM mode

But it can't work for me by connecting GSM EN to D2 and GPS EN to D3.

When I connect GSM EN to D3 I can easily send/read an SMS but I really don't know how to connect GPS EN to visualize GPS weft (even when I connect GPS RX ->DUINO TX and GPS TX -> DUINO RX or when I connect GPS EN->D2/D4).

This is my code that allow me to send an SMS and, hope so, configure the GPS:

§DISCOURSE_HOISTED_CODE_1§


I've spent a very long time on google/ waveshare/ arduino forum to find a solution but I failed.

Right, in my usual way I'll probably miss out some crucial steps but let's start with this:

Just define the pins

# define GSM_Mode 2
# define GPS_Mode 3
# define powerPin 16 // A2

Put it GSM mode

digitalWrite(GSM_Mode,LOW);  //Enable GSM mode
digitalWrite(GPS_Mode,HIGH); //Disable GPS mode

Now we can write to the SIM908.

Send the commands to turn the GPS on:

AT+CGPSPWR=1
AT+CGPSRST=1
AT+CGPSIPR=115200

And then set to receive GPS data:

digitalWrite(GPS_Mode,LOW);  //Enable GPS mode
digitalWrite(GSM_Mode,HIGH); //Disable GSM mode

Obviously as the shield uses pins D0 & D1 to talk to the Arduino you cannot use them for Serial Monitor. I use a CP2102 based USB -> UART device and set up a software serial connection to use Serial Monitor.

Hi dannable,

Thank you for your answer. I can configure as you said but is there a simple way to be sure that I configured well the GPS MODE? Maybe a serialEvent() with a blinking LED?

This is my code:

# define GSM_Mode 2
# define GPS_Mode 3
# define powerPin 16 // A2

void setup()
{
	//Init the driver pins for GSM function
	pinMode(2,OUTPUT);
	pinMode(3,OUTPUT);
	pinMode(5,OUTPUT);

	//Output GSM Timing 
	digitalWrite(5,HIGH);
	delay(1500);
	digitalWrite(5,LOW); 

	Serial.begin(115200);

	digitalWrite(GSM_Mode,LOW);//enable GSM TX、RX
	digitalWrite(GPS_Mode,HIGH);//disable GPS TX、RX

	delay(2000);

	Serial.println("AT+CMGS=\"+33673791674\"");
	delay(1000);
	Serial.print("My GPS doesn't work");
	delay(1000);
	Serial.write(26);
	delay(5000);

	Serial.println("AT+CGPSPWR=1");
	Serial.println("AT+CGPSRST=1");
	Serial.println("AT+CGPSIPR=115200");
	delay(5000);

	digitalWrite(GPS_Mode,LOW);
	digitalWrite(GSM_Mode,HIGH);
}
void loop()    
{    
	Serial.println("AT+CGPSINF=0");
	delay(2000);
}

Thanks,

Renaud