#include <TinyGPS.h>
float lat,lon; // create variable for latitude and longitude object
TinyGPS gps; // create gps object
void cord(void);
void setup(){
Serial.begin(9600); // connect serial
Serial1.begin(4800);
Serial2.begin(9600); // connect serial
cord();
}
void cord(){
Serial.println("incord");
while(Serial1.available()){ // check for gps data
if(gps.encode(Serial1.read())){ // encode gps data
gps.f_get_position(&lat,&lon); // get latitude and longitude
Serial.println("got lat and long");
Serial2.println("AT");
delay(1000);
Serial2.println("AT+CMGS=\"+923244845012\""); //sending sms number
delay(1000);
Serial2.print(lat,14);Serial2.print(",");// print latitude
Serial2.println(lon,14); // print longitude
delay(1000);
Serial2.write(byte(26));
delay(3000);
Serial.println("outcord");
}
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.stats(&chars, &sentences, &failed_checksum);
delay(2000);
}
}
void loop()
{
char inByte;
char arr[100]={0};
Serial.print( " m in function ");
for(int z=0; z<4; z++)
{
do
{
while ( !Serial2.available() );
} while ( ',' != Serial2.read() );
Serial.print("m in do while");
}
do
{
while ( !Serial2.available() );
} while ( '\r' != Serial2.read() );
Serial.print(" I have detected quotes ");
int y=0;
do
{
while ( !Serial2.available() );
inByte = Serial2.read();
arr[y]=inByte;
Serial.write( inByte );
if(inByte=='s'){
Serial.println("initialise");
}
else{
Serial.println("error");
}
y++;
}while(inByte != '\r');
test1();
delay(1000);
test2();
}
void test1(void)
{
cord();
}
void test2(void){
Serial.println("test2");
}
In "setup" function i have called my "cord" function so technically it should run first before "loop" function and it does but problem is my output monitor shows
"incord(which is in "cord" function)
m in function(which is in "loop" function)"
it means my "cord" function doesnot complete and it jumps to "loop"..how is it possible..it does not even print "got lat and long" and "outcord" and in middle of function jumps to "loop" function..can someone tell me how is this happening?
Robin2:
Put some Serial.println() statements in various places so you can follow what your code is doing.
You have a lot of delay() statements. Maybe you need more patience?
...R
function
i have placed Serial.println() in three places in my cord() function to check whether my cord() function executes or gets stuck in while loop...thats what i am trying to say it just prints the first Serial.println() line that is "incord" and then jumps to loop(). delay i introduced later and gonna remove it
mistergreen:
TinyGPS gps; // create gps object
void cord(void); <-------------------------------------------- what is this?
void setup(){
Serial.begin(9600); // connect serial
Serial1.begin(4800);
Serial2.begin(9600); // connect serial
"incord(which is in "cord" function)
m in function(which is in "loop" function)"
I don't see how the sketch you posted could print "incord". Could you post the actual sketch that demonstrates the problem, and the output from it? Also explain what is wrong with the output.
While you're doing that, also look at the while loop at the top of coord() and think about whether that's a sensible thing to do.
I am very sorry i just posted wrong code..now check code i have edited it...this is the right one..sorry once again ...and peter which while loop you talking about this one "while(Serial1.available()){ // check for gps data" ?
Always auto format your code before trying to run/debug it this way you will see the real flow of your code and not what you think it is. Always format it before posting here.
Where is the new version? I hope you haven't changed the version in your original post because that just makes a nonsense of all the subsequent comments.
Can you post the latest version in a new post below this post, please.
Where is the new version? I hope you haven't changed the version in your original post because that just makes a nonsense of all the subsequent comments.
Can you post the latest version in a new post below this post, please.
...R
I have edited my original code in my first post.. check that out..
Where is the new version? I hope you haven't changed the version in your original post because that just makes a nonsense of all the subsequent comments.
Can you post the latest version in a new post below this post, please.
...R
I have edited my original code in my first post.. check that out..