Pages: [1]   Go Down
Author Topic: Arduino SIM300 help in reading SMS  (Read 315 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am new to micro controller programming.I am trying to connect SIM300 with Arduino duelmilanove ATmega168.

I was able to send SMS,call and other functions required for my project.I was even able to receive data from SIM300.Now I stuck at reading SMS from Memory.

For testing the reading part of my code is as follows:
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);
const int buttonPin = 5;
int index = 0;
boolean stringComplete = false;  // whether the string is complete
String inputString = "";
int buttonState = 0;


void setup() {
  // initialize serial:
  mySerial.begin(9600); // the GPRS baud rate
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  //inputString.reserve(1200);
   mySerial.println("AT");
   delay(2000);
}

void loop() {
  mySerialEvent();
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println("Loop input String = " + inputString + "...");
    // clear the string:
     inputString = "";
    stringComplete = false;
  }
  
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {  
      mySerial.println("AT+CMGF=1");
      delay(2500);
      mySerial.print( "AT+CMGR=1" );
  }
  }


void mySerialEvent() {
  
  while (mySerial.available()) {
    // get the new byte:
    char inChar = (char)mySerial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
  //Serial.println("Outside while inputstring=" + inputString + "...");
}
 
I am able to read and get all other response but for reading SMS from memory...it keep coming out of while loop before reading the complete msg...It keep truncating the msg at time of the SMS.

Output is as follows:
Code:
AT+CMGR=1



+CMGR: "REC READ","phonenumber","","9/9/13,03:40:

Please help me resolve this issue.

Thanks,
Pallavi
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11138
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Output is as follows:

What is output on the serial monitor when you run this sketch? Clearly it's not the output you show below.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just copied the output where the problem is...the actual output is as follows:

Code:
Loop input String = AT

OK
...
Loop input String =
RDY

+CFUN: 1
...
Loop input String =
+CPIN: READY
...
Loop input String = A+CMGF=1

OK
Loop input String = AT+CMGF=1

+CMGR: "REC READ","phonenumber",,"13/03/13,13:24:...


Thanks,
Pallavi
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11138
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After printing the command "AT+CMGF=1" the sketch waits for two and a half seconds before doing anything else, which makes it almost certain that the reply will have been sent and will have to be buffered inside the Serial port driver. Since that has a limited buffer  space (typically 64 bytes) any part of the response that won't fit in the buffer will be discarded. If you check your output, you'll see that is roughly where the response has been truncated.

I suggest it would be better to restructure your code so that after sending each command it reads the response until the complete response has been received, or the response has timed out.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply...

Even after removing the reply I was not able to read the complete SMS. So I tried increasing RX buffer Size in SoftwareSerial.H.
After increasing it to 128, I was able to read the SMS but getting some weird characters along too. I was not getting this before why it is so???
Code:
Loop input String = ÕÒTGF=1

OK
...
Loop input String = PU¥¨©”Tþ1

OK
ûÿÿ¿ÿÿÿýÿÿÿÿÿ¿ÿÿÿÿÿÿ¿ßÿÿýÿþÿÿÿÛûÿþÿÿÿÿ¿ÿÿÿÿÿÿÿÿÿßÿÿÿÿÿÿÿÿýÿþ÷ÿÿÿÿÿßÿßÞÿþÿÿÿÿïÿÿÿûûÿÿÿÿÿÿýÿÿÿÿÿÿ÷ÿßþÿÿÿÿÿßïÿÿýÿÿÝÿ...
Loop input String = PÕ+CMGF=1

OK
ÿEµ4ú...
Loop input String = IõÅQ­
5ÿGF=1

+CMGR: "REC READ","+phonenumber",,"13/10/10,15:18:19+22"
PUMP ON

I have one more doubt...what should be baud rate for tx and rx fro SIM300 modem,

Thanks
Pallavi
Logged

Pages: [1]   Go Up
Jump to: