Tracking Solution - uC, GPS, GSM and SD Card

Hi,

Background: I need to assemble a solution which is to have a Microcontroller (uC), SD Card, GSM, GPS and Temperature sensor. Till now, I have coupled an Arduino Uno Shield with Adafruit GSM Shield (GSM + SD).

The program compares the real-time GPS coordinates with the reference coordinates on SD card and outputs red/ green LED output based on deviation (later, this is to be replaced by SMS option - to be sent based on any deviation). On compiling my program I see the following message (pls. note: for now, program is running fine - shows red/ green deviation LED output):

Sketch uses 24,038 bytes (74%) of program storage space. Maximum is 32,256 bytes. Global variables use 1,576 bytes (76%) of dynamic memory, leaving 472 bytes for local variables. Maximum is 2,048 bytes. Low memory available, stability problems may occur.

Question/ Request for Guidance: However, my concern is that going ahead I need to couple GSM (for SMS) and Analog sensor. Is it feasible - given the memory consumption above. If not, what precautions do I need to take to ensure that I can add GSM/ which GSM component should I choose.

Regards

Your sketch may work fine, depending on how much run-time stack space it needs. The TinyGPS library example "test_wit_gps_device" only uses 14,478 bytes of FLASH and 1,022 bytes of SRAM. The SD library example "Datalogger" uses 13,976 bytes of FLASH and 923 bytes of SRAM. I guess it makes sense that your sketch uses a lot of both.

You may have to find smaller libraries or switch to a larger Arduino like the MEGA. It would be easier to provide useful advice if we could see your sketch.

Thanks johnwasser.

I understand that either of the two a) TinyGPS or b) Arduino MEGA is the solution.

Just going one step ahead, my aim is to finally bundle all the above functionality into a wearable device. Can you pls. guide me on what can be a better set of components for such a wearable solution that includes:

  1. Microcontroller,
  2. SD Card,
  3. GPS,
  4. GSM and
  5. temp/ pulse sensor

I welcome other contributors too willing to suggest a possible solution.

Regards

There are combined GSM/GPRS/GPS modules. That should help reduce size.

Maybe you can find small-format Arduino clone with a processor larger than the 328P, like the 644 or 1280 or 2560.

The TinyGPS library example “test_with_gps_device” only uses 14,478 bytes of FLASH and 1,022 bytes of SRAM.

FWIW, only 180 bytes of RAM are used by the TinyGPS library. The rest is “string” literals, printing buffers and other system RAM.

For the FLASH usage, about 2,400 bytes are for TinyGPS. The rest is the app code and all the system code.

You may have to find smaller libraries…

:smiley: If you are up to trying a different library, you could try NeoGPS. I’ve been pitching this for a few months as an alternative for resource-constrained environments (i.e., lots of devices and lots of processing). It is very configurable, and it should work with any GPS brand. There’s also special code for ublox devices, but you probably won’t need it.

It’s more complicated to understand, but it will only use 40 bytes of RAM and 2800 bytes of FLASH when configured like TinyGPS. If you only need Date, Time and Location from GPS, you can configure it to use 25 bytes of RAM and 2100 bytes of FLASH. It’s also about 40% faster.

I’ve only had one other person try it (that I know of), so the install instructions may not be good enough for all levels of Arduino user. If you do try it and have problems, please let me know and I’ll be glad to help. And fix the docs or (gasp) code. :wink:

I’ve built an app with GPS, analog sensor and SD, and it was 15-20K flash and <1k RAM, even with debug code. That’s without floating point math, which will add 5K-8K. Adding the GSM doesn’t seem like it would add more than a few K, but it really depends on the library. So I think what you’re trying to do would probably fit in a 328.

RAM is certainly no problem if you’re careful. NeoGPS alone would save 155 bytes. I suspect you need to look into using the F macro around “string” literals, and reducing your globals and/or static buffers and arrays. Some variables could probably be const, too. Seems like SD has to use at least 512 bytes RAM, as it has to buffer the writes to the card.

Cheers,
/dev

Thanks johnwasser & /dev.

johnwasser - I will try finding a component that has GSM, GPS & SP card coupled into one. Meanwhile, any product that you can readily recall

Regards

Look for SIM908. GSM/GPRS and GPS all in one.

Thanks dannable.

Finally, I picked up SIM900A - some local module. I am trying to sms…

2 days have passed by and I am still struggling to send sms with code (pls. ref below):

