1

I am working on a GSM based electronic notice board using p10 module and SIM800l GSM module.

Due to conflict between the DMD library and the Arduino softwareSerial library, I decide to use two Atmega328p microcontrollers. One microcontroller receives SMS from the GSM module and sends it to the other microcontroller via serial interface.

The issue here is that, when the message is received by the second microcontroller from the first microcontroller, the message is not complete; it is truncated.

Code for receiving SMS and sending the message to the second microcontroller:

#include <SIM800L.h>
SIM800L sim800l(2, 3); //Rx, Tx
int LED_PIN = 8;

//Enter the phone number of the person whom you want to send sms
String reply = "Hey! I have got your message";

void handleSMS(String number, String message) {
  int start_index = message.indexOf('*'); // message starts with '*'
  int end_index = message.indexOf('#'); // message ends with '*'
  //message.trim();
  // if message starts with * and ends with #
  if(start_index == 0 && end_index == (message.length() - 1)) {
    Serial.println(message);
    blinkLed();
    sim800l.sendSMS(number, reply);
  } 
}

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  sim800l.begin(9600);
  sim800l.setSMSCallback(handleSMS);
}

void loop() {
  sim800l.listen();
}

void blinkLed(){
   for(int i = 0; i < 3; i++){
      digitalWrite(LED_PIN, HIGH);
      delay(1000);
      digitalWrite(LED_PIN, LOW);
      delay(1000);
 }
}

Code for receiving message from the first microcontroller and displaying it on p10:

#include <SPI.h>
#include  "buzzer.h"
#include <DMD.h>
#include "memory.h"

#include <TimerOne.h>

#include "SystemFont5x7.h"

#include "Arial_black_16.h"


#define ROW 3

#define COLUMN 1

#define FONT Arial_Black_16
char message [250] = "Welcome to electronic projects workshop 1234"; 
char r_msg[250] = "";
bool flag = false;

DMD led_module(ROW, COLUMN);


void scan_module()

{

  led_module.scanDisplayBySPI();

}


void setup()

{
  EEPROM.begin();
  Serial.begin(9600);
  buzzerSetup();
  beeps(3);

  int m_length = EEPROM.read(5);
 
    //    strcpy(message, "");
  String stored_string = read_string(5); 
     
  char stored_char[stored_string.length() + 1];
  stored_string.toCharArray(stored_char, stored_string.length() + 1); // convert message from string to array of char
  strcpy(message, stored_char); // update p10 with stored message

  
  Timer1.initialize(2000);

  Timer1.attachInterrupt(scan_module);

 led_module.clearScreen( true );
writeString(5, "Hello people");
}

void loop()

{
  Serial.println(read_string(5)); 
    receiveMessage();
    
    led_module.selectFont(FONT);

    led_module.drawMarquee(message, strlen(message), (32 * ROW), 0);

    long start = millis();

    long timming = start;

    boolean flag = false;

    while (!flag)

    {

      if ((timming + 20) < millis()) 

      {

        flag = led_module.stepMarquee(-1, 0);

        timming = millis();
      }
    }

  }

void receiveMessage()
{
  /*
    Listens to incoming message through serial interface. 
    It extracts the message if it starts with '*' and ends with '#'
  */
  while(Serial.available())
  {
    String s_msg = Serial.readString();
    // s_msg.trim();
    int start_index = s_msg.indexOf('*') + 1;
    int end_index = s_msg.indexOf('#');
      
    // whether message contains * and # and also # comes after *
    if(start_index > 0 ){
        beeps(1);
        String substr = s_msg.substring(start_index, end_index - 1);
        int m_len = substr.length() + 1;
        char m_msg [m_len];
        substr.toCharArray(m_msg, m_len);
        
        strcpy(message, m_msg);
        // write to eeprom
        writeString(5, substr);
      }
   }
}

3
  • "the message is not complete; it is truncated" -- That's a summation suitable for a title, but you also need to provide specific details of the problem. Exactly what was sent? What was received? You are apparently using two untested programs together at the same time; that's usually a difficult method of testing unproven code. Be careful assuming that the receive was "truncated"; why do you assume that the transmit was perfect?
    – sawdust
    Commented Jul 4, 2023 at 19:54
  • What was received as SMS by the microcontroller was "*Hello people of working with you are you doing tonight or tomorrow morning dear#" but what was received by the second microcontroller through Serial was "*Hello people of working with you are you doing tonight or tomo". Commented Jul 5, 2023 at 8:39
  • I would suggest changing the polling approach to a SerialEvent where you build the incoming message char by char. Make the interrupt routine as short as possible and get ready for an inrush of comments telling you to avoid using Arduino String types Commented Feb 6 at 13:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.