Question

I am trying to make my arduino work with a gps and a gprs shield. So far so good. My code works when I have the commented lines commented and stops working if I uncomment them.

Even earlier events fail. For example I must take output GPRS Registered and GPRS AT Ready but it does not happen.

Is there a chance that my arduino is damaged?

Here is the code.

Note that I tested the commands I send to the gprs shield with the actual shield and it works.

#include <SoftwareSerial.h>
#include <TinyGPS.h>

#define BUFFSIZ 90

int GPRS_Registered;
int GPRS_AT_Ready;

char incoming_char = 0;
char buffidx;
char at_buffer[BUFFSIZ];

int firstLoop = 1;

TinyGPS gps;
SoftwareSerial cell(2,3);
SoftwareSerial uart_gps(0,1);

void sendSMS(char *msg){
  cell.println("AT+CMGF=1");
  cell.print("AT+CMGS=");
  cell.write(34);
  cell.print("A number here");
  cell.write(34);
  cell.println("");
  delay(500);
  cell.println(msg);
  cell.write(26);
  delay(15000);
}

void readATString(){
  char c;
  buffidx = 0;

  while(true){
    if(cell.available() > 0){
      c = cell.read();
      if(c == -1){
        at_buffer[buffidx] = '\0';
        return;
      }

      if(c == '\n'){
        continue;
      }

      if((buffidx == BUFFSIZ - 1) || (c == '\r')){
        at_buffer[buffidx] = '\0';
        return;
      }

      at_buffer[buffidx++] = c;
    }
  }
}

void processATString(){
  if(strstr(at_buffer, "+SIND: 8") != 0){
    GPRS_Registered = 0;
    Serial.println("GPRS Network Not Available");
  }

  if(strstr(at_buffer, "+SIND: 11") != 0){
    GPRS_Registered = 1;
    Serial.println("GPRS Registered");
  }

  if(strstr(at_buffer, "+SIND: 4") != 0){
    GPRS_AT_Ready = 1;
    Serial.println("GPRS AT Ready");
  }


}

void setup(){
  Serial.begin(115200);

  cell.begin(9600);
  uart_gps.begin(4800);

  cell.listen();
  Serial.println("Starting SM5100 Communication...");

  delay(5000);
}


void loop(){
  bool dataReady = false;
  unsigned long chars, prev_chars = 0;
  unsigned short sentences, failed;

  if(firstLoop){
    firstLoop = 0;
    while(GPRS_Registered == 0 || GPRS_AT_Ready == 0){
      readATString();
      processATString();
    }
    Serial.println("Everything is working");
  }

  uart_gps.listen();
  for (unsigned long start = millis(); millis() - start < 1000;){
    while (uart_gps.available()){
      char c = uart_gps.read();
      if (gps.encode(c))
        dataReady = true;
    }
  }

  if (dataReady)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("flat: ");
    Serial.print(flat, 6);
    Serial.print("flon: ");
    Serial.println(flon, 6);

    cell.listen();

      // HERE IS THE PROBLEM
//    cell.println("AT+CGDCONT=1,\"IP\",\"internet\"");
//    delay(3000);
//    cell.println("AT+CGACT=1,1");
//    delay(3000);
//    cell.println("AT+SDATACONF=1,\"TCP\",\"my.server.com\",8080");
//    delay(3000);
//    cell.println("AT+SDATASTART=1,1");
//    cell.println("AT+SSTRSEND=1,\"testing arduino gprs\"");


    Serial.println("Sent data to server");

  }
}
Was it helpful?

Solution

I would connect the shield TX and RX to the PC's serial port directly and then manually issue the commands and see the responses. As the responses will illuminate your problem and solution. This can be done simply by a few jumps on the Arduino

  1. jump RST to GND
  2. jump 0 to 2 and 1 to 3. ( i might have that backwards 0 to 3 and 1 to 2.)

The RST shuts down the ATmega328 and the others jump the TX/RX to between the Cell device and the bases FTDI chip to the PC's USB serial port.

If you use Arduino's IDE serial monitor, take note to set the LineFeed correctly.


You are trying to use Three devices:

  1. SoftwareSerial cell(2,3);
  2. SoftwareSerial uart_gps(0,1);
  3. Serial.Print

Where you are only actually using 2 pairs of Tx and Rx pins, not 3 pair. Note that the Serial Class is already defined by the Arduino Core to use the Hardware UART on pins 0 and 1. But yet you are defining a SoftwareSerial (aka UART) on 0,1 for the GPS. Hence two things using the same pins - problem.

The SMS work initial as the uart_gps.begin disable the hardware uart used by Serial.begin. So your cell.prints work. But then your Serial.prints conflict with your uart_gps and things go bad.

Not sure of your exact symptoms but one needs to clear up the resource issues first. Looking at the GPS and GPRS shields I see move are selectable as you state between 0,1 and 2,3. Where 0,1 is to do my original suggestion of jamming the Arduino CPU into RESET, which then tri-states is use of pins 0 and 1, allowing the Shield when selected to 0,1 to route the radio's uart to the FTDI for direct PC control. Whereas this can be used to the Arduino's CPU but then the FTDI needs to be in Tristate.

The solution is some jumpers on the shield, to use pins other than 0,1 to unused pins and move the corresponding SoftwareSerial to those pins. While making sure the 0,1 pins are not connected between shields, likely bending them away when stacked.

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