Hello,
I'v recently ordered GPRS and GPS shield for my arduino UNO board.
I use them for building simple gps tracking device which would take position and send it to my web application periodically.
However, I've tested both of those shields seperately to see if they work with my arduino uno as I expected. And they really do.
I get GPS coordinates (parsed with TinyGPS) and I managed to send simple sms message to my phone with GPRS shield.
But the problem was when I combined all shields at the same time.
I believe that the problem is in my software serial baud rate. GPRS shield that I use requires 19200 baud rate while GPS works at 9600.
As I'm new to arduino I'm probably doing some stupid mistake because I've never worked with more software serials opened at same time.
So, here is my code. When I upload it to my board I'm able to receive and see gps coordinates at 9600 but I'm not able to send sms message. I hope you can tell me where the problem is and what's the best way to fix it.
Thank you very much
#include <SoftwareSerial.h>
#include <TinyGPS.h>
// Create an instance of the TinyGPS object
TinyGPS gps;
void getgps(TinyGPS &gps);
SoftwareSerial mySerial(7, 8);
void setup()
{
mySerial.begin(19200); // the GPRS baud rate
Serial.begin(9600);
delay(500);
}
void loop()
{
byte a;
if (Serial.available()) {
a = Serial.read();
if (gps.encode(a)) {
getgps(gps);
}
if (a=='send') {
SendTextMessage();
}
}
if (mySerial.available()) {
Serial.write(mySerial.read());
}
}
void getgps(TinyGPS &gps) {
long latitude, longitude;
gps.get_position(&latitude, &longitude);
Serial.print("Lat: ");
Serial.println(latitude);
Serial.print("Lon: ");
Serial.println(longitude);
}
void SendTextMessage()
{
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT + CMGS = \"+385xxxxxxxxx\"");//send sms message, be careful need to add a country code before the cellphone number
delay(100);
mySerial.println("A test message!");//the content of the message
delay(100);
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
mySerial.println();
}