1

I'm using a MG2639 Cell Module with the SMS and GPS functionality. I have a sketch that sends through SMS the location of the arduino UNO.

This is my code:

#include <SoftwareSerial.h> //to communicate with mg2639 cell module.
#include <SFE_MG2639_CellShield.h> //basic librarie of the module.
#include <AltSoftSerial.h>   //to communicate with the GPS module
#include <TinyGPS++.h>    //to acquire the NMEA codes.

TinyGPSPlus gps;

AltSoftSerial ALTS(9, 8);
char celprim[11]="4423337388";
uint8_t GPStatus=0;
long temp=0;

 void configurado()
{
  sms.start(celprim);
  sms.print("Transmitiendo GPS Tracking....");
  sms.send();
  delay (6000);
}

     void GPSTracking()
{
   do
      {
        if (ALTS.available()>0)
          if (gps.encode(ALTS.read())) 
      {
        if (gps.date.isValid() && gps.location.isValid() && gps.time.isValid()){
          sms.start(celprim); 
          sms.print("Fecha/Hora/Ubicacion: ");
          sms.print(gps.date.day());
          sms.print("-");
          sms.print (gps.date.month());
          sms.print("-");
          sms.print(gps.date.year());
          sms.print(" ");
          if ((gps.time.hour()-5) < 10) sms.print("0");
          sms.print(gps.time.hour()-5);
          sms.print(":");
          if (gps.time.minute() < 10) sms.print("0");
          sms.print(gps.time.minute());
          sms.print(":");
          if (gps.time.second() < 10) sms.print("0");
          sms.print(gps.time.second());
    sms.print("https://www.google.com.mx/maps/dir/19.4161748,-99.1664011/");
          sms.print(gps.location.lat(), 6);
          sms.print(",");
          sms.print(gps.location.lng(), 6);
          sms.print("/@");
          sms.print(gps.location.lat(), 6);
          sms.print(",");
          sms.print(gps.location.lng(), 6);
          sms.print(",19z");
          sms.send();
          GPStatus=1;
        }
    }
      if ((millis()-temp) > 30000 && GPStatus==0)
      {
        GPStatus=1;
        sms.start(celprim);
        sms.print("Imposible ubicar equipo, intente mas tarde...");
        sms.send();        
      }
    }while (GPStatus ==0);
}

void setup()
{
  delay (5000);
  int beginStatus = cell.begin();
  if (beginStatus <= 0)
  {
     while(1)
      ;
  }
  delay (10000);
  sms.setMode(SMS_TEXT_MODE);   //Se pone al modulo en modo de recepción y envio de sms
  ALTS.begin(115200); // Or whatever rate the GPS uses
  configurado();
}

void loop()
{ 
  if (GPStatus==0)
  {
    temp = millis();
    GPSTracking();
  }
}

Is it possible to use only AltSoftSerial to create 2 serial ports and communicate with both cell and GPS in order to reduce program storage and global variables space? If it's possible, what changes should do in the MG2639 library to make it work? Or what could i do to reduce space.

1

Is it possible to use only AltSoftSerial to create 2 serial ports and communicate with both cell and GPS in order to reduce program storage and global variables space?

The question is a little vague.

AltSoftSerial only works on pins 8 & 9, so I thought you were asking if you could connect both the cell and the GPS to pins 8 & 9 (using jumper pads on the back of the board), and use one AltSoftSerial instance to talk to both devices. If it were possible, this would save RAM (just one instance) and program space (you wouldn't need two link in another software serial class, like SoftwareSerial). However, this is not possible. Serial connections are always point-to-point. Although two "things" can listen to one RX line, the TX line cannot be shared by two devices.

If you were asking if you can have two instances of AltSoftSerial on two separate pairs of pins (e.g., 2/3 and 8/9), the answer is again "No", because... AltSoftSerial only works on pins 8 & 9. Also, the SparkFun library only uses SoftwareSerial to talk to the cell.

what could i do to reduce space.

Use NeoGPS instead, and use the F macro around double-quoted strings that you print:

    sms.print( F("Imposible ubicar equipo, intente mas tarde...") );

That will save several hundred bytes of RAM.

Also, you may be sending multiple SMS's per second. It depends on what sentences the GPS emits. As it is, your sketch will send one SMS per sentence (i.e., one for each encode). Even if you don't use NeoGPS, look at the example program NMEAloc.ino et al for the correct program structure. The Troubleshooting section also contains some tips.

6
  • Huh? It sounds like the original poster already knows that serial connections are point-to-point. Also, he's using the MG2639 Cellular Shield, which connects the "cell module" to Arduino pins 2 and 3; and the "GPS module" to pins 8 and 9, so I don't know why you brought up "shared by 2 devices". – David Cary Jun 11 '16 at 11:37
  • @DavidCary, do you think he means two instances of AltSoftSerial? I thought he meant one instance shared by two devices. This board has jumper pads on the back that allow you to connect the devices to other pins. And because they default to being on two separate ports (2/3 and 8/9), I thought he wanted to wire them both to 8/9, the only port that AltSoftSerial supports. I'll clarify. – slash-dev Jun 11 '16 at 14:59
  • Ok, didn't know AltSoftSerial can only be used at 8/9 pins. What I intend with this project is send an SMS to the MG2639 asking its location, so only in that moment it will acquire a valid GPS fix and reply it with a SMS. So i dont need to be listening the GPS port all the time. My first sketch was using the hardware serial (0/1 pins) but i didnt get a valid fix, thats why i end up using AltSoft. Meanwhile i'll try to use NeoGPS but i'm not very skilled so it looks a little complex – Israel Gonzalez Jun 11 '16 at 15:20
  • Yes, NeoGPS is definitely more complex under-the-hood, but I've recently simplified the examples and improved the docs. BTW, using pins 0/1 for the GPS would be the most efficient and reliable, but I'm not sure what steps need to be taken on the UNO. The UNO's USB-to-Serial converter is also attached to 0/1. Three things (UNO, converter & GPS) cannot share pins 0/1. There might be a way keep the converter from interfering with UNO-GPS comms: disconnect the USB cable? Scratch out a trace? Regardless, AltSoftSerial is a good alternative, and that's why they connected the GPS to 8/9. – slash-dev Jun 11 '16 at 15:56
  • @slash-dev, yes, I think he means two instances of AltSoftSerial or two instances of SoftwareSerial, kind of like how "How to utilize multiple software serial in libraries in Arduino?" uses several instances of SoftwareSerial for the Arduino to communicate to three other devices. – David Cary Jun 12 '16 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.