0
votes

So as it clear from the title, I am working on message sending and receiving project using arduino Mega 2560 connected to GSM shield SIM900 and a TFT Nextion HMI Screen. The following code is working and I am able to send and receive message using the serial monitor in Arduino IDE software. The next step is to print the received sms message to the screen. I am using AT command for receiving and sending messages with GSM. The problem is, how can I only read the message so that I can easily stored in any string variable and printed to the TFT screen using TFT Nextion style print code??

This is the code:

#include <SoftwareSerial.h>
#include <Nextion.h>

SoftwareSerial mySerial(10, 11); // GSM Rx pin is connected to pin 10 and Tx pin is connected to pin 11
SoftwareSerial nextion(53, 52);  // Nextion TX to pin 2 and RX to pin 3 of Arduino

Nextion myNextion(nextion, 9600); //a Nextion object named myNextion using the nextion serial port @ 9600bps

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
  myNextion.init();     // Setting the baud rate of TFT Screen (LCD)
}


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

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


 void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+947779328453\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}


 void RecieveMessage()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
 }
1
Don't spam tags! Arduino is not C!too honest for this site

1 Answers

0
votes

As you said, to communicate with the modem, you have to use a set of AT commands. For the first tries, I suggest you to simply connect the modem to a serial port and run AT commands manually to experience them.

Here is the first document I found on google, search for CMGR:

http://www.zeeman.de/wp-content/uploads/2007/09/ubinetics-at-command-set.pdf

You also probably need to set the PIN code, here is from mind how to do it:

AT+CPIN?      <-- request pin status
AT+CPIN=1234  <-- Enter the pin

Then when it works and you know the set of commands to use, you can start programing!

Depending on the vendor, some specific AT commands might be available but for more portability, I suggest you to stick with the standards!

Sorry I don't have any modem right now, so I cannot provide a complete example...