SIM5320E

Hey guys I am trying to control an led via sms using the SIM5320E and an ardunio uno. i have been trying to find an example but they are all for the SIM900 and don’t seem to work. Could someone please help. Thanks in advance.

i was looking into using something like this which i found on the forum but it doesn’t seem to work.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10); //tx (9), rx (10)


#define LED 13
void setup()
{
  Serial.begin(115200);    // Setting the baud rate of Serial Monitor (Arduino) 
  mySerial.begin(115200);   // Setting the baud rate of GSM Module 
  delay(100);
  mySerial.print("AT+CMGF=1\r"); // set SMS mode to text
  delay(100);
  mySerial.print("AT+CNMI=1,2,0,0,0\r");
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
} // end void

//Variable to hold last line of serial output from sim5320e
char currentLine[500] = "";
int currentLineIndex = 0;
 
//Boolean to be set to true if message notificaion was found and next
//line of serial output is the actual SMS message content
bool nextLineIsMessage = false;
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
void loop()
{
  
  //If a character comes in from the cellular module.  
  if(mySerial.available()>0)
  { 
    char lastCharRead = mySerial.read();
    Serial.print(lastCharRead);
    

    //Read each character from serial output until \r or \n is reached (which denotes end of line)
    if(lastCharRead == '\r' || lastCharRead == '\n')
    {
    
        String lastLine = String(currentLine);
         
        //If last line read +CMT, New SMS Message Indications was received.
        //Hence, next line is the message content.
        if(lastLine.startsWith("+CMT:"))
        {
           
          Serial.println(lastLine);
          nextLineIsMessage = true;
           
        } // end if
        
        else if (lastLine.length() > 0) 
        {
           
          if(nextLineIsMessage) 
          {
            
            Serial.println(lastLine);
             
            //Read message content and set status according to SMS content
            if(lastLine.indexOf("1") >= 0)
            {
              Serial.println("on LED");
              digitalWrite(LED HIGH);
            } 
            else if(lastLine.indexOf("2") >= 0) 
            {
              Serial.println("off LED");
              digitalWrite(LED, LOW);
            }
             
            nextLineIsMessage = false;
          } // end if next line
           
        } // end of else if (lastLine.length() > 0)
         
        //Clear char array for next line of read
        for( int i = 0; i < sizeof(currentLine);  ++i ) {
         currentLine = (char)0;
        }
        currentLineIndex = 0;
    } 
    else 
    {
      currentLine[currentLineIndex++] = lastCharRead;
    } // end else 
  } // end of //If a character comes in from the cellular module.
}

Have you verified the serial comms? Write a simple program to echo serial monitor to-from the modem. All my SIM5320 midemsa arrive preset for 4800bps

Yes I have verified the serial comms! I have been able to send text messages but I can't figure out how to receive texts. Could you possibly show me an example

Try using CNMI=2,2,.... instead of 1,2,.... Quickly looking at the docs, it seems like it will hold the messages if DTR is not asserted.

I am also getting an error on this line ! currentLine = (char)0; Should that be currentLine[500] ={0}

Correct. currentLine[500] reserves 500 bytes for your string buffer. In this case, there is no need to initialise it, and if you did want to, "..." is a 'string literal' constant, not a single char constant.

Two ways to vastly improve your code. Get rid of (S)trings, use char arrays to operate with (s)things, and... Read about char * pointers.

Thanks to your help i have managed to turn on the led using an sms. However it seems to turn on noo matter what i send. The only things i changed from the above code was the baaud rate and the 2,2....

I know it's a big effort, but losing the (S)trings will make this a lot more efficient. Just out of interest - what are the compilation stats when you build this? FLASH / RAM usage...

What does the serial monitor show when you send a text with 1 or 2 in the body? (Perhaps just grab the text off screen, and paste it here in a quote block)

Serial.print() is a great debugging tool for issues like this.

Hey thank you soo much for your help i really appreciate it ! i got it working ! but i am not entirely sure what u mean by getting rid of the (S)trings. Im using a CHar array here ? alsi u use 16% program storage and 42% dynamic memory.

TheGreatApe: Hey thank you soo much for your help i really appreciate it ! i got it working ! but i am not entirely sure what u mean by getting rid of the (S)trings. Im using a CHar array here ? alsi u use 16% program storage and 42% dynamic memory.

Example of one of your String(s):

        String lastLine = String(currentLine);

how would u go about replacing this with a char array instead

how would u go about replacing this with a char array instead

That's a subject in itself... Try searching within the forum