Serial.println(F("Trying to connect..."));
  theGSM3ShieldV1ModemCore.println(F("AT"));
  gsmAccess.begin("",true,false); //Use async mode and requires that GSM debug mode has been set on GSM object creation
  while(notConnected) 
  {
    int intGsmStatus = 0;
    gsmAccess.ready(); //Call this if debugging is on. Otherwise we will never reach GSM_READY...?!?
    delay(1000); //might not call ready too often.??? See GSM3ShieldV1AccessProvider.cpp, GSM3ShieldV1AccessProvider::begin
    intGsmStatus = gsmAccess.getStatus();
    if (intGsmStatus != GSM_READY){
      Serial.print(F("GSM status: "));
      Serial.println(intGsmStatus);
    } else {
      notConnected = false;
    }
  }
  
  if(notConnected)
    Serial.println(F("Error in connection"));
  else
    Serial.println(F("Connected to GSM network"));

!(http://\Macintosh HD\Users\santosh\Desktop\GSM Module.jpeg)
The output is:
Trying to connect…
AT%13%%10%AT%13%GSM status: 2
GSM status: 2

I understand status 2 stands for failure. The GSM module is couple to Arduino Uno (Flash 32 Kb).
Can someone please guide me on the reason of failure/ the changes I need to make…Meanwhile I will continue googling.

P.S.: FYR, attached herewith is my GSM module snapshot.

Regards

I don't have the bandwidth to download files that size.

Assuming that the SIM900A works in your country, try the link in my signature. It might help you get the device functioning.

Thanks Dannable,

I tried the code (below) from SeeedStudio link. In my case, it seems to be failing at SIM900.available(). I am attaching a smaller image of GSM Module (900a).
The connections are:
SIM900a(Tx) - Uno Rx
SIM900a(Rx) - Uno Tx
SIM900a(Gnd) - Uno Gnd and
a adapter cord 12v, 1A supply.

The code:

#include <SoftwareSerial.h>

char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);

int led = 10;

void setup()
{
  Serial.begin(19200);
  // set up the digital pins to control
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);

  // wake up the GSM shield
  SIM900.begin(19200);
  delay(20000); // give time to log on to network.
  SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
  Serial.println("Ready...");
}

void loop()
{
  //If a character comes in from the cellular module...
  if(SIM900.available() >0)
  {
    Serial.println(F("sim available..."));
    inchar=SIM900.read();
    
    if (inchar=='#')
    {
      delay(10);

      inchar=SIM900.read();
      if (inchar=='a')
      {
        delay(10);
        inchar=SIM900.read();
        if (inchar=='0')
        {
          digitalWrite(led, LOW);
        }
        else if (inchar=='1')
        {
          digitalWrite(led, HIGH);
        }
        delay(10);
        // SIM900.println("AT+CMGD=1,4"); // delete all SMS
      }
    }
  }
  else 
  {
     Serial.println(F("sim not available..."));
  }
}

P.S.: When I call the phone#(SIM) on the GSM module, I hear the ring (simultaneously, the “RING” LED blinks on module) - that means the the number is dialling.

Where could I be going wrong.

Regards

Have you tried the earlier part of the page, just testing communication with the SIM900 with SerialRelay? There's no point trying to run a program if you can't communicate.

You're right Dannable; I skipped over some steps.

Now I see that GPRS.available() fails; GPRS is a SoftwareSerial object. I do have a GSM GPRS added in libraries folder. Pin connections were mentioned earlier: Rx-Tx, Tx-Rx, Gnd-Gnd & external supply 12v DC.

So, I'm stuck clueless. Indicators on GSM modules seem to be throwing right signals - network led blinks every 3 secs; ring led glows when I call the no.

Where am I be going wrong.

SoftwareSerial is working in other code files. Elsewhere, on AdafruitGPS, the serial object is working; just the declaration: *SoftwareSerial mySerial(8, 7); Adafruit_GPS GPS(&mySerial);

and, I am able to use GPS object.

Regards

First, if you are using more than one instance of SoftwareSerial you could have problems. But we’ll leave that for now.

All the functions you have described (call indicator, led flashing) indicates that the SIM900A is connecting to the cell phone network. The problem is that you can’t communicate with the SIM900A.

Disconnect everything from the Arduino. Upload the following sketch:

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);

unsigned char buffer[64];  // buffer array for data receive over serial port
int count=0;               // counter for buffer array 

void setup()
{
  GPRS.begin(19200);
  Serial.begin(19200);
}

void loop()
{
  if (GPRS.available())
  {
    while(GPRS.available())
    {
      buffer[count++]=GPRS.read();
      if(count == 64)break;
    }
    Serial.write(buffer,count);
    clearBufferArray();
    count = 0;
  }
  if (Serial.available())
    GPRS.write(Serial.read());
}

