sms wont display on serial monitor

is their something wrong in my code?

#include <SoftwareSerial.h> 
#include <GSM_Shield.h>


char number[]="##########";  //here would be my # but i wont show it 
byte del_sms=1;                //0: No deleting sms - 1: Deleting SMS
GSM gsm;
char sms_rx[122]; //Received text SMS
char number_incoming[20];
int error;

void setup() {
   Serial.begin(9600);
  Serial.println("system startup"); 
  gsm.TurnOn(9600);          //module power on
  gsm.InitParam(PARAM_SET_1);//configure the module  
  gsm.Echo(1);               //enable AT echo 

}

void loop() {
  char pos_sms_rx;  //Received SMS position     
     pos_sms_rx=gsm.IsSMSPresent(SMS_UNREAD);
     if (pos_sms_rx!=0)
     {
       //Read text/number/position of sms
       gsm.GetSMS(pos_sms_rx,number_incoming,sms_rx,120);
       Serial.print("Received SMS from ");
       Serial.print(number_incoming);
       Serial.print("(sim position: ");
       Serial.print(word(pos_sms_rx));
       Serial.println(")");
       Serial.println("before");
       Serial.println(sms_rx); //HERE IS WHERE THE SMS IS DYSPLYED
       Serial.println("after");
       if (del_sms==1)  //If 'del_sms' is 1, i delete sms 
       {
         error=gsm.DeleteSMS(pos_sms_rx);
         if (error==0)Serial.println("SMS deleted");      
         else Serial.println("SMS not deleted");
       }
     }

}

here is what serial monitor looks like, there is something wrong with the sms_rx

Capture.PNG

Where did you get this code?

i got it from a example (test) code that came with the library

https://github.com/jgarland79/GSM_Shield

plzzzzzz help

I don't have experience with GSM shields.

Is the library suppose to be compatible with the shield?

Post a link to the shield you're using.

yes everything else works receive calls,sends sms, making a call still does not work

but ill just work on it till i have it, today i tried for about 9 hours https://www.robotshop.com/en/ld-arduino-compatible.html

So, that shield comes with a library that’s presumably compatible. Did you try running the examples contained therein?

In the .cpp file of that library I see:

NewSoftSerial mySerial(4, 5);  //rx, tx

In the library you’re using I see:

SoftwareSerial mySerial(2, 3);  //rx, tx

So, which pins do you have the shield setup to use for Serial Comm?

i have pins 2,3 rx,tx setup. that library didnt work that came with that shield. if u see the github lib you can what all he clanged to make it work.

But couldn't i somehow take that sms_rx out and go direct what the arduino is seeing

and also what does that sim position mean?

The source code for the module is filled with examples and help, you should try to look into those informations. I can spot a bug in your code:

char pos_sms_rx;
pos_sms_rx=gsm.IsSMSPresent(SMS_UNREAD);
if (pos_sms_rx!=0) {
  ...
}

“pos_sms_rx” may be < 0, indicating an error. You code should be “if (pos_sms_rx > 0)” to indicate the presence of a message.

EDIT: Have I been liberated of the 100 post spam limit? OH YES, I HAVE! :wink:

Same thing happens, so u dont think it has to do with the sms_rx?

Nope.. But you should check the return value of GetSMS, since it may tell you what the problem may be.

Thanks for the reply it returns a 3. i looked in the documentation what that 3 indicates and it said

-1 - comm. line to the GSM module is not free -2 - GSM module didn't answer in timeout -3 - specified position must be > 0 OK ret val:

Return value 3 means GETSMS_OTHER_SMS. Have you tried to check the length of "sms_rx" with strlen? AFAIK an empty SMS is possible. If strlen is > 0 then try to print each individual char to see what comes out, if 7bit encoded it must be converted to octets in order to be displayed properly.

ok now i think i know the problem but i dont know how to solve it. i commanded the serial monitor to see what value is coming from the pos_sms_rx=gsm.IsSMSPresent(SMS_UNREAD);.

the serial monitor left a space for the value but it was blank something like this

before

//here the value would go but nothing is written

after

what is going on, how do i fix it?

the string length is 0. So do i have convert them to octets. I have never even herd that word but i will do research if thats what to be done

If strlen is 0 then the SMS must be empty, try to read another SMS which you know has some content.

im not quite sure what u mean by “try to read another SMS which you know has some content.” could u maybe give me an example

Try to GetSMS from another position, or try to DeleteSMS from the position after you have read it with GetSMS. If there is an empty SMS in the GSM module, you will always read that empty SMS until it is deleted or you pick another position to read from.