Arduino Due + SIM808 serial comm. issues

Hi all,

I'm somewhat a beginner at Arduino and I'm new to this forum, so please advice if I'm posting this in a wrong section.

I'm building a simple program, where I will use a SIM808 module to connect and retrieve sensor values via SMS commands(e.g. Temp and Humidity).

For a beginning I have wired the SIM808 GSM/GPRS module to the Arduino Due through the RX/TX 14/15 pins(Serial3) and I'm running a simple example program where I can send "r" or "s" via the serial monitor in order to send or receive a SMS.

The example program is running "okay" - I can send the command "s" and receive a SMS on the designated number.(See code below)

// this sketch is used for testing LoNet with Arduino 


void setup()
{  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial3.begin(9600);   // Setting the baud rate of GSM Module
  
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'r':
      RecieveMessage();
      break;
  }


 if (Serial3.available()>0)
   Serial.write(Serial3.read());
}


 void SendMessage()
{  

   
  String message = "Hello, this is a test sms";
  
  Serial3.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Serial3.println("AT+CMGS=\"+1234567890\"\r"); // Replace nr with your mobile number
  delay(1000);
  Serial3.println(message);// The SMS text you want to send
  delay(100);
  Serial3.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}


 void RecieveMessage()
{
  Serial3.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
 }

However, the Serial Monitor is spitting out random characters on startup as well as when I try to write normal AT commands.

I have also tried another example to communicate via AT commands, however the module is totally unresponsive - the serial monitor is not spitting out anything(see code below).

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial3.begin(9600);

}

void loop() // run over and over
{
  if (Serial3.available())
    Serial.write(Serial3.read());
    
  if (Serial.available())
  { 
    while(Serial.available())
    {
      Serial3.write(Serial.read());
    }
    Serial3.println();
  }
}

I'm not sure what the issue is, and I have tried searching for everything regarding the Arduino Due + SIM808 - but nothing exists. Is it a compatibility issue or? I hope someone can help me.

Thanks in advance,

/Soerenp

However, the Serial Monitor is spitting out random characters on startup as well as when I try to write normal AT commands.

How do you expect us to explain what appears in the Serial Monitor application, when you failed to show us that?

The Serial Monitor application does NOT randomly spit out characters. It shows ONLY what the Arduino sent.

PaulS: How do you expect us to explain what appears in the Serial Monitor application, when you failed to show us that?

The Serial Monitor application does NOT randomly spit out characters. It shows ONLY what the Arduino sent.

Hi PaulS,

I'm sorry for not being more specific or providing you all with a proper screenshot of the output in the serial monitor. However, when I refer to random characters, I mean gibberish nonsense.

If I type "AT" and I expect a response "OK", then sometimes I receive no response, and other times I receive something like "?`óe" - this especially applies to the first piece of code. The second piece of code either doesn't give any responses or it simply outputs what I provide as input.

I don't have the setup with me at the time of writing, but I can provide more information about the whole setup later if necessary.

I apologise for the inconvenience.

If I type "AT" and I expect a response "OK", then sometimes I receive no response, and other times I receive something like

Your expectations are wrong then.

What you SHOULD expect is that when you send "AT" to the device, nothing will happen immediately. THAT is normal behavior.

At some point in the future, you should get a response. You have no way of predicting how long any given AT command will take to get to the device, or how long that device will take to formulate a reply, or how long it will take for the Arduino to get the response. Nor do you know exactly when the response is complete. That seems to me to be a critical flaw in the entire AT command process. Every response should either start with a length or be terminated with some known character.

What you need to do then is either keep track of the commands sent, and the responses received, so you can match them up, and decide what to do next, or you spin for a while after sending each AT command, waiting for a reply (but not waiting forever) or something that indicates that the response is complete. For every AT command, what constitutes "response is complete" could be different.

How long to wait for a response is up to you, and might be different for each AT command.

What you can NOT do is send a bunch of AT commands, ignoring any response from the device. Which is what you are doing.

I can follow you on your points, and I definitely haven't been patient when it comes to responses from the SIM808 module, but I didn't expect that I had to wait several seconds or even minutes for a response on a simple "AT" command to see if the module is responsive(with response type "OK"). What triggers me is that some parts of it are working, but outside of the SendMessage and ReceiveMessage methods, then it is not working reliably.

I will based on your inputs try to implement some kind of tracking of the serial communication to see if I can pinpoint the error further.