void clearBufferArray()
{
  for (int i=0; i<count;i++)
  {
    buffer[i]=NULL;
  }
}

Now connect SIM900A Rx to 8 and SIM900A Tx to 7. And ground to ground of course. And the USB cable from your computer. Apply power. Open serial monitor and set the baud rate to 19200.

Type AT and click ‘Send’. If you don’t get any response at all then swap Rx and Tx over.

Ok Dannable,

So, finally I am getting the AT and OK on serial window. I recognized that my Rx, Tx were connected to Pin 0, 1 Tx, Rx of Uno (and, an Adafruit was fixed atop Uno).

Moving ahead to next program on Seeedstudio page (sent by you), I change the baud rate to 9600. It runs and I see the “Ready…” message.

The serial.print(inchar) - bold text - in loop() prints the strings passed to SIM900 object (output below):

Ready...
AT+CMGF=1
AT+CNMI=2,2,0,0,0

OK

I don’t see how it will get #a1 value and act accordingly. In addition, I entered “#a1” on serial and send it but nothing happens - LED on Pin 10 of Uno and Serial.println message for each of loops (fyr, updated code below):

#include <SoftwareSerial.h>

char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);

int led = 10;

void setup()
{
  Serial.begin(9600);
  // set up the digital pins to control
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);

  // wake up the GSM shield
  SIM900.begin(9600);
  delay(20000); // give time to log on to network.
  SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
  Serial.println("Ready...");
}

void loop()
{
  //If a character comes in from the cellular module...
  if(SIM900.available() >0)
  {
    inchar=SIM900.read();
[b]    Serial.print(inchar);[/b]
    if (inchar=='#')
    {
      Serial.println("#");
      delay(10);

      inchar=SIM900.read();
      if (inchar=='a')
      {
        Serial.println("#a");
        delay(10);
        inchar=SIM900.read();
        if (inchar=='0')
        {
          Serial.println("#a0");
          digitalWrite(led, LOW);
        }
        else if (inchar=='1')
        {
          Serial.println("#a1");          
          digitalWrite(led, HIGH);
        }
        delay(10);
        // SIM900.println("AT+CMGD=1,4"); // delete all SMS
      }
    }
  }
}

Pls. Note.: My ultimate aim is to send sms. In that context There is one complication that needs to be handled - I have removed the Adafruit GPS shield, for now. But that can wait for now…

Regards

Have you tried sending an SMS '#a1' to the device? That should turn the led on, and conversely '#a0' turn it off. But that is receiving a message, not sending one.

Sending a text is a simple three stage process. Who to, what, and done!

GPRS.println("AT + CMGS = \"+447751123456\""); // Who to
delay(100);
GPRS.print("Hello world!"); // what
delay(100);
GPRS.println((char)26);//ctrl+z - done!

If I get it correctly, yes I did too. I sent message two separate messages: #a1 and #a0 (there were no quotes around #a1 message) to the SIM on GSMmodule.

Not seeing any LED, I took out the SIM in some time and put it on handset and yes, I did see the messages - they loaded once I put sim in the Handset.

In addition, I tried send message too, without any result...

Regards

Previously you said that you got had the net led blinking slowly, indicating that it had connected to the network. Was that the same on this occasion?

Just to ensure that all settings are fine, I ran a brief diagonistics:

  1. Checked that N/W is locked.
  2. Made a call to module’s SIM and saw the ring LED glow
  3. Finally, pushed reset button on module and waited for GSM module to lock again i.e. N/w led blinking at 3secs frequency.

I ran this code the send sms code below to destinationNumber:

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8);

String outMessage = "Hello world!";
String destinationNumber = "+91xxxxxxxx";

void setup()
{
  SIM900.begin(19200);
  delay(20000); // give time to log on to network.
  SIM900.print("AT+CMGF=1\r");
  delay(100);
  SIM900.println("AT + CMGS = \"" + destinationNumber +"\"");
  delay(100);
  SIM900.println(outMessage);
  delay(100);
  SIM900.println((char)26);//ctrl+z
  delay(100);
}

void loop()
{
}

I did not receive the sms on the destinationNumber SIM.

The code seems to be minimal. And, I had run the diagonistics (supposedly) successfully at the beginning. So puzzled about failure.

Regards

How long does it take until you get a 3 second blink from powering up?

about 5 seconds..it blinks at faster rate till then.

I replaced earlier SIM with another one. No luck yet...