ERROR Show SMS on LED Matrix

I am creating some project where SMS will display in 8x64 led matrix.

Codes are working, except when I call the checkSMS() function.
When I include checkSMS() on void loop. display in led matrix is blinking while scrolling.
I need to loop checkSMS() to check if new sms has arrived to replace current message being displayed.
I am using GSM Library from open electronics and SIM900 modem.
Here is my code.
[code]#include "cmap.h"             // library of Character Map
#include <SIM900.h>           // SIM900D library
#include <sms.h>              // SMS library
#include <SoftwareSerial.h>   // Software Serial Library Default in Arduino Lib Files
#include <avr/pgmspace.h>
SMSGSM sms;   //declaration of GSM for SMS Library

#define INTEN 5000  //Speed of scrolling of character map data into LED MATRIX

//Definition of PINs of LED MATRIX Driver Shield
#define CLK  5    // clock pin connected to digital pin 5
#define DAT  6    // Data pin connected to digital pin 6
#define STR  7    // Strobe pin connected to digital pin 7 
#define K0  A0    // Data 0 connected to analog pin 0
#define K1  A1    // Data 1 connected to analog pin 1
#define K2  A2    // Data 2 connected to analog pin 2
#define K3  A3    // Data 3 connected to analog pin 3
#define K4  8     // Data 4 connected to digital pin 8
#define K5  9     // Data 5 connected to digital pin 9
#define K6  10    // Data 6 connected to digital pin 10
#define K7  11    // Data 7 connected to digital pin 11

////LED MATRIX Declarations////////
int d;
unsigned char char_pointer;
char Display_Ram[76];
unsigned char mask;
char count;	
unsigned char shift_counter;

int pins[]  = { CLK, DAT, STR, K0,      // pins for LED Matrix
                K1, K2, K3, K4, K5, 
                K6, K7 };
int mask_data[]  = {0x00, 0x00, 0x00,   // mask for LED Matrix Display
                    0x80, 0x40, 0x20, 
                    0x10, 0x08, 0x04, 
                    0x02, 0x01};
                    
/////SMS/GSM Declarations/////
boolean started=false;    //indicates if GSM Modem is power on and connected, False = OFF, True = Connected
char smsbuffer[160];      //SMS Holder allocates 160 characters only
char n[20];               //sender number holder
int showMSG = 0;

char *scrolling_message(int msg)   //FUnction that return the appropraite message to be displayed
{
    
  char *defaultMSG PROGMEM = "WELCOME HOME FRIENDS........LED MATRIX..... #";  //Default Message if there is no SMS from GSM Modem
  char *smsMSG PROGMEM = smsbuffer;   //Assign the SMS read from GSM Modem
  
  if (msg == 0)  //If there is no SMS read, 0 will return and issue default message to load.
  {
   return defaultMSG; 
  }
  if(msg ==1)
  {
   return smsMSG; 
  }
}

void setup() 
{   
  digitalWrite(12,HIGH);   //Issue High Value to PIN #12 of Arduino to Power ON GSM Modem
  delay(3000);             //Wait for 3 seconds to power ON GSM Modem before connection begin
  
  Serial.begin(9600);
  if(gsm.begin(4800))      //allow 3 secs then connect/begin connection of gsm modem using Baud Rate 4800
  {
    started=true;
    Serial.println("Ready");
    //checkSMS();
  }
  else Serial.println("\nIdle");

    pinAssignment();      //Distribute assign value of LED MATRIX Shield pins
}

void pinAssignment()
{
 for (int x =0; x<=10; x++){  
    pinMode(pins[x], OUTPUT);     
  }   
  for (int y=3; y <=10; y++){
    digitalWrite(pins[y],HIGH);  
  }  
  for(d=0;d<64;d++)
  {
    clock();
  }
  strobe();      //Power Up LED Matrix
  d = 0; 
  
}

void loop()
{
    Display();     //Display character data by issuing mask data into pins
    shift();
    checkSMS();
}

void checkSMS()
{
  if(started){   
   if(gsm.readSMS(smsbuffer, 160, n, 20))
    {
            showMSG = 1;
            Serial.println(n);
            Serial.println(smsbuffer);
    }
    }
    
}

void delsms(){
  for (int i=0; i<10; i++){  //do it max 10 times
      int pos=sms.IsSMSPresent(SMS_ALL);
      if (pos!=0){
        if (sms.DeleteSMS(pos)==1){   
   //Just delete it
        }

      }
    }
 
}		

void shift(void)                                // Scroll message on the display (64 leds for now)
{
  for (int val=0; val<74; val++)
  {
    Display_Ram[val] = Display_Ram[val+1];
  }
  
  shift_counter++;
  
  if(shift_counter == 8)    //Shift counter is equal to 8, coz we use 8x8 dot matrix module of character map data
  {
    shift_counter = 0;    
    load();  
  }
  
}

void Display(void)
{
  int i = 0;
  for (i = 10; i >=3 ; i--)
  {
    mask = mask_data[i] ;
    scan();
    digitalWrite(pins[i],LOW);
    for(d=0;d<INTEN;d++){}
    digitalWrite(pins[i],HIGH);
    
  }
}

void load(void)          //Load data into led driver shield
{
  char counter1;
  char *LED_DATA PROGMEM = scrolling_message(showMSG);  //Holder of DATA To be displayed
  
  if(LED_DATA[char_pointer+1] == '#')
  {
    char_pointer = 0;
  }
  for(counter1 = 0; counter1 < 7; counter1++)
  {
    Display_Ram[64 + counter1] = pgm_read_byte(&(character_data[(LED_DATA[char_pointer] - 0x20)][counter1])); //read the byte at this location
  }	
  Display_Ram[76] = 00;	
  char_pointer++;
    

}

