0

Friends, my team and I are working on a gsm based wireless display as a part of our project. We are using Arduino UNO as the microcontroller which is interfaced with a sim900 module. Upon arrival of a new sms in the gsm module, its contents will be passed on to the dot matrix led display through SoftwareSerial. We almost got the code working but the problem we now encounter is the reception of new sms. The code works fine for the first sms but to display the next new sms, we had to manually reset the Arduino every time. Can you guys help me? This is the code:

#include <SoftwareSerial.h>
#include <SPI.h>      
#include <DMD.h>        
#include <TimerOne.h>   
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

int temp=0,i=0,x=0,k=0;
char str[160],msg[160];
void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

SoftwareSerial SIM900(0, 1);

void setup()
{


   Timer1.initialize( 5000 );          
   Timer1.attachInterrupt( ScanDMD );   


   dmd.clearScreen( true );   
   Serial.begin(9600); 

   SIM900.begin(9600); 
   void SIM900power();
   delay(20000);  

     SIM900.print("AT+CMGF=1\r");  
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r"); 
  delay(100);  
}

  void SIM900power()

{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}


void loop(){
for(unsigned int t=0;t<60000;t++){
  void serialEvent();
  if(temp==1)
  {
    x=0,k=0,temp=0;
    while(x<i)
    {
      while(str=='#')

      {
        x++;
        while(str!='*')

        {
          msg[k++]=str[x++];
        }
      }
      x++;
    }
   }
  }
     const char* dchars;
      dchars=msg;
     dmd.clearScreen( true );
   dmd.selectFont(Arial_Black_16);

  for(unsigned int i=0;i<=300;i++){
   dmd.drawMarquee(dchars,strlen(dchars),(32*DISPLAYS_ACROSS)-1,0);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+30) < millis()){
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
 }
}

void serialEvent(){ 
  while(Serial.available())
  {
    char ch=(char)Serial.read();
    str[i++]=ch;
    if(ch == '*')
    {
      temp=1;
    }
  }
} 

The DMD library was found on the net.

  • Please use the code format button to format the code properly. – Avamander Mar 6 '16 at 21:04
  • i did @Avamander – user82838 Mar 7 '16 at 2:54
  • 1
    Surely you have noticed there are syntax errors in your code? – SoreDakeNoKoto Mar 7 '16 at 3:28
  • The code compiled successfully i can't find errors.can u pls pin point them – user82838 Mar 11 '16 at 4:05
  • I have confusions in value passing through buffer and once this buffer value enters dmd loop there is no way out, hw can i improve that – user82838 Mar 11 '16 at 4:10
2

Does nothing clear 'i' at the end of a message? If not, then long/unexpected/multiple messages can overflow your str[160] buffer.

It also looks like writing to the msg[160] buffer isn't well protected from overflow.

| improve this answer | |
  • How can i protect msg(160) from overflow,can you please share the code – user82838 Mar 11 '16 at 6:08
  • strncopy() is made for copying strings up to the length of a buffer. I'd set a const int buffermax = 160; and use that as one limit on incrementing the buffer indices. – Dave X Mar 11 '16 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.