I have a GSM / GPRS Shield connected to an Arduino Duemilanove, and i have much trouble communicating to it reliably.
I set the Shield so that it takes commands via SoftwareSerial and then spits out any response to that Command via regular Serial - this has improved my issues a fair bit. Whats happening is that i send a command to the GSM Shield, and i get a reply of unknown length back. Or often i don't. The below process is fairly consistent and demonstrates my issue with an example:
1. Reset Arduino & open Serial Console
2. Send a new SMS to the GSM shield via Mobilephone
3. Run check_sms command to list new SMS
4. The output in the console is either not existing or cut off somewhere.
5. Run check_sms command to list new SMS again
6. The output is, in 95% of cases, what it should be.
7. Send another new SMS via Mobilephone
8. Rinse & repeat. Output is wrong the first time, it's nearly always correct the second or third time.
So why is it that i need to run a command twice? I played around with different methods, timings and delays for days now, and just cant get it to work reliably. When i started out using pure SoftwareSerial to communicate back and forth with the GSM Shield it was even worse, and get a lot of garbled output. Now the issue is that i don't reliably get all the output, or sometimes even no output.
I would be most grateful for someone to tell me just what the right way(TM) is to communicate reliably with my GSM Shield, or what the problems are in my Code or with my Timing. How to solidly read Data from the Device so that i can nearly guaranteed get the full output? I guess it all has to do with how fast the Shield processes incoming commands and how long it takes to send back a reply.
Thanks a lot.
String command = "";
Serial.println("Starting ATWIN Communication...");
command = get_serial_contents();
if(command == "check_sms")
command = "";
ch = Serial.read();
Serial.println("Getting Serial data");
character = Serial.read();