Hello,
How can i interface gsm module (sim 900A) and gps module (reb-1315s4) on single arduino uno?
from where should i start with and how can i do programming?
can any one pass me some code to send and receive message and check longitude and latitude?
thanx
heres a little sketch I wrote to send and receive texts from a sim900 shield or just communicate via AT commands. and a bonus, if you text it + it turns on a light and - turns it off. It might be good start to pull from. Good luck.
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial GSMserial(7, 8);
int num[10];
unsigned char text[300];
char mess[300];
char choice;
String message = "";
String phone = "";
String received = "";
String str= "";
int count = 0;
int i = 0;
boolean light = true;
int relayPin = 13;
void setup()
{
Serial.begin(9600);
GSMserial.begin(19200);
pinMode(relayPin, OUTPUT);
}
void loop()
{
if(GSMserial.available()) // if date is comming from softwareserial port ==> data is comming from GSMserial shield
{
while(GSMserial.available()) // reading data into char array
{
text[count]=GSMserial.read(); // writing data into array
//Serial.print(text[count]); // debug
if(text[count] == '"') i++;
if(i >= 6 && text[count] != '"')
{
if((char)text[count] == '+') light = true;
if((char)text[count] == '-') light = false;
received += (char)text[count];
}
if(count == 300)break;
count++;
}
Serial.println(received);
Serial.println(light);
digitalWrite(relayPin, light);
received = "";
Serial.write(text,count); // if no data transmission ends, write text to hardware serial port
cleartextArray(); // call cleartextArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
i = 0;
}
//Serial.println(received);
if (Serial.available())
{
while(Serial.available()) // reading data into char array
{
text[count]=Serial.read();
if(text[count] == '~')
{
text[count]=NULL; Serial.flush(); count = 0; function();
}
count++;
if(count == 300)break;
}
GSMserial.write(text,count); // if no data transmission ends, write text to hardware serial port
cleartextArray(); // call cleartextArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
}
}
void function()
{
int bytes_read = 0;
Serial.print("Send Text(s) or Exit(x): ");
while(bytes_read < 1)
{
if(Serial.available() > 0)
{
choice = Serial.read();
}
switch(choice)
{
case 's': Serial.println(choice); bytes_read++; choice = ' '; SendTextMessage();
break;
case 'x': Serial.println("AT COMMAND MODE"); bytes_read++;
break;
bytes_read++;
}
choice = ' ';
}
}
void setNumber()
{
Serial.print("Enter Phone Number: ");
int bytes_read = 0;
while (bytes_read < 10) //amount of numbers to read - corresponds to array decleration and print loop
{
//Serial.println(num[bytes_read]); //debug
//Serial.println("number"); //debug
if(Serial.available()>0)
{
num[bytes_read] = Serial.read() - 48; //its adds 48 to it? i dont know
phone += num[bytes_read];
//Serial.print(num[bytes_read]); //debug
//Serial.print("num[]"); //debug
bytes_read ++;
}
}
}
void printNumber()
{
Serial.println(phone);
}
void setMessage()
{
Serial.print("Type Message: ");
int bytes_read = 0;
boolean done = false;
while (done == false) //amount of numbers to read - corresponds to array decleration and print loop
{
//Serial.println("message"); //debug
if (Serial.available() > 0)
{
mess[bytes_read] = Serial.read();
if(mess[bytes_read] == '~')
{
done = true;
}
if(mess[bytes_read] != '~')
{
message += mess[bytes_read];
}
bytes_read ++;
}
}
}
void printMessage()
{
for(int i = 0; i < 300; i++)
if(mess[i] != '~')
{
Serial.print(mess[i]);
}
Serial.println(" ");
}
void SendTextMessage()
{
setNumber();
printNumber();
setMessage();
printMessage();
GSMserial.println("AT+CMGF=1"); //Because we want to send the SMS in text mode
delay(100);
String str = "";
str += "AT+CMGS = \"+1";
str += phone;
str += "\"";
GSMserial.println(str);
delay(100);
//Serial.println(message); //the content of the message
GSMserial.println(message); //the content of the message
delay(150);
GSMserial.println((char)26); //the ASCII code of the ctrl+z is 26
delay(200);
Serial.println("Message Sent!");
phone = "";
message = "";
clearMessage();
Serial.flush();
GSMserial.flush();
}
void cleartextArray() // function to clear text array
{
for (int i=0; i<300;i++)
{ text[i]=NULL;} // clear all index of array with command NULL
}
void clearMessage()
{
for (int i=0; i<300;i++)
{ mess[i]=NULL;}
}
//void ReceiveTextMessage()
//{
//
// char incoming[300];
// Serial.println("Checking for messages");
// int bytes_read = 0;
// boolean finished = false;
// GSMserial.println("AT+CNMI=2,2,0,0,0"); //"AT+CMGR=1"
// if(GSMserial.available())
// {
// while(GSMserial.available())
// {
// incoming[bytes_read] = GSMserial.read();
// delay(20);
// received += incoming[bytes_read];
// incoming[bytes_read] = NULL;
// bytes_read++;
// }
//
// //Serial.println(bytes_read);
// }
//
// Serial.println(received);
//
// choice = ' ';
// received = "";
// message = "";
// function();
//}
i have bought gsm module but its not of arduino sim 900A can i interface arduinio uno with sim 900A with same code used for gsm shield of arduino?
Did you start here?
ya i started but i am unable to find library
#include"SIM900.h"
from where can i download this library,so that i can import it?
and on which pin i can connect gsm Rxd and Txd pins?
i mean analog or digital pins?