//Clear LED display when pointer value is reach, which is "#"
void Clear_Display_Ram(void){
  unsigned char rcount;
  for(rcount = 0; rcount < 74; rcount++)
    Display_Ram[rcount] = 0xff;      
}

//Scan each mask 
void scan(void)
{
  for (count=64;count>(-1);count--){
    if ((Display_Ram[count] & mask) == mask)
      digitalWrite(DAT,LOW);
    else
      digitalWrite(DAT,HIGH);
    clock();
  }
  strobe();
}

void clock(void){
  digitalWrite(CLK,HIGH);			// clock hi
  digitalWrite(CLK,LOW);		        // clock low
}

void strobe(void){
  digitalWrite(STR,HIGH);			// strobe hi
  digitalWrite(STR,LOW);			// strobe low
}



//NOTE TO MYSELF: Aruino UNO holds only 2048 bytes in SRAM, So we need to use PROGMEM to reduce memory size consumed, by redirecting assign value into other memory.
//                If we don't use such technique, buffer overflow and error will occur.

I Also tried this one but no message being shown on my LED Matrix

void loop()
{
    Display();     //Display character data by issuing mask data into pins
    shift();
    
    if(started){   
   if(gsm.readSMS(smsbuffer, 160, n, 20))
    {
            showMSG = 1;
            Serial.println(n);
            Serial.println(smsbuffer);
    }
    }
}

[/code]

It sounds like the call to checkSMS() is taking enough time to cause a pause in the display updating.

If this is unavoidable (the delay) then it suggests the display update should be interrupt-driven from
one of the timer/counters, so that it continues unaffected.

Why is your question in the code block? It's very hard to read that way.

I need to loop checkSMS() to check if new sms has arrived to replace current message being displayed.

What does "I need to loop checkSMS()" mean? Are you trying to call checkSMS() in a loop? Are you trying to have some kind of loop in the function?

  char *smsMSG PROGMEM = smsbuffer;   //Assign the SMS read from GSM Modem

Storing a two byte pointer in PROGMEM hardly makes sense, when the 160 byte array it points to is not in PROGMEM.

void loop()
{
    Display();     //Display character data by issuing mask data into pins
    shift();
    checkSMS();
}

Maybe you need to wait a while after calling Display() (display what?) and shift() (what is being shifted? How much?) before calling checkSMS().

You definitely should reduce your reliance on global variables. The checkSMS() function should return a value, indicating whether or not there was an SMS found, rather than setting a global variable. The Display() and shift() functions may, or may not, need to be called, depending on whether or not there is a message to display.

You definitely need to use Tools + Auto
Format. The inconsistent
indenting makes the code

hard to read. Delete
some of the useless blank

lines, too.

  if(shift_counter == 8)    //Shift counter is equal to 8, coz we use 8x8 dot matrix module of character map data

Comments do not always need to be placed after code. They can be on lines by themselves. When they are on the same line as the code, they should be short!

Of course, useless comments should just be deleted. Comments should describe what a block of code is doing. It's hard to figure out from your code just what is supposed to be happening. The few comments that are there mostly state the obvious.

@MarkT

Codes are not final so that coding format is no in correct format…sorry for that.

Anyway.

Blinking now is minimal but if the message is in size of 64 characters.
But if the sms is above 64 chars, blinking is very frequent.
Here’s the part where I call checkSMS(); now.

void load(void)          //Load data into led driver shield
{
  char counter1;
  char *LED_DATA PROGMEM = scrolling_message(showMSG);
    #ifdef OUTPUT_SERIAL
      Serial.println(LED_DATA);
    #endif
  if(LED_DATA[char_pointer+1] == '#')
  {
    char_pointer = 0;
    if(char_pointer == 0)
    {
      checkSMS();
    }
  }
  for(counter1 = 0; counter1 < 7; counter1++)
  {
    Display_Ram[64 + counter1] = pgm_read_byte(&(character_data[(LED_DATA[char_pointer] - 0x20)][counter1]));

  }
  Display_Ram[76] = 00;
  char_pointer++;

}

And also is that possible to show/repeat scrolling of message only if last char exit the last matrix at left side before it starts scrolling again from first chars. For now I am using 2 8x32 LED Matrix which is 8x64 now.

    char_pointer = 0;
    if(char_pointer == 0)

Isn't that if statement rather useless?

PaulS:

    char_pointer = 0;

if(char_pointer == 0)



Isn't that if statement rather useless?

I edited that already on my code.
That minimized the blink portion. But if sms is only 64 characters only.

if(LED_DATA[char_pointer+1] == '#')
  {
    char_pointer = 0;
      checkSMS();

  }

MarkT:
It sounds like the call to checkSMS() is taking enough time to cause a pause in the display updating.

If this is unavoidable (the delay) then it suggests the display update should be interrupt-driven from
one of the timer/counters, so that it continues unaffected.

I tried your suggestion to use Timer
Library available here Google Code Archive - Long-term storage for Google Code Project Hosting.

But after setting up a timer. There is no sms being display on my led matrix.
And on my serial monitor, I saw that after gsm.begin started=true, the rest of my codes are not running. Maybe that's why there is no message appearing, even the default one.

I tried this one.

In that library. message appearing, but stil blinking is there.