SMS-Based LED Matrix Display.

Hi Guys. I'm working on a project, SMS-Based LED Matrix Display. this would display messages sent from a mobile phone to an LED matrix.

the GSM code can be found here: Arduino Forum

And the LED-matrix part is attached in this message.

both work well independently, but when I integrate the two codes together and stacked the Arduino, GSM Shield and LED-matrix driver shield on one another, there's nothing being displayed on both Serial Monitor and LED Matrix. :frowning:

I think there may be a Pin conflict? Hope you guys could help me out. thanks! :slight_smile:

WORKING_time_announcment.rar (3.23 KB)

What pins are being used? Review your different code listings and see which device is using what pin.

for the LED-Matrix Driver, here are the pins i'm using and their pinModes.

const char CLK = 5; 
const char DAT = 6; 
const char STR = 7; 
const char K0 = A0; 
const char K1 = A1; 
const char K2 = A2; 
const char K3 = A3; 
const char K4 = 8; 
const char K5 = 9; 
const char K6 = 10; 
const char K7 = 11; 

void setup() {                
  pinMode(CLK, OUTPUT);     
  pinMode(DAT, OUTPUT);     
  pinMode(STR, OUTPUT);     
  pinMode(K0, OUTPUT);     
  pinMode(K1, OUTPUT);     
  pinMode(K2, OUTPUT);     
  pinMode(K3, OUTPUT);     
  pinMode(K4, OUTPUT);     
  pinMode(K5, OUTPUT);     
  pinMode(K6, OUTPUT);     
  pinMode(K7, OUTPUT);  

  digitalWrite(K0,HIGH);  
  digitalWrite(K1,HIGH);  
  digitalWrite(K2,HIGH);  
  digitalWrite(K3,HIGH);  
  digitalWrite(K4,HIGH);  
  digitalWrite(K5,HIGH);  
  digitalWrite(K6,HIGH);  
  digitalWrite(K7,HIGH);

as for the GSM, i'm not really sure. I used pins 2 and 3 to define TX, RX. does the GSM Shield other pins as well?

thanks!

  • Migs

Over in the other listing you have

#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>

and
  Serial.begin(9600);
  if (gsm.begin(4800)){

I don't see where the pins are called out that these are using. So except for 0,1 for Serial.begin its hard to say.
How about listing all of the code here?

Here's my code for GSM:

/*

GSM BASED LED MATRIX DISPLAY USING ARDUINO
October 2012

*/

#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>

// ---------- for sms ----------

char smsbuffer[160];	   //holds buffered data
char smsdata[160];         //sms only accept 160 char, remaining for header
char numberRx[20];         //holds sender number

char incomingChar;

boolean started=false;

//---------- registered numbers ----------
char regnum[] = {"639339182267"};
char passRx[] = {"default#"};           //holds password, must be 8 char only! and ends with #
char parSMS[160];

void setup ()
{
  gsmsetup();  
}


void loop ()
{
  checkSMS();
}


void gsmsetup(void)
// ---------- serial setup ----------
{
  Serial.begin(9600);
  if (gsm.begin(4800)){
    Serial.println("GSM SHIELD READY");
    started=true;  
  }
  else Serial.println("GSM SHIELD IDLE");
}

void checkSMS()
// ---------- check if there is new message ----------
{
   if(started){	
    if(gsm.readSMS(smsbuffer, 160, numberRx, 20))
    {
      Serial.print("\nFrom: ");
      Serial.print(numberRx);
      Serial.print("\nMessage: ");
      Serial.print(smsbuffer);
      Serial.println("\n");
    }
    delay(1000);
    checkSender();
  }
}

void checkSender()
{
  char numRx[12];
  int p = sizeof(regnum);
  for (int x=0;x<=p;x++)
  {
    numRx[x]= regnum[x];
  }
  
  if (strncmp (numberRx, numRx, 11) == 0)
    {
    Serial.println("Authorized Sender.");
    checkPassword();;
    }
    
  else
  {
    Serial.println("Unauthorized Sender."); 
  }
}

void checkPassword()
{
 
  // ---------- check for password in string ------------
  if (strncmp (smsbuffer, passRx, 8) == 0)
  {
    Serial.println("Password Correct.");
    parseSMS();
  }
  else
  {
    Serial.println("Password inCorrect.");
  }
}  

void parseSMS()
{
  int y = 0;
  int i = 9;
  Serial.print("\nSMS Buffer: ");
  while (smsbuffer[i] != '\0')
  {
    parSMS[y] = smsbuffer[i];
    Serial.print(smsbuffer[i]);
    i++;
    y++;  
  }
  loadSMS(); 
}

void loadSMS()
{
  int i = 0;
  Serial.print("\nParsed SMS: ");
  while (smsbuffer[i] != '\0')
  {
    Serial.print(parSMS[i]);
    i++; 
  }
  Serial.println("");
}

Here's my code for LED Matrix Display

#include <DateTime.h>
#include <DateTimeStrings.h>
#include <stdio.h>
#include <stdlib.h>
#include "cmap.h"


unsigned int d;
unsigned char char_pointer;
char Display_Ram[38];
unsigned char mask;

int message_no;

char count;	
unsigned char shift_counter;

#define INTEN 6500      //speed the higher the value, the slower the scroll

const char CLK = 5; 
const char DAT = 6; 
const char STR = 7; 
const char K0 = A0; 
const char K1 = A1; 
const char K2 = A2; 
const char K3 = A3; 
const char K4 = 8; 
const char K5 = 9; 
const char K6 = 10; 
const char K7 = 11; 

void setup() {                
  pinMode(CLK, OUTPUT);     
  pinMode(DAT, OUTPUT);     
  pinMode(STR, OUTPUT);     
  pinMode(K0, OUTPUT);     
  pinMode(K1, OUTPUT);     
  pinMode(K2, OUTPUT);     
  pinMode(K3, OUTPUT);     
  pinMode(K4, OUTPUT);     
  pinMode(K5, OUTPUT);     
  pinMode(K6, OUTPUT);     
  pinMode(K7, OUTPUT);  

  digitalWrite(K0,HIGH);  
  digitalWrite(K1,HIGH);  
  digitalWrite(K2,HIGH);  
  digitalWrite(K3,HIGH);  
  digitalWrite(K4,HIGH);  
  digitalWrite(K5,HIGH);  
  digitalWrite(K6,HIGH);  
  digitalWrite(K7,HIGH);  

  for(d=0;d<32;d++)
  {
    clock();
  }
  strobe();
  d = 0;
    
    DateTime.sync(DateTime.makeTime(0, 15, 10, 12, 9, 2012)); // default start, 00:00:00 at tuesday, october 9, 2012
  // sec, min, hour, date, month, year // Replace this with the most current time
  //  NOTE: month January starts from 0.

//   Serial.begin(9600);
}

void loop(){
//  unsigned long  prevtime;
//  if(DateTime.available()) { // update clocks if time has been synced
 //   digitalWrite(13,LOW);  // first flash the LED
 //   prevtime = DateTime.now();
 //   while( prevtime == DateTime.now() )  // wait for the second to rollover
  //      ;
    DateTime.available(); //refresh the Date and time properties
  //  digitalClockDisplay( );   // update digital clock
  //  Serial.println("");
    // send our time to any app at the other end of the serial port
 /*   Serial.print( TIME_HEADER,BYTE); // this is the header for the current time
    Serial.println(DateTime.now());
    digitalWrite(13,HIGH);  */
 // }
  
  
  Display();
  shift();

}		

void shift(void) 
{
  for (int val=0; val<37; val++){
    Display_Ram[val] = Display_Ram[val+1];
  }
  
  shift_counter++;
  if(shift_counter == 6){
    shift_counter = 0;
    load();
  }
}

void Display(void)
{
  mask = 0x01;
  scan();
  digitalWrite(K7,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K7,HIGH);

  mask = 0x02;
  scan();
  digitalWrite(K6,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K6,HIGH);

  mask = 0x04;
  scan();
  digitalWrite(K5,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K5,HIGH);

  mask = 0x08;
  scan();
  digitalWrite(K4,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K4,HIGH);

  mask = 0x10;
  scan();
  digitalWrite(K3,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K3,HIGH);

  mask = 0x20;
  scan();
  digitalWrite(K2,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K2,HIGH);

  mask = 0x40;
  scan();
  digitalWrite(K1,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K1,HIGH);

  mask = 0x80;
  scan();
  digitalWrite(K0,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K0,HIGH);
}

void load(void){
  char counter1;
  
  char *LED_DATA= announcement(message_no);                   
  
  if(LED_DATA[char_pointer]  == '\0'){
    char_pointer = 0;
    message_no++;
    if (message_no >12){
      message_no = 0; 
    }
    goto exit;
  }

  for(counter1 = 0; counter1 < 5; counter1++){
    //LED_DATA[char_pointer] - 0x20 =  ASCII code - 32
    //character_data[character/element from cmap.h][array in cmap representing each column]
    Display_Ram[32 + counter1] = character_data[(LED_DATA[char_pointer] - 0x20)][counter1];
  }
  Serial.println(LED_DATA);	
//  Serial.print("*****");
//  Serial.println(DateTime.Year,DEC);
  Display_Ram[37] = 00;	
  char_pointer++;
  exit:
    counter1++; //do nothing
}


char *announcement(int message_no1){

//char *day_digit;
//itoa(DateTime.Day,day_digit, DEC);
char *Month_string = DateTimeStrings.monthStr(DateTime.Month);
//char *Day_string = DateTimeStrings.dayStr(DateTime.DayofWeek);
char *day_digit = convert_byte(DateTime.Day);
char *year_digit = convert_year(DateTime.Year-100);
char *min_digit = convert_byte(DateTime.Minute);
char *hr_digit = convert_byte(DateTime.Hour);


char *LED_message[]={"Today is ",
                     //Day_string,
                     //"      ",
                     Month_string,
                     day_digit,
                     ",",
                     year_digit,
                     
                     "   Time: ",
                     hr_digit,
                     ":",
                     min_digit,
		     "     LCoES Announcements            ",
		     "Oct. 11-17 Final Examination       ",
                     "Oct. 18 Semestral Break       ", 
                     "Enjoy your vacation!!!       ",
                     "See you next Semester       "};
      
	return LED_message[message_no1];
}


char *convert_byte(byte number){
  char *digit[]={"00","01","02","03","04","05","06","07","08","09","10",
                      "11","12","13","14","15","16","17","18","19","20",
                      "21","22","23","24","25","26","27","28","29","30",
                      "31","32","33","34","35","36","37","38","39","40",
                      "41","42","43","44","45","46","47","48","49","50",
                      "51","52","53","54","55","56","57","58","59","60"};
               
  return digit[number];  
}

char *convert_year(byte year_number){
  char *year_digit[]={"2000","2001","2002","2003","2004","2005","2006","2007","2008",
                 "2009","2010","2011","2012","2013","2014","2015","2016",
                 "2017","2018","2019","202","2021","2022","2023","2024"};
  return year_digit[year_number];
}

void Clear_Display_Ram(void){
  unsigned char rcount;
  for(rcount = 0; rcount < 37; rcount++)
    Display_Ram[rcount] = 0xff;
}

void scan(void){
  for (count=32;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
}

Hope you could help me. thanks!

"but when I integrate the two codes together and stacked the Arduino, GSM Shield and LED-matrix driver shield on one another, there's nothing being displayed on both Serial Monitor and LED Matrix.

So where's the combined code? That's what you're try to debug, yes?

So where's the combined code? That's what you're try to debug, yes?

oh sorry. I used a simpler code first for the LED matrix, but it works in a similar way. then i combined it to the GSM code. here it is.

#include "cmap.h"
#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>

char smsbuffer[160];	   //holds buffered data
char smsdata[160];         //sms only accept 160 char, remaining for header
char numberRx[20];         //holds sender number

char incomingChar;

boolean started=false;

//---------- registered numbers ----------
char regnum[] = {"639339182267"};
char passRx[] = {"default#"};           //holds password, must be 8 char only! and ends with #
char parSMS[160];

int d;
unsigned char char_pointer;
char Display_Ram[38];
unsigned char mask;

char count;	
unsigned char shift_counter;

int newmessage = 0;

#define INTEN 6000

const char CLK = 5; 
const char DAT = 6; 
const char STR = 7; 
const char K0 = A0; 
const char K1 = A1; 
const char K2 = A2; 
const char K3 = A3; 
const char K4 = 8; 
const char K5 = 9; 
const char K6 = 10; 
const char K7 = 11;

void setup() 
{
  gsmsetup();   
  pinMode(CLK, OUTPUT);     
  pinMode(DAT, OUTPUT);     
  pinMode(STR, OUTPUT);     
  pinMode(K0, OUTPUT);     
  pinMode(K1, OUTPUT);     
  pinMode(K2, OUTPUT);     
  pinMode(K3, OUTPUT);     
  pinMode(K4, OUTPUT);     
  pinMode(K5, OUTPUT);     
  pinMode(K6, OUTPUT);     
  pinMode(K7, OUTPUT);
  
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  
  digitalWrite(K0,HIGH);  
  digitalWrite(K1,HIGH);  
  digitalWrite(K2,HIGH);  
  digitalWrite(K3,HIGH);  
  digitalWrite(K4,HIGH);  
  digitalWrite(K5,HIGH);  
  digitalWrite(K6,HIGH);  
  digitalWrite(K7,HIGH);  

  for(d=0;d<32;d++)
  {
    clock();
  }
  strobe();
  d = 0;
}

void loop()
{
  Display();
  shift();
  newmessage++;
  if (newmessage == 500)
  {
    checkSMS();
  }
}		


void gsmsetup(void)
// ---------- serial setup ----------
{
  Serial.begin(9600);
  if (gsm.begin(4800)){
    Serial.println("GSM SHIELD READY");
    started=true;  
  }
  else Serial.println("GSM SHIELD IDLE");
}

void checkSMS()
// ---------- check if there is new message ----------
{
   if(started){	
    if(gsm.readSMS(smsbuffer, 160, numberRx, 20))
    {
      Serial.print("\nFrom: ");
      Serial.print(numberRx);
      Serial.print("\nMessage: ");
      Serial.print(smsbuffer);
      Serial.println("\n"); 
    }
    delay(1000);
    checkSender();
  }
}

void checkSender()
{
  char numRx[12];
  int p = sizeof(regnum);
  for (int x=0;x<=p;x++)
  {
    numRx[x]= regnum[x];
  }
  
  if (strncmp (numberRx, numRx, 11) == 0)
    {
    Serial.println("Authorized Sender.");
    checkPassword();;
    }
    
  else
  {
    Serial.println("Unauthorized Sender."); 
  }
}

void checkPassword()
{
 
  // ---------- check for password in string ------------
  if (strncmp (smsbuffer, passRx, 8) == 0)
  {
    Serial.println("Password Correct.");
    parseSMS();
  }
  else
  {
    Serial.println("Password inCorrect.");
  }
}  

void parseSMS()
{
  int y = 0;
  int i = 9;
  Serial.print("\nSMS Buffer: ");
  while (smsbuffer[i] != '\0')
  {
    parSMS[y] = smsbuffer[i];
    Serial.print(smsbuffer[i]);
    i++;
    y++;  
  }

  i = 0;
  Serial.print("\nParsed SMS: ");
  while (smsbuffer[i] != '\0')
  {
    Serial.print(parSMS[i]);
    i++; 
  }
  Serial.println("");
  newmessage = 0;
}

void shift(void) 
{
  for (int x=0;x<37;x++)
  {
    Display_Ram[x] = Display_Ram[x+1];
  }
  shift_counter++;
  if(shift_counter == 6){
    shift_counter = 0;
    load();
  }
}

void Display(void)
{
  mask = 0x01;
  scan();
  digitalWrite(K7,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K7,HIGH);

  mask = 0x02;
  scan();
  digitalWrite(K6,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K6,HIGH);

  mask = 0x04;
  scan();
  digitalWrite(K5,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K5,HIGH);

  mask = 0x08;
  scan();
  digitalWrite(K4,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K4,HIGH);

  mask = 0x10;
  scan();
  digitalWrite(K3,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K3,HIGH);

  mask = 0x20;
  scan();
  digitalWrite(K2,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K2,HIGH);

  mask = 0x40;
  scan();
  digitalWrite(K1,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K1,HIGH);

  mask = 0x80;
  scan();
  digitalWrite(K0,LOW);
  for(d=0;d<INTEN;d++){}
  digitalWrite(K0,HIGH);
}

void load(void)
{
  char counter1;
  if(smsdata[char_pointer+1] == '~')
    char_pointer = 0;
  for(counter1 = 0; counter1 < 5; counter1++){
    Display_Ram[32 + counter1] = character_data[(smsdata[char_pointer] - 0x20)][counter1];
  }	
  Display_Ram[37] = 00;	
  char_pointer++;
}

void Clear_Display_Ram(void){
  unsigned char rcount;
  for(rcount = 0; rcount < 37; rcount++)
    Display_Ram[rcount] = 0xff;
}

void scan(void){
  for (count=32;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
}

i'm getting fuzzy characters out of the LED Matrix. I'm guessing the GSM code and LED matrix can't run simultaneously, because i tired using loop statements before running the displays and it kinda worked.

  • Migs

To start:
"there's nothing being displayed on both Serial Monitor and LED Matrix."

and now:
"i'm getting fuzzy characters out of the LED Matrix. "
So some improvement?

and how about the serial monitor?

in void setup(), you call

  gsmsetup();
which then calls
  Serial.begin(9600);
  if (gsm.begin(4800)){

so you might think pins 0,1 (serial) and 2,3 (gsm serial? still not seeing software serial setting up pins 2,3)
would be serial ports - but then back in void setup you set those same pins as inputs

 pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);

which might be interfering with their use as serial ports.

To start:
"there's nothing being displayed on both Serial Monitor and LED Matrix."

and now:
"i'm getting fuzzy characters out of the LED Matrix. "
So some improvement?

Yes Definitely. It's an improvement. Random display is better than no display at all. :smiley:

pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);

I actually just thought of utilizing those pins. but didn't use them anyway.

and how about the serial monitor?

when i open the serial monitor, the LED matrix stop and turn off. but when I deleted the pinModes of 0-3, it worked, but now i'm getting a ON-OFF state LED Matrix with the same Random ASCII characters.

just a few more tweaks i guess! :slight_smile: thanks!

  • Migs

I'm not seeing why the serial port has any impact.

I'm not seeing why the serial port has any impact.

i'm not also sure why. When i start the program, the LED Matrix just displays the random character continuously. but when i open the serial monitor, it blinks and scrolls very slowly, around 30 seconds per dot.

could you see if there is a problem with this code?

void load(void)
{
char counter1;
if(smsdata[char_pointer+1] == '~')
char_pointer = 0;
for(counter1 = 0; counter1 < 5; counter1++){
Display_Ram[32 + counter1] = character_data[(smsdata[char_pointer] - 0x20)][counter1];
}
Display_Ram[37] = 00;
char_pointer++;
}

thats the one that locates the appropriate character on the character_data (CMAP.H)

Maybe its just an overall use of SRAM?
I see you have a lot of arrays defined, some long serial.print messages.
How about shortening some of those up for testing?

It partially worked last night. First it displayed the usual garbage, but when i sent a message to the GSM Shield, it displayed some text, then some garbage again. it displayed "639339182267hello!"

some improvement again i guess. :slight_smile:

Maybe its just an overall use of SRAM?
I see you have a lot of arrays defined, some long serial.print messages.
How about shortening some of those up for testing?

i'll try your suggestion. :slight_smile: maybe it's consuming too much memory. But the sketch shows that i only consume around 11k when there's 32k available.

"11k when there's 32k available. "
That's Flash.
All the arrays & strings & variables are in SRAM.
You're using an Uno? You've only got 2K.

"11k when there's 32k available. "
That's Flash.
All the arrays & strings & variables are in SRAM.
You're using an Uno? You've only got 2K.

oh. i see. how do i know how much SRAM i've consumed already?

Umm, browse around for "memory usage", something like that, can add a memory call in your program and have it display how much is used.

Umm, browse around for "memory usage", something like that, can add a memory call in your program and have it display how much is used.

i think you're right. it's the memory. I found a code that shows the memory use of a sketch

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.print("free memory = ");
Serial.print(availableMemory());
Serial.print(" - memory used = ");
Serial.println(2048-availableMemory());
}

int availableMemory()
{
  int size = 8192;
  byte *buf;
  while ((buf = (byte *) malloc(--size)) == NULL);
  free(buf);
  return size;
}

i inserted this into the GSM & LED codes and found that i had only a small space. so i cannot combine them. i tried optimizing the code. here's what i got so far:

#include "cmap.h"
#include <sms.h>
#include <SoftwareSerial.h>

#define INTEN 6500      //speed the higher the value, the slower the scroll

const char CLK = 5; 
const char DAT = 6; 
const char STR = 7; 
const char K0 = A0; 
const char K1 = A1; 
const char K2 = A2; 
const char K3 = A3; 
const char K4 = 8; 
const char K5 = 9; 
const char K6 = 10; 
const char K7 = 11; 

// ---------- for sms ----------

char smsdata[160];         //sms only accept 160 char, remaining for header
char numberRx[20];         //holds sender number

boolean started=false;

//---------- registered numbers ----------
char regnum[] = {"639339182267"};
char passRx[] = {"default#"};           //holds password, must be 8 char only! and ends with #
int pins[] = { CLK, DAT, STR, K0, K1, K2, K3, K4, K5, K6, K7 };
int mask_data[] = {0, 0, 0, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

unsigned int d;
unsigned char char_pointer;
char Display_Ram[38];
unsigned char mask;

int message_no;

char count;	
unsigned char shift_counter;

void setup() 
{ 
  gsmsetup();
  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<32;d++)
  {
    clock();
  }
  strobe();
  d = 0; 

  Serial.print("free memory = ");
  Serial.print(availableMemory());
  Serial.print(" - memory used = ");
  Serial.println(2048-availableMemory());  
}

void loop()
{
 
  Display();
  shift();
  checkSMS();  
}		

void shift(void) 
{
  for (int val=0; val<37; val++)
  {
    Display_Ram[val] = Display_Ram[val+1];
  }
  shift_counter++;
  if(shift_counter == 6)
  {
    shift_counter = 0;
    load();
  }
}

void Display(void)
{

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

}

void load(void)
{
  char counter1;
  char *LED_DATA= announcement(message_no);                   
  
  if(LED_DATA[char_pointer]  == '\0')
  {
    char_pointer = 0;
    message_no++;
    if (message_no > 6)
    {
      message_no = 0; 
    }
    goto exit;
  }

  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = character_data[(LED_DATA[char_pointer] - 0x20)][counter1];
  }
  Display_Ram[37] = 00;	
  char_pointer++;
  exit:
  counter1++;
}


char *announcement(int message_no1)
{
  char *LED_message[]={"LCoES Announcements            ",
		     "Oct. 11-17 Final Examination       ",
                     "Oct. 18 Semestral Break       ", 
                     "Enjoy your vacation!!!       ",
                     "See you next Semester       "};
      
  return LED_message[message_no1];
}

void scan(void)
{
  for (count=32;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
}



void gsmsetup(void)
// ---------- serial setup ----------
{
  Serial.begin(9600);
  if (gsm.begin(4800)){
    Serial.println("GSM SHIELD READY");
    started=true;  
  }
  else Serial.println("GSM SHIELD IDLE");
}

void checkSMS()
// ---------- check if there is new message ----------
{
   if(started){	
    if(gsm.readSMS(smsdata, 160, numberRx, 20))
    {
      Serial.print("\nFrom: ");
      Serial.print(numberRx);
      Serial.print("\nMessage: ");
      Serial.print(smsdata);
      Serial.println("\n");
    }
    delay(1000);
    checkSender();
  }
}

void checkSender()
{  
  if (strncmp (numberRx, regnum, 11) == 0)
    {
    Serial.println("Authorized Sender.");
    checkPassword();;
    }   
  else
  {
    Serial.println("Unauthorized Sender."); 
  }
}

void checkPassword()
{
 
  // ---------- check for password in string ------------
  if (strncmp (smsdata, passRx, 8) == 0)
  {
    Serial.println("Password Correct.");
    parseSMS();
  }
  else
  {
    Serial.println("Password inCorrect.");
  }
}  

void parseSMS()
{
  int i;
  Serial.print("\nSMS Buffer: ");
  while (smsdata[i] != '\0')
  {
    smsdata[i] = smsdata[i+9];
    Serial.print(smsdata[i]);
    i++; 
  }
  loadSMS(); 
}

void loadSMS()
{
  int i = 0;
  Serial.print("\nParsed SMS: ");
  while (smsdata[i] != '\0')
  {
    Serial.print(smsdata[i]);
    i++; 
  }
  Serial.println("");
}

int availableMemory()
{
  int size = 2048;
  byte *buf;
  while ((buf = (byte *) malloc(--size)) == NULL);
  free(buf);
  return size;
}

but it stopped working. :expressionless:

any ideas?

All the function calls make this hard to follow.
Why not put all the setup stuff together - like gsmsetup within setup.
Then put the reset in the order they are used.

Hi! here's what i got. i tried to optimize the code as much as possible.

#include "cmap.h"
#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>
#define INTEN 6500      //speed the higher the value, the slower the scroll


//-------------------GSM VARIABLES-----------------------

boolean started = false;
char regnum[] = "639339182267";
char passRx[] = "default#";           //holds password, must be 8 char only! and ends with #
char smsdata[160];         //sms only accept 160 char, remaining for header
char numberRx[20];         //holds sender number

//-----------------LED MATRIX VARIABLES------------------

const char CLK = 5; 
const char DAT = 6; 
const char STR = 7; 
const char K0 = A0; 
const char K1 = A1; 
const char K2 = A2; 
const char K3 = A3; 
const char K4 = 8; 
const char K5 = 9; 
const char K6 = 10; 
const char K7 = 11;

char Display_Ram[38];
char count;	
unsigned char char_pointer = 0x00;
unsigned char mask;
unsigned char shift_counter;
int message_no;
int pins[] = { CLK, DAT, STR, K0, K1, K2, K3, K4, K5, K6, K7 };
int mask_data[] = {0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
unsigned int d;



void setup() 
{ 
  gsmsetup();
  pinsetup(); 
}

void loop()
{
  checkSMS();
  Display();
  shift(); 
}


void gsmsetup(void)
// ---------- serial setup ----------
{
  Serial.begin(9600);
  gsm.begin(4800);  
}

void pinsetup()
{
  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<32;d++){
    clock();
  }
  strobe();
  d = 0;
}

void checkSMS()
// ---------- check if there is new message ----------
{
  int i;
  gsm.readSMS(smsdata, 160, numberRx, 20);
  delay(1000);
  if (strncmp (numberRx, regnum, 11) == 0)
    {
      if (strncmp (smsdata, passRx, 8) == 0)
      {
        while (smsdata[i] != '\0')
        {
          smsdata[i] = smsdata[i+9];
          i++; 
        }
        i = 0;
        Serial.print("\nParsed SMS: ");
        while (smsdata[i] != '\0')
        {
          Serial.print(smsdata[i]);
          i++; 
        }
        Serial.println("");
      }
    }
}

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

void scan(void){
  for (count=33;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
}

void shift(void) 
{
  for (int val=0; val<37; val++)
  {
    Display_Ram[val] = Display_Ram[val+1];
  }
  
  shift_counter++;
  if(shift_counter == 6){
    shift_counter = 0;
    load();
  }
}

void load(void)
{ 
  char counter1;
  if(smsdata[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
  } 
  int a = smsdata[char_pointer] - 0x20;
  Serial.println(a);
  Serial.print ("load data; ");
//  Serial.println(character_data[a][counter1]);
/*  
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = character_data[-0x20][5]; 
    Serial.print ("load data; ");
    Serial.println(Display_Ram[32 + char_pointer]); 
  }
  
  while (smsdata[char_pointer+1] = '\0')
  {
    Serial.print ("load data; ");
    Serial.println(Display_Ram[32 + char_pointer]);
    char_pointer++;
  }
  
  Display_Ram[37] = 00;	
  char_pointer++;
  exit:
  counter1++;*/
}

i noticed that this is the line where the code stops working

void load(void)
{ 
  char counter1;
  if(smsdata[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
  } 
  int a = smsdata[char_pointer] - 0x20;
  Serial.println(a);
  Serial.print ("load data; ");
//  Serial.println(character_data[a][counter1]);
/*  
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = character_data[-0x20][5]; 
    Serial.print ("load data; ");
    Serial.println(Display_Ram[32 + char_pointer]); 
  }
  
  while (smsdata[char_pointer+1] = '\0')
  {
    Serial.print ("load data; ");
    Serial.println(Display_Ram[32 + char_pointer]);
    char_pointer++;
  }
  
  Display_Ram[37] = 00;	
  char_pointer++;
  exit:
  counter1++;*/
}

i'm gonna still try to do this tomorrow. :slight_smile: please let me know if you have ideas. thanks! :smiley:

i kinda figured out what makes the code go wrong. whenever i call character_data, the Serial Monitor does not respond. any ideas why?

here's an updated code:

#include "cmap.h"
#include <SIM900.h>
#include <sms.h>
#include <SoftwareSerial.h>
#define INTEN 6500      //speed the higher the value, the slower the scroll


//-------------------GSM VARIABLES-----------------------

boolean started = false;
char regnum[] = "639339182267";
char passRx[] = "default#";           //holds password, must be 8 char only! and ends with #
char smsdata[160];         //sms only accept 160 char, remaining for header
char numberRx[20];         //holds sender number

//-----------------LED MATRIX VARIABLES------------------

const char CLK = 5; 
const char DAT = 6; 
const char STR = 7; 
const char K0 = A0; 
const char K1 = A1; 
const char K2 = A2; 
const char K3 = A3; 
const char K4 = 8; 
const char K5 = 9; 
const char K6 = 10; 
const char K7 = 11;

char Display_Ram[38];
char count;	
unsigned char char_pointer = 0x00;
unsigned char mask;
unsigned char shift_counter;
int message_no;
int pins[] = { CLK, DAT, STR, K0, K1, K2, K3, K4, K5, K6, K7 };
int mask_data[] = {0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
unsigned int d;



void setup() 
{ 
  gsmsetup();
  pinsetup(); 
}

void loop()
{
  checkSMS();
  Display();
  shift(); 
}


void gsmsetup(void)
// ---------- serial setup ----------
{
  Serial.begin(9600);
  gsm.begin(4800);  
}

void pinsetup()
{
  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<32;d++){
    clock();
  }
  strobe();
  d = 0;
}

void checkSMS()
// ---------- check if there is new message ----------
{
  int i;
  gsm.readSMS(smsdata, 160, numberRx, 20);
  delay(1000);
  if (strncmp (numberRx, regnum, 11) == 0)
    {
      if (strncmp (smsdata, passRx, 8) == 0)
      {
        while (smsdata[i] != '\0')
        {
          smsdata[i] = smsdata[i+9];
          i++; 
        }
        i = 0;
        Serial.print("\nParsed SMS: ");
        while (smsdata[i] != '\0')
        {
          Serial.print(smsdata[i]);
          i++; 
        }
        Serial.println("");
      }
    }
}

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

void scan(void){
  for (count=33;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
}

void shift(void) 
{
  for (int val=0; val<37; val++)
  {
    Display_Ram[val] = Display_Ram[val+1];
  }
  
  shift_counter++;
  if(shift_counter == 6){
    shift_counter = 0;
    load();
  }
}

void load(void)
{ 
  int a;
  int b;
  unsigned char c;
  char counter1;
  if(smsdata[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
  } 
  
  a = (smsdata[char_pointer] - 0x20);
  b = counter1;
  c = character_data[a][b];
  Serial.print("\na: ");
  Serial.print(a);
  Serial.print("\nb: ");
  Serial.print(b); 
  Serial.print ("\nload data: ");
  Serial.println(c);
/*  
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = character_data[a][b]; 
    Serial.print ("load data; ");
    Serial.println(Display_Ram[32 + char_pointer]); 
  }
  
  while (smsdata[char_pointer+1] = '\0')
  {
    Serial.print ("load data; ");
    Serial.println(Display_Ram[32 + char_pointer]);
    char_pointer++;
  }
  
  Display_Ram[37] = 00;	
  char_pointer++;
  exit:
  counter1++;*/
}

by the way, i'm using an ATmega32.
please help me guys, the deadline of this project is really near. :frowning:

thanks!

  • migs