I have written a program for reading SIM 908 from Arduino Mega 2560. I have more or less completed the work but there is an extra thing i wish to work on.
In the SIM 908, we have both, GSM and GPS modules. Uptil now i have been using GSM module and sent some messages. But now i want to use the GPS module and send the co ordinates i get of it through a text message. Problem is that I get a fairly long string of numbers when i get data from GPS. I need to pick out exactly 12 bytes from it to send in a text message. For that purpose I have made a function. But the problem is, apparently, Arduino resets as soon as it reaches the function call statement.
I am attaching my code too.
ReadGSM_v5.ino (4.94 KB)
You are not telling the function how much data is in the array. Since the array is a local array, it is not initialized, and, in the caller you do not NULL terminate the array.
So, you are scanning the array, looking for a 78, which may occur anywhere in the 200 bytes, AND may be garbage.
Suppose the 78 is found in position 0.
for (int n=7;n>1;n--)
You just copied data from positions -7 to -1 in data to useful. Does that seem like a reasonable thing to do?
Suppose the 78 is found at position 199.
for (int o=2;o<=7;o++)
Now, you are copying data from positions 201 to 206 in data to useful. Does that seem like a reasonable thing to do?
I don’t know why your posted code looks so awful, but it does. The formatting positively sucks. Use Tools + Auto Format before posting code again.