MakerGram Logo

    MakerGram

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Users
    • Groups

    Help needed: Arduino Wireless Notice Board project

    Arduino
    6
    28
    3654
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rafitc99
      rafitc99 @codelery last edited by

      @codelery You can use any Arduino board. So far as i remember, we used Arduino UNO.

      Somehow i found the code in my gist. It was a 3 year old project. So, i don't remember most of the things

      Code:

      #include <SoftwareSerial.h>
      #include <SPI.h>
      #include <DMD.h>
      #include <TimerOne.h>
      #include "SystemFont5x7.h"
      #include "Arial_black_16.h"
      
      #define ROW 1
      #define COLUMN 1
      #define FONT Arial_Black_16
      
      DMD led_module(ROW, COLUMN);
      
      String st;
      const char *msg;
      unsigned int LengMsg;
      char finalMsg[100] = "";
      SoftwareSerial mySerial(3, 2);
      
      void scan_module() {
        led_module.scanDisplayBySPI();
      }
      
      void setup() {
        Timer1.initialize(2000);
        Timer1.attachInterrupt(scan_module);
        led_module.clearScreen( true );
      
        Serial.begin(9600);
        mySerial.begin(9600);
        Serial.println("Starting...");
        delay(1000);
        mySerial.println("AT");
        updateSerial();
        mySerial.println("AT+CMGF=1");
        updateSerial();
        mySerial.println("AT+CNMI=1,2,0,0,0");
        updateSerial();
      }
      
      void loop() {
        //  pollSms();
        displayMessage();
        delay(500);
      
        //Start print in led matrix
        led_module.selectFont(FONT);
        led_module.drawMarquee(finalMsg, LengMsg, (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();
          }
        }
      }
      
      //------GSM Helper
      
      void displayMessage()
      {
        delay(500);
        String msg = "";
        int start = 0, endPoint = 0;
        finalMsg[100] = "";
        while (Serial.available())
        {
          mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
          //     parseData(mySerial.readString());//Calls the parseData function to parse SMS
        }
        while (mySerial.available())
        {
          msg = mySerial.readString();//Forward what Software Serial received to Serial Port
        }
      
        if (msg.length() > 1) {
          start = msg.indexOf('*') + 1;
          endPoint = msg.indexOf('#') - 1;
          int count = 0;
          if (start > 1 && endPoint > 1) {
            strcpy( finalMsg, "");
      
            for (int i = start; i <= endPoint; i++) {
              finalMsg[count] = msg[i];
              count++;
            }
            Serial.println("SMS Received: ");
            Serial.println(finalMsg);
            LengMsg = count;
          }
          else{
            return false;
          }
        }
      }
      
      void updateSerial()
      {
        delay(500);
        while (Serial.available())
        {
          mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
        }
        while (mySerial.available())
        {
          Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
        }
      }
      

      NB: The sms body should be between start and hash
      Eg: * Hello Makers! #

      C 2 Replies Last reply Reply Quote 0
      • C
        codelery @rafitc99 last edited by

        @rafitc99 thank you so much. I will try it out and see if it will work.

        1 Reply Last reply Reply Quote 0
        • C
          codelery last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • C
            codelery @rafitc99 last edited by

            @rafitc99 I tried this code, but the SMS is always corrupted. I got "Hello peopl⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
            "

            instead of "Hello people of the village who work day and night to make sure all is well"

            salmanfaris 1 Reply Last reply Reply Quote 0
            • salmanfaris
              salmanfaris @codelery last edited by

              @codelery Could you please share your code for checking?

              C 1 Reply Last reply Reply Quote 0
              • C
                codelery @salmanfaris last edited by codelery

                @salmanfaris After countless trials and efforts without success, I have decided to use two separate microcontrollers (Atmega328p). One microcontroller receives SMS from SIM800l, parses it and sends it to the second microcontroller via serial interface (Arduino Rx and Tx pin). The second microcontroller receives the message via serial and send it to p10 module for display. This solution is not cost-effective because of the additional microcontroller. However, it solves the problem of interference between DMD library and SoftwareSerial which appeared to be the reason for the corrupted string I shared earlier.

                However, I am facing another challenge; the message that the second microcontroller receives via serial interface is not complete. When I send "*Hello people of working with you are you doing tonight or tomorrow morning dear#" via SMS, what is received and displayed on p10 is "*Hello people of working with you are you doing tonight or tomo".

                Here are the two codes:

                Code for receiving SMS

                 
                 #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 and displaying message 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 [500] = "Welcome to electronic projects workshop 1234"; 
                char r_msg[500] = "";
                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 );
                }
                
                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);
                      }
                   }
                }
                
                rafitc99 1 Reply Last reply Reply Quote 0
                • rafitc99
                  rafitc99 @codelery last edited by

                  @codelery It might be because of buffer size of received message. You need to increase the buffer size.
                  Check the section "Expanding Arduino SoftwareSerial Buffer Size" in this tutorial : https://lastminuteengineers.com/sim800l-gsm-module-arduino-tutorial/

                  C 2 Replies Last reply Reply Quote 1
                  • C
                    codelery @rafitc99 last edited by

                    @rafitc99 The thing is that I am not using the SoftwareSerial library in receiving the message from the first microcontroller. I am using the hardware serial (pin 0 and 1 on Arduino Uno)

                    salmanfaris 1 Reply Last reply Reply Quote 0
                    • salmanfaris
                      salmanfaris @codelery last edited by

                      @codelery said in Help needed: Arduino Wireless Notice Board project:

                      I am using the hardware serial (pin 0 and 1 on Arduino Uno)

                      As @rafitc99 mentioned, you need to expand the Serila buffer, in the hardware serial also the Arduino board package implements a 64-byte ring buffer for send and receive on the hardware serial messages. So you need to change that to 256 as per your message length.

                      C 1 Reply Last reply Reply Quote 0
                      • C
                        codelery @salmanfaris last edited by

                        @salmanfaris I did change the buffer size and everything is working perfectly. Thanks coming to my rescue.

                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post

                        Recent Posts

                        • @codelery Awesome. That's great news. Kudos to @rafitc99 . 🙌

                          @codelery Please keep us updated about your project, looking forward to seeing it in action 🤩

                          • read more
                        • C

                          @rafitc99 I changed the buffer and that solved the problem. Thanks a lot for coming to my rescue.

                          • read more
                        • C

                          @salmanfaris I did change the buffer size and everything is working perfectly. Thanks coming to my rescue.

                          • read more
                        • @codelery said in Help needed: Arduino Wireless Notice Board project:

                          I am using the hardware serial (pin 0 and 1 on Arduino Uno)

                          As @rafitc99 mentioned, you need to expand the Serila buffer, in the hardware serial also the Arduino board package implements a 64-byte ring buffer for send and receive on the hardware serial messages. So you need to change that to 256 as per your message length.

                          • read more
                        • C

                          @rafitc99 The thing is that I am not using the SoftwareSerial library in receiving the message from the first microcontroller. I am using the hardware serial (pin 0 and 1 on Arduino Uno)

                          • read more
                        By MakerGram | A XiStart Initiative | Built with ♥ NodeBB
                        Copyright © 2023 MakerGram, All rights reserved.
                        Privacy Policy | Terms & Conditions | Disclaimer | Code of Conduct