Hello,
I have been working on a Car Tracking System using a Tiny GPS, the SIM900 Quad-Band GPRS Shield w/ Micro SD Slot, and the Arduino Uno. I have been able to send a text to a designated phone number using this code:
/*Note:This code is used for Arduino 1.0 or later*/
#include <SoftwareSerial.h>
SoftwareSerial Sim900Serial(2, 3);
void setup()
{
Sim900Serial.begin(115200); // the GPRS baud rate
delay(500);
Sim900Serial.println("AT+IPR=19200");
delay(500);
Sim900Serial.begin(19200); // the GPRS baud rate
delay(1000);
Serial.begin(9600); // the Hardware serial rate
Serial.println("Please type 's' to send SMS");
}
void loop()
{
if (Serial.available())
switch(Serial.read())
{
case 's':
SendTextMessage();
break;
}
if (Sim900Serial.available())
Serial.write(Sim900Serial.read());
}
void SendTextMessage()
{
Sim900Serial.print("AT+CMGF=1\r"); //Sending the SMS in text mode
delay(100);
Sim900Serial.println("AT + CMGS = \"***********\"");//The target phone number
delay(100);
Sim900Serial.println("hello");//the content of the message
delay(100);
Sim900Serial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
Sim900Serial.println();
}
And I have also been able to locate the position of the GPS using this code:
#include <TinyGPS.h>
#include <SoftwareSerial.h>
SoftwareSerial GPS(2, 3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
void getGPS();
bool feedgps();
long lat, lon;
unsigned long fix_age;
float LAT, LON;
void setup()
{
GPS.begin(9600);
Serial.begin(115200);
}
void loop()
{
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.get_position(&lat, &lon, &fix_age);// retrieves +/- lat/long in 100000ths of a degree
// time in hh:mm:ss, date in dd/mm/yy
/*gps.get_datetime(&date, &time, &fix_age);
year = date % 100;
month = (date / 100) % 100;
day = date / 10000;
hour = time / 1000000;
minute = (time / 10000) % 100;
second = (time / 100) % 100;
Serial.print("Date: ");
Serial.print(year); Serial.print("/");
Serial.print(month); Serial.print("/");
Serial.print(day);
Serial.print(" :: Time: ");
Serial.print(hour); Serial.print(":");
Serial.print(minute); Serial.print(":");
Serial.println(second);
*/
getGPS();
Serial.print("Latitude : ");
Serial.print(LAT/100000,7);
Serial.print(" :: Longitude : ");
Serial.println(LON/100000,7);
}
void getGPS()
{
bool newdata = false;
unsigned long start = millis();
// Every 1 seconds we print an update
while (millis() - start < 1000)
{
if (feedgps ())
{
newdata = true;
}
if (newdata)
{
gpsdump(gps);
}
}
}
bool feedgps()
{
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}
return 0;
}
void gpsdump(TinyGPS &gps)
{
//byte month, day, hour, minute, second, hundredths;
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
{
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
}
}
The problem we are having is with everything else. When we try to use the sample code provided by Arduino to receive a text message from the phone number and display it on the Serial Monitor it only outputs this:
SMS Messages Receiver
GSM initialized
Waiting for messages
/*
SMS receiver
This sketch, for the Arduino GSM shield, waits for a SMS message
and displays it through the Serial port.
Circuit:
* GSM shield attached to and Arduino
* SIM card that can receive SMS messages
created 25 Feb 2012
by Javier Zorzano / TD
This example is in the public domain.
http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
*/
// include the GSM library
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retreived from
char senderNumber[20];
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS Messages Receiver");
// connection state
boolean notConnected = true;
// Start GSM connection
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
void loop()
{
char c;
// If there are any SMSs available()
if (sms.available())
{
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
// An example of message disposal
// Any messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
while(c=sms.read())
Serial.print(c);
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}
**UPDATE: I just ran the program again to see what it output to the Serial Monitor and it actually ran through all the way and printed like 10 messages we sent it a couple of days ago. So, we tried sending another message just now and it has gone back to only printing those first three lines...
I'm not sure why it is doing this? I would assume it isn't a software issue, being as the code is a publicly used code known to work for the Arduino. It also has worked for us in sending messages to our phone and OCCASSIONALLY receiving messages and printing them to the Serial Monitor. So, to me that doesn't seem like a hardware or software problem...
If anyone can give me any insight in to what my issue might be that would be great! Thanks!