I have successfully implemented the switch on and switch off though the details provided in the wiki are vague. I am having a hard time using the code which has software serial used in it. The simple one for just sending the AT commands doesnt work and just send garbage value on the terminal. I have changed the baud rate and done a lot but the code with the software serial does not seem to work. Here is the code. I need to make this work as without this i can not see the responce of the AT commands on the serial interface in order to fix up the code for posting data on the interent
Please Help
//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include <NewSoftSerial.h>
NewSoftSerial mySerial(7, 8);
void setup()
{
mySerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
}
void loop()
{
if(Serial.available())
{
mySerial.print((unsigned char)Serial.read());
}
else if(mySerial.available())
{
Serial.print((unsigned char)mySerial.read());
}
}
[\code]
Typically, a garbage received on serial communication is an indication of mismatching baud rates.
In your case there are two places this could be happening: between the Arduino and the SIM900, or between the Arduino and your PC (e.g. your terminal isn't set to talk at 19200 baud).
I assume that you already verified that your Arduino and PC can communicate properly. (You did, right?)
The SIM900 can be set to communicate at a specific baud rate, or in an "automatic" mode. The mode and baud rate can be stored in the SIM900, and it will remember them across power cycles (i.e. it doesn't revert to some factory default when powered up or reset). When it's in "automatic" mode, it expects to receive the character 'A' (capital A) at the beginning of the communication to figure out the baud rate.
I see two options that may explain your situation:
The SIM900 is in "automatic" mode and you don't send it a capital A at the beginning of your messages.
The SIM900 is in fixed baud rate that you didn't try.
To complicate matters, my experience is that using SoftwareSerial in such a configuration is reliable only up to 19200 baud. If your SIM900 is configured at a fixed baud which is higher than 19200, you've got a catch-22, because you need to be able to talk to the SIM900 in order to configure its baud rate.
It's possible that you'll have to talk to it through the hardware UART at a higher baud rate to be able to configure it before you'll be able to continue with your project.
Rite now I am not even receiving garbage values. There is just nothing on the terminal screen. I have used the same shield to send SMS by sending the commands via the hardware UART. But the problem with using hardware UART is that I am in the dark whether any command is being executed or not.
Do you find any issue with the code ? If its not with the baud rate, could it be the case that the jumpers provided on the shield are not working properly. Have u got any experience of working with this shield ?
Have you tried the IDE 1.0 version of the sketch on the linked page?
If you are using Arduino 1.0 or later, use this sketch instead:
//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8);
void setup()
{
mySerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
My suggestion at this point is to go back to the test where you used the hardware serial port to send an SMS.
Can you repeat this test?
If you're able to successfully send an SMS using the hardware serial port, please post here the code of this test.
You'll then use a modified version of this code to change the baud rate to 9600 using the AT+IPR command.
Hopefully you'll then be able to talk to the SIM900 with SoftwareSerial at 9600 baud.
I've been attempting to use the SoftwareSerial library the past couple of days,
and found it to provide very poor communications. I have personally given up on
using the library for practical use.
I elicited comments from other people on their experience with the library, but
no one came forwards saying they have had really good luck with it. You can see
the thread here:
There was a comment about the AltSoftSerial library, which I just downloaded
and tried out, and it worked perfectly well the first time out of the box. It uses
pins 8,9, and co-opts Timer1, so you cannot use any other libraries that use
Timer1. Eg, I believe the Servo library uses Timer1.
I am able to successfully send the text message from the code mentioned on the Wiki Website. I have also tried to run the GPRS code given on that link. You can see it there because if i past it here, it would exceed the limit for the characters. I am pasting the code for the text message.
For the GPRS code, i get the following output. I have modified the code just not to use the sensor header files and send a random variable value to b e posted on the internet.
Here is the output i get. The output is in ASCII i guess and that why I can make out what is the responce of the commands. Either they are getting accepted or not. Do you think this is actual responce or just some garbage dump coming out of the software serial
"Turn on GPRS Modem and wait for 1 minute.
and then press a key
Press c for power on configuration
press any other key for uploading
Executing AT Commands for one time power on configuration
ATE0 Sent
Received:0|0|152|24|30|255|AT+CIPMUX=0 Sent
Received:0|126|134|24|128|96|254|128|248|134|134|24|248|AT+CIPMODE=0 Sent!
Received:0|248|158|96|134|128|248|158|158|0|158|152|248|AT+CGDCONT=1,"IP","inter net"
Received:0|248|158|24|230|24|254|120|230|128|126|25|121|15|24|102|25|3|51|126|10 2|96|207|230|24|152|102|152|30|255|AT+CSTT="INTERNET" Sent!
Received:0|248|158|24|230|0|6|134|158|158|230|126|159|126|6|102|51|204|15|AT+CIP SHUT Sent!
Received:0|248|158|96|134|96|152|254|6|24|7|255|Press a key to read temperature and upload it
TMP102 Temperature = Trial Version going on
AT+CIPSTART="TCP","api.cosm.com","80" Sent!
Received:0|126|134|96|134|96|152|0|126|255|158|128|0|24|128|152|134|158|120|6|103|207|120|231|102|230|134|134|126|135|102|30|121|60|240|51|230|248|AT+CIPSEND Sent!
Received:0|248|158|96|134|96|248|128|120|128|120|248|PUT /v2/feeds/62521.csv HTTP/1.1 Sent!
Host: api.cosm.com Sent!
X-PachubeApiKey: 4HaJl25MfMGEb9g2OuR9A0j9leaSAKxCNllDMHRqVFVXND0g Sent!
Content-Length: 12 Sent!Connection: close Sent!Received:0|0|126|230|102|254|102|224|128|230|152|230|230|254|230|158|230|120|158|126|255|134|128|0|6|159|102|134|126|230|248|24|254|102|224|126|224|96|224|120|254|102|254|102|248|126|230|126|248|24|158|24|248|0|102|248|96|230|96|128|96|248|30|AT+CIPSHUT Sent!
Received:0|248|158|96|134|96|152|254|6|24|7|255|"
void setup()
{
Serial.begin(19200); //Default serial port setting for the GPRS modem is 19200bps 8-N-1
Serial.print("\r");
delay(1000); //Wait for a second while the modem sends an "OK"
Serial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(1000);
//Serial.print("AT+CSCA=\" +919032055002\"\r"); //Setting for the SMS Message center number,
//delay(1000); //uncomment only if required and replace with
//the message center number obtained from
//your GSM service provider.
//Note that when specifying a tring of characters
// " is entered as \"
Serial.print("AT+CMGS=\"+918446043032\"\r"); //Start accepting the text for the message
//to be sent to the number specified.
//Replace this number with the target mobile number.
delay(1000);
Serial.print("SIM900 and Arduino say Hi!\r"); //The text for the message
delay(1000);
//Serial.print(26,BYTE); //Equivalent to sending Ctrl+Z
Serial.write(26); //June 2nd 2012: I replaced Serial.print(26,BYTE) by Serial.write(26) because the first command did not work in my case; Serial.write worked fine; please verify. -Ardutinker-
}
void loop()
{
//We just want to send the SMS only once, so there is nothing in this loop.
//If we put the code for SMS here, it will be sent again and again and cost us a lot.
}
[\code]
OK. Forget the GPRS for a moment. All we want is to be able to talk to the SIM900 via SoftwareSerial, and for that the code of the SMS is enough.
Since you have a working demo with hardware serial, I suggest you repeat the exact same test but with SoftwareSerial instead.
Try the following:
Configure your shield to use the software serial port (set the jumpers).
Then try to run this code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8);
void setup()
{
mySerial.begin(19200);
mySerial.print("\r");
delay(1000); //Wait for a second while the modem sends an "OK"
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(1000);
mySerial.print("AT+CMGS=\"+918446043032\"\r"); //Start accepting the text for the message
//to be sent to the number specified.
//Replace this number with the target mobile number.
delay(1000);
mySerial.print("SIM900 and Arduino say Hi!\r"); //The text for the message
delay(1000);
mySerial.write(26);
}
void loop()
{
}
The only difference between this and your working demo is the usage of SoftwareSerial instead of the hardware UART.
If this doesn't work, let's try to lower the baud rate.
Set your shield jumpers back to the hardware port, and run this code:
Again i have added the line to just check each char recieved. Can you tell me any other way I can see the actual characters being returned from the SIM900 module so that I can make out where the error is coming. I guess that would solve the issue for me.