Pages: [1]   Go Down
Author Topic: How to Print serial results from GPRS shield and GPS Shield with differnet pins?  (Read 584 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How to Print serial results from GPRS shield and GPS Shield with differnet pins?

Seeed Studios GPRS (SIM900) http://www.seeedstudio.com/depot/gprs-shield-p-779.html WIKI: http://www.seeedstudio.com/wiki/GPRS_Shield
PINS: 7-8
Sparkfun GPS Shield (EM-406) https://www.sparkfun.com/products/10710
PINS:2-3

I don't know if I'm doing this wrong, but by jumping the pins and following the sample sketches from each shield I was able to send the GPS coordinates to my Server(APACHE+MYSQL - see log below).

Code:
208.54.64.140 - - [05/Jan/2013:13:12:59 -0500] "GET /tracker.php?Lat=XX.XXXXX&Long=-XX.XXXXX&Speed=0.39&Cardinal=ESE&Altitude=318.80&Course=120.85 HTTP/1.1" 200 263 "-" "SIMCOM_MODULE"

The only issue I'm having is printing the return result from the GPRS shield to serial.
Sending the command AT+CSQ should return the following:

Code:
+CSQ: 12,0

OK


The result I get on serial is:
Code:
TURNING GPRS ON
Checking Status
AT+CGATT?

U:AT+CSQ

+CSQ: 12,0

OK
$GPGGA,183755.000,3359.9443,N,08Setting the SAPBR
Setting the APN
*Setting the SAPBR
Init HTTP request
Setting the httppara
Submit the request
Read data from website

Checking Status
AT+CGATT?

?vÚµÐ?±6Æ ³f?1c&3e?9ÅV?3Í?2c&e?,,2.2,1.0,1.9*30
$GPRMC,18381Setting the SAPBR
Setting the APN
*Setting the SAPBR
Init HTTP request
Setting the httppara
Submit the request
Read data from website

My code is:
Code:
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <String.h>
#include <PString.h>

/*****************************************
 * Buffers
 */
const int BUFFSIZE = 180;
char incoming_char = 0;
char buffer[BUFFSIZE];
PString myStr(buffer, sizeof(buffer));

#define RXPIN 2
#define TXPIN 3

//baud rate of GPS
#define GPSBAUD 4800
//baud rate of GPRS
#define GPRSBAUD 19200

// Create an instance of the TinyGPS object
TinyGPS gps;


SoftwareSerial uart_gps(RXPIN, TXPIN);


void getgps(TinyGPS &gps);


void setup()
{

  Serial.begin(GPRSBAUD);
  uart_gps.begin(GPSBAUD);
     
    Serial.println("S: TURNING GPRS ON");
    delay(4000);
}

void loop()
{
  while(uart_gps.available())     // While there is data on the RX pin...
  {
   
    int c = uart_gps.read();    // load the data into a variable...
    if(gps.encode(c))      // if there is a new valid sentence...
    {
      getgps(gps);         // then grab the data.

    }
  }

}

// The getgps function will get and print the values we want.
static void getgps(TinyGPS &gps)
{
  // Define the variables that will be used
  unsigned long age;
  float lat, lng, speed;
  // Then call this function
  gps.f_get_position(&lat, &lng);

  // Acquire data from gps
  gps.f_get_position(&lat, &lng, &age);
  speed = gps.f_speed_mph();



  Serial.println("Checking Status");
  uart_gps.println("U:AT+CSQ");
  delay(1000);

  //ShowSerialData();
  Serial.println("AT+CGATT?");
  ShowSerialData();
  uart_gps.println("AT+CGATT?");
  ShowSerialData();
  delay(1000);

  //ShowSerialData();
  Serial.println("Setting the SAPBR");
  uart_gps.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);

  //ShowSerialData();
  Serial.println("Setting the APN");
  uart_gps.println("AT+SAPBR=3,1,\"APN\",\"epc.tmobile.com\"");
  delay(2000);//4000

//ShowSerialData();
  Serial.println("*Setting the SAPBR");
  uart_gps.println("AT+SAPBR=1,1");
  delay(1000); //2000

//ShowSerialData();
  Serial.println("Init HTTP request");
  uart_gps.println("AT+HTTPINIT");

  delay(1000);  //2000
//ShowSerialData();
  Serial.println("Setting the httppara");

  myStr.print("AT+HTTPPARA=\"URL\",");
  myStr.print("\"www.cybercraft.org/");     
  myStr.print("tracker.php");
  myStr.print("?Lat="); 
  myStr.print(lat, DEC);
  myStr.print("&Long=");
  myStr.print(lng, DEC);
  myStr.print("&Speed="); 
  myStr.print(speed);
  myStr.print("&Cardinal="); 
  myStr.print(TinyGPS::cardinal(gps.f_course()));
  myStr.print("&Altitude=");
  myStr.print(gps.f_altitude());
  myStr.print("&Course=");
  myStr.print(gps.f_course());
  myStr.print("\"");

 // Serial.println(myStr); 
  uart_gps.println(myStr);
  delay(1000);

//ShowSerialData();
  Serial.println("Submit the request");
  uart_gps.println("AT+HTTPACTION=0");
  delay(5000);//Important delay

//ShowSerialData();
  Serial.println("Read data from website");
  uart_gps.println("AT+HTTPREAD");
  delay(300);

//ShowSerialData();
  Serial.println("");
  uart_gps.println("");
  delay(100);
  myStr.begin();

}

void ShowSerialData()
{

 while(uart_gps.available()!=0)
    Serial.write(uart_gps.read());
}
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the problem here is that you are using the hardware serial pins to communicate with your GPRS module (pins 1&2), correct? These pins are the same pins that connect to the USB module, which you are using for your debugging information. The Arduino has one hardware uart module and this connects to both the usb and pins 1&2, you would notice, for example, that if you sent data to your arduino via the usb and looked at the Rx pin (1) on an oscilloscope, you would see the bits as they are sent, you can also put a wire connecting pin 1&2 anything you send from the pc will echo straight back to the pc, as the data comes from the Rx pin, but this is connected directly to the Tx pin, so the data gets sent there as well.
I think you'll either have to use a software serial port for the GPRS sheild or stop using the hardware serial for debugging.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your help, I end up finding the solution using this sketch for xbee+gps changing the xbee to my GPRS specs.

http://my.safaribooksonline.com/book/hardware/arduino/9781449321185/discussion/id3260287#X2ludGVybmFsX0h0bWxWaWV3P3htbGlkPTk3ODE0NDkzMjExODUlMkZpZDMyNjAyODcmcXVlcnk9
Logged

Pages: [1]   Go Up
Jump to: