Go Down

Topic: SMS-Based LED Matrix Display. (Read 12193 times) previous topic - next topic

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maskinao

Quote
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

Code: [Select]
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:

Code: [Select]
#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. :|

any ideas?
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maskinao

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

Code: [Select]
#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

Code: [Select]
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. :) please let me know if you have ideas. thanks! :D

Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

maskinao

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:

Code: [Select]
#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. :(

thanks!

- migs
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

CrossRoads

#20
Oct 15, 2012, 09:36 pm Last Edit: Oct 15, 2012, 09:41 pm by CrossRoads Reason: 1
What is
Code: [Select]

character_data[a][b];

I don't see it defined until you use it at end. Where does data get put into it?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maskinao

it's from a separate header file called cmap.h. this is where the data gets the values to output to the LED matrix. here's the code:

Code: [Select]
const unsigned char character_data[][6] =
{
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },       //20-
    { 0x00, 0x00, 0x00, 0xF2, 0x00, 0x00 },       //21-!
    { 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00 },       //22-"
    { 0x28, 0xFE, 0x28, 0xFE, 0x28, 0x00 },       //23-#
    { 0x24, 0x54, 0x7E, 0x54, 0x48, 0x00 },       //24-$
    { 0xC4, 0xC4, 0x10, 0x26, 0x46, 0x00 },       //25-%
    { 0x6C, 0x92, 0xAA, 0x44, 0x1A, 0x00 },       //26-&
    { 0x00, 0x00, 0xA0, 0xC0, 0x00, 0x00 },       //27-'
    { 0x00, 0x00, 0x38, 0x44, 0x82, 0x00 },       //28-(
    { 0x00, 0x82, 0x44, 0x38, 0x00, 0x00 },       //29-)
    { 0x28, 0x10, 0x6C, 0x10, 0x28, 0x00 },       //2A-*
    { 0x10, 0x10, 0x6C, 0x10, 0x10, 0x00 },       //2B-+
    { 0x00, 0x00, 0x0A, 0x0C, 0x00, 0x00 },       //2C-,
    { 0x10, 0x10, 0x10, 0x10, 0x10, 0x00 },       //2D--
    { 0x00, 0x00, 0x06, 0x06, 0x00, 0x00 },       //2E-.
    { 0x04, 0x08, 0x10, 0x20, 0x40, 0x00 },       //2F-/
    { 0x7C, 0x82, 0x82, 0x82, 0x7C, 0x00 },       //30
    { 0x00, 0x42, 0xFE, 0x02, 0x00, 0x00 },       //31
    { 0x42, 0x86, 0x8A, 0x92, 0x62, 0x00 },       //32
    { 0x84, 0x82, 0xA2, 0xD2, 0x8C, 0x00 },       //33
    { 0x18, 0x28, 0x48, 0xFE, 0x08, 0x00 },       //34
    { 0xE4, 0xA2, 0xA2, 0xA2, 0x9C, 0x00 },       //35
    { 0x3C, 0x52, 0x92, 0x92, 0x0C, 0x00 },       //36
    { 0x80, 0x8E, 0x90, 0xA0, 0xC0, 0x00 },       //37
    { 0x6C, 0x92, 0x92, 0x92, 0x6C, 0x00 },       //38
    { 0x60, 0x92, 0x92, 0x94, 0x78, 0x00 },       //39
    { 0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00 },       //3A-:
    { 0x00, 0x00, 0x6A, 0x6C, 0x00, 0x00 },       //3B-//
    { 0x00, 0x10, 0x28, 0x44, 0x82, 0x00 },       //3C-<
    { 0x28, 0x28, 0x28, 0x28, 0x28, 0x00 },       //3D-=
    { 0x00, 0x82, 0x44, 0x28, 0x10, 0x00 },       //3E->
    { 0x40, 0x80, 0x8A, 0x90, 0x60, 0x00 },       //3F-?
    { 0x7C, 0x82, 0xBA, 0xAA, 0xBA, 0x70 },       //40-@
    { 0x7E, 0x88, 0x88, 0x88, 0x7E, 0x00 },       //41-A
    { 0xFE, 0x92, 0x92, 0x92, 0x6C, 0x00 },       //42-B
    { 0x7C, 0x82, 0x82, 0x82, 0x44, 0x00 },       //43-C
    { 0xFE, 0x82, 0x82, 0x44, 0x38, 0x00 },       //44-D
    { 0xFE, 0x92, 0x92, 0x92, 0x82, 0x00 },       //45-E
    { 0xFE, 0x90, 0x90, 0x90, 0x80, 0x00 },       //46-F
    { 0x7C, 0x82, 0x92, 0x92, 0x5E, 0x00 },       //47-G
    { 0xFE, 0x10, 0x10, 0x10, 0xFE, 0x00 },       //48-H
    { 0x00, 0x82, 0xFE, 0x82, 0x00, 0x00 },       //49-I
    { 0x04, 0x02, 0x82, 0xFC, 0x80, 0x00 },       //4A-J
    { 0xFE, 0x10, 0x28, 0x44, 0x82, 0x00 },       //4B-K
    { 0xFE, 0x02, 0x02, 0x02, 0x02, 0x00 },       //4C-L
    { 0xFE, 0x40, 0x30, 0x40, 0xFE, 0x00 },       //4D-M
    { 0xFE, 0x20, 0x10, 0x08, 0xFE, 0x00 },       //4E-N
    { 0x7C, 0x82, 0x82, 0x82, 0x7C, 0x00 },       //4F-O
    { 0xFE, 0x90, 0x90, 0x90, 0x60, 0x00 },       //50-P
    { 0x7C, 0x82, 0x8A, 0x84, 0x7A, 0x00 },       //51-Q
    { 0xFE, 0x90, 0x98, 0x94, 0x62, 0x00 },       //52-R
    { 0x62, 0x92, 0x92, 0x92, 0x8C, 0x00 },       //53-S
    { 0x80, 0x80, 0xFE, 0x80, 0x80, 0x00 },       //54-T
    { 0xFC, 0x02, 0x02, 0x02, 0xFC, 0x00 },       //55-U
    { 0xF8, 0x04, 0x02, 0x04, 0xF8, 0x00 },       //56-V
    { 0xFC, 0x02, 0x1C, 0x02, 0xFC, 0x00 },       //57-W
    { 0xC6, 0x28, 0x10, 0x28, 0xC6, 0x00 },       //58-X
    { 0xE0, 0x10, 0x0E, 0x10, 0xE0, 0x00 },       //59-Y
    { 0x86, 0x8A, 0x92, 0xA2, 0xC2, 0x00 },       //5A-Z
    { 0x00, 0x00, 0xFE, 0x82, 0x82, 0x00 },       //5B-[
    { 0x40, 0x20, 0x10, 0x08, 0x04, 0x00 },       //5C-\

    { 0x00, 0x82, 0x82, 0xFE, 0x00, 0x00 },       //5D-]
    { 0x20, 0x40, 0xFE, 0x40, 0x20, 0x00 },       //5E-^
    { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },       //5F-_
    { 0x80, 0x40, 0x20, 0x00, 0x00, 0x00 },       //60-`
    { 0x04, 0x2A, 0x2A, 0x2A, 0x1E, 0x00 },       //61-a
    { 0xFE, 0x12, 0x22, 0x22, 0x1C, 0x00 },       //62-b
    { 0x1C, 0x22, 0x22, 0x22, 0x04, 0x00 },       //63-c
    { 0x1C, 0x22, 0x22, 0x12, 0xFE, 0x00 },       //64-d
    { 0x1C, 0x2A, 0x2A, 0x2A, 0x18, 0x00 },       //65-e
    { 0x08, 0x3F, 0x48, 0x40, 0x20, 0x00 },       //66-f
    { 0x18, 0x25, 0x25, 0x25, 0x3E, 0x00 },       //67-g
    { 0xFE, 0x10, 0x20, 0x20, 0x1E, 0x00 },       //68-h
    { 0x00, 0x22, 0xBE, 0x02, 0x00, 0x00 },       //69-i
    { 0x02, 0x01, 0x21, 0xBE, 0x00, 0x00 },       //6A-j
    { 0x00, 0xFE, 0x08, 0x14, 0x22, 0x00 },       //6B-k
    { 0x00, 0x82, 0xFE, 0x02, 0x00, 0x00 },       //6C-l
    { 0x3E, 0x20, 0x18, 0x20, 0x1E, 0x00 },       //6D-m
    { 0x3E, 0x10, 0x20, 0x20, 0x1E, 0x00 },       //6E-n
    { 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00 },       //6F-o
    { 0x3F, 0x24, 0x24, 0x24, 0x18, 0x00 },       //70-p
    { 0x18, 0x24, 0x24, 0x14, 0x3F, 0x00 },       //71-q
    { 0x3E, 0x10, 0x20, 0x20, 0x10, 0x00 },       //72-r
    { 0x12, 0x2A, 0x2A, 0x2A, 0x04, 0x00 },       //73-s
    { 0x20, 0xFC, 0x22, 0x02, 0x04, 0x00 },       //74-t
    { 0x3C, 0x02, 0x02, 0x04, 0x3E, 0x00 },       //75-u
    { 0x38, 0x04, 0x02, 0x04, 0x38, 0x00 },       //76-v
    { 0x3C, 0x02, 0x0C, 0x02, 0x3C, 0x00 },       //77-w
    { 0x22, 0x14, 0x08, 0x14, 0x22, 0x00 },       //78-x
    { 0x38, 0x05, 0x05, 0x05, 0x3E, 0x00 },       //79-y
    { 0x22, 0x26, 0x2A, 0x32, 0x22, 0x00 },       //7A-z
    { 0x00, 0x10, 0x6C, 0x82, 0x00, 0x00 },       //7B-{
    { 0x00 },                                   //7C-|-BLANK BAR
    { 0x00, 0x82, 0x6C, 0x10, 0x00, 0x00 },       //7D-}
    { 0x18, 0x24, 0x7E, 0x24, 0x08, 0x00 },
    { 0 }                                       //7F-DO NOT USE

};


i'm not sure if character_data must take char parameters or int. i've tried both. but somehow both don't work. :| I'm really close to solving this. i can feel it. hahaha.

thanks for the help! :) appreciate it very much. :D
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

maskinao

Someone also suggested that the RX_max buffer FIFO from Software Serial was too small, which is 64. He suggested I use 128. What does this really do?

I'm going to try it out later. Off to school in a bit. :)
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

CrossRoads

Sets aside 128 bytes of SRAM for incoming messages.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maskinao

Got it quite working a little bit yesterday. :)

Code: [Select]
#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
char LED_DATA[] = " Hello! ";

//-----------------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] != '~')
        {
          smsdata[i] = smsdata[i+9];     
          i++;
        }
        i = 0;
//       Serial.print("\nParsed SMS: ");
       
        while (smsdata[i] != '~')
        {
//          Serial.print(smsdata[i]);
          i++;
        }
//       Serial.println("");
      }
    }
}

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 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 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;
  char *smsdata= announcement(message_no);                   
  Serial.println(smsdata);
  if(smsdata[char_pointer]  == '~' || smsdata[char_pointer]  == '\0')
  {
    char_pointer = 0;
    message_no++;   
    goto exit;
  }

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


it displays the text message plus a ton of random characters when the message_no1 overflows. how do i filter out the message? would really appreciate your help. :D thanks!

- Migs
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

CrossRoads

Stop the display output when you detect the end of the message?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maskinao


Stop the display output when you detect the end of the message?


the random characters display before and after the text message. i'm finding it hard to filter out. i'm trying to use string compare.
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

maskinao

Hi! it's almost working! :) I added PROGMEM to the CMAP.h

Code: [Select]
#include <avr/pgmspace.h>

const unsigned char character_data[][6] PROGMEM =
{


then i tried textiing a single Character ("L ") to the LED matrix. It displayed something. :D

Code: [Select]

void load(void)
{
  int i = 0;
  int counter1;
  char *LED_DATA = announcement(message_no);                   
  char *LED_DATA2 = fromSMS[msg_count];
 
  Serial.print("SMS DATA: ");
  Serial.println(LED_DATA);
  Serial.print("LED DATA: ");
  Serial.println(smsdata);
 
  if(smsdata[char_pointer]  == '\0')
  {
    char_pointer = 0;
//   message_no++;
  }

  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = character_data[(smsdata[char_pointer] - 0x20)][counter1];
  }
 
// if(message_no > 1)
  {
//   message_no = 0;
  }
 
  Display_Ram[37] = 00;
  char_pointer++;

}


the only problem is, the character is wrong. It kinda got messed up. What is Progmem really for?

- Migs
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

CrossRoads

progmem is for putting things like font descriptions and text strings you want to send out into flash memory and not tie up sram as if that stuff was another variablex
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

maskinao


progmem is for putting things like font descriptions and text strings you want to send out into flash memory and not tie up sram as if that stuff was another variablex


i got it 90% working last night! :) just need to polish the code a bit, try to optimize it as much as possible. :)

i'll post the code as soon as it's done. :D thanks once again!

- Migs
Don't stop Learning.

Arduino Projects:

SMS-Based LED Matrix Display
http://youtu.be/WVhDr5CNxwE

Go Up