Can't read SMS on the port serial. [GPRS + Arduino]

Hello,

I have develop a small program which can receive, send and delete SMS.
There is no problem when I send or delete a SMS but when I receive the Serial port just tell me that :

“+CMGL: 1, “REC READ”,”+3247321"

while it should show me my phone number (and not a part of it), the day and the message of course.

#include <SoftwareSerial.h>
#include <String.h>
#include <SMS.h>

SoftwareSerial GPRS (7, 8 );



void setup()
{
 GPRS.begin(19200);               // the GPRS baud rate   
 Serial.begin(19200);    // the GPRS baud rate 
 delay(1000);
 Serial.println("****************  Service d'envoie et de réception de MSG  ****************");
 GPRS.println("AT+CSQ"); // niveau de réception
  delay(1000);
  Serial.println("envoi de la commande : AT+CMBF=1");
 delay (1000);
  //GPRS.println("AT+CMGF=l\r");
  delay (1000);  
  GPRS.println("AT+CSCA=\"+32475161616\"\r"); //se mettre sur le réseau
  delay (500);
  Serial.println("envoi de la commande : AT+CPIN=\"****\"");
  delay (1000);
  Serial.println("envoi de la commande : AT+CSCA=\"+32475161616\"");   // centre de messagerie proximus
  GPRS.println("AT+CPIN=\"****\""); //insertion du code PIN
  delay (100);
  GPRS.println("AT+CPIN?") ; // PIN ok ou error
  delay (1000);
  Serial.println("****************  Appuyer sur s pour envoyer un MSG au 0473/217105  ****************");
  delay (500);
   Serial.println ("****************  Pour voir les MSG reçus, tapé 'r'  ****************");
  delay (500);
  Serial.println ("****************  Pour supprimer tous les MSG, tapé 'd'  ****************");
  delay (500);
}

void loop()
{ 

  if (Serial.available())
   switch(Serial.read())
  {
    case 's':
      SendMSG();
      break;
      
    case 'r':
      ReceiveTxTmsg();
      break;

    case 'd':
      Delete();
      break;
  } 
 if (GPRS.available())
   Serial.write(GPRS.read());
}

///
 void SendMSG()
{  
  GPRS.print("\r");   // Envoyer un retour à la ligne <CR>
  delay(1000);                  
  GPRS.print("AT+CMGF=1\r");  // Envoyer un SMS en mode texte
  delay(1000);                                 
  GPRS.print("AT+CMGS=\"+32473217105\"\r");   // Numéro du destinataire
  delay(1000);
  GPRS.print("Salut !\r");     // Le texte du message
  delay(1000);
  GPRS.write(26);  // Equivalent du Ctrl+Z (fin de texte du SMS)
}

void ReceiveTxTmsg()
{
 GPRS.println("AT+CMGF=1") ; //passe les sms en mode texte
  delay (1000);
  //delay (500);
  //GPRS.println("AT+CMGL"); //montre tous les sms non lu
  //GPRS.println("AT+CMGR=\r"); //Lis le deuxième sms
//  Serial.println("AT+CMGR=9");
 // delay (3000);
 // GPRS.println("AT+CMGR=1"); 
  GPRS.println("AT+CMGL=\"ALL\""); //lis tous les sms
  //GPRS.println("AT+CMGR=1");
  delay (10000);
}

void Delete()
{
GPRS.println("AT+CMGD=1,4\r");
}
 if (GPRS.available())
   Serial.write(GPRS.read());

A while loop would make more sense.

Thank you for your answer. Have you an idea for the receiving's problem ?

Have you an idea for the receiving's problem ?

That was my (proposed) answer. It's up to you to test it.

Ah ok, sorry I am a beginner.
like this ?

 while (GPRS.available())
 Serial.write(GPRS.read());

If it is like this, it’s change nothing.
Thank you for your help

I'm not sure why you are using a binary function (write()) to send ASCII data. If using print() instead doesn't fix anything, I'm out of ideas.

What do you get in response to AT+CNMI?

It sends me this :

AT+CNMI?

+CNMI: 2,1,0,0,0

OK

Which means that the text messages are sent to memory and only a notification is sent to the serial monitor.

I assume that you want the entire message sent to the serial monitor on receipt? If so, try sendingAT+CNMI=2,2,0,0,0

Yes, it is what i'm looking for.

like this ? It doesn't work.

 GPRS.println("AT+CNMI=2,2,0,0,0");
GPRS.println("AT+CNMI=2,2,0,0,0\r");

In what way doesn't it work? When you issue the command do you get an error? You only need to do this once, the modem will remember the setting until it is reset.

My bad, it actually works ! Thank you ! But it only shows me the entire message when it's received. When I want to read it in the memory it shows me the start of the message.

Have you an idea for that ?

In your original example,

+CMGL: 1, “REC READ”,"+3247321"

the 1 indicates that the message is in memory location number 1

Use AT+CMGR= to read the message at a particular location. (e.g. AT+CMGR=1)

Thank for all these goods advices !

Hello!
At the time in this thread i would like to ask question - can You show which module are You using and how connected hardware? Im having the same difficulties.
I am using THIS modul and connecting it to Arduino MEGA. 19 pin(RX1) of Arduino i connect with moduls TX7 and Arduino 18 pin(TX1) with RX7. Below is the picture showing it.

Dont worry about power, i also used 72VA power supply, it didnt worked also. Modem doesnt need such current as recomennded for serial communication.
Tx from Arduino works because i can make call and send sms, but in serial port monitor i cant see no data coming from SIM900.

As im not sure there’s a problem in programm or hardware i added my sketch below. Basically there is 4 cases - 2nd case calls and hangs up, in 3rd im asking is there any sms and in 4th case im asking signal quality. In 3rd and 4th case atleast something needs to be showing in serial port monitor but nothing…

I also used lines like this for data reading from SIM900, but none of them worked.

if (mySerial.available())
{
   Serial.write(mySerial.read());
}
if (mySerial.available() > 0)
{
  Serial.println(mySerial.read());
}
if(mySerial.available() >0)
  {
    incoming_char=mySerial.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
  }
}

Complete code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(19, 18);  //Arduino 18 pin(TX1) and 19 pin(RX1)

int LED = 13;

void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(19200);
mySerial.begin(19200);  // the GPRS baud rate   
powerUp();

}

void powerUp()
{
pinMode(9, OUTPUT); 
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(9000);
Serial.println("Modem powered");
}


void loop()
{
  if (Serial.available())
  {
    char inSer = Serial.read();
    switch (inSer)
    {     
      case '1':      //Just for confirmation that incoming characters from serial port is reading
      digitalWrite(LED, HIGH);
      delay(3000);
      digitalWrite(LED, LOW);
      break;
      
      case '2':
      mySerial.println("ATD + +371200....;"); //Calling to my cell. I just deleted part of my phone number cus i dont want to shove it
      delay(100);
      mySerial.println();
      delay(7000);            
      mySerial.println("ATH");  //Hangup
      break;
     
      case '3':
      mySerial.println("AT+CNMI=?\r");  //asking for new sms message indication
      delay(100);
      break;
      
      case '4':
      mySerial.println("AT+CSQ=?\r");  //asking for signal quality report
      delay(100);
      break;
    }
  }
if (mySerial.available()) 
{
   Serial.write(mySerial.read());
}  
}

I would be appreciated for help how to read data from SIM900 :slight_smile: