Pages: 1 2 [3] 4 5   Go Down
Author Topic: SMS-Based LED Matrix Display.  (Read 11075 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! smiley Here's a video of what I've done so far. I think it's 90% of what I want to do.

<iframe width="420" height="315" src="http://www.youtube.com/embed/SwLE17cIAqU" frameborder="0" allowfullscreen></iframe>

the only problem is, when the text message is loaded, it disappears after loading. smiley-sad i want it to be stored with the fixed message array. then the first text message would be overwritten if there are like, over 5 text messages received.

any ideas?

here's my code.

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

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

//-----------------LED MATRIX PINS------------------

#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

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

boolean MSG_RCVD    = false;            // no message recieved as initial value
boolean started     = false;            // set gsm as off initally
const char regnum[] = "639339182267";   // admin number
const char passRx[] = "default#";       // holds password, must be 8 char only! and ends with #
char smsdata[160];                      // sms only accept 160 characters
char numberRx[20];                      // holds sender number
int message_no;                         // message counter
char *LED_DATA = announcement(message_no); // LED_DATA pointer

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

char Display_Ram[38];                   // locates the the ASCII Character Map Display
char count;                             // counter for
unsigned char char_pointer = 0x00;      // character pointer for smsdata and LED_DATA arrays
unsigned char mask;                     // for masking the display
unsigned char shift_counter;            // for scrolling the message

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};
                   
unsigned int d;

void setup()
{
  // ---------- serial setup ----------
  gsm.begin(4800);
  pinsetup();
}

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

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;
  if(gsm.readSMS(smsdata, 160, numberRx, 20))
  {
    if (strncmp (numberRx, regnum, 11) == 0)
    {
      if (strncmp (smsdata, passRx, 8) == 0)
      {
        while (smsdata[i] != '\0')
        {
          smsdata[i] = smsdata[i+8];     
          i++;
        }
        MSG_RCVD = true;
      }
    }
  }
  else
  {
    MSG_RCVD = false;
  }
}

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 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;
 
    if(MSG_RCVD == true)
    {
      loadSMS();
    }
    else
    {
      load_data();
    }
  }
}

void load_data(void)
{
  int counter1 = 0;
  char *LED_DATA = announcement(message_no);
 
  if(LED_DATA[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
    message_no++;
  }
   
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = pgm_read_byte(&(character_data[(LED_DATA[char_pointer] - 0x20)][counter1])); //read the byte at this location
  }
 
  Display_Ram[37] = 00;
  char_pointer++;
 
  if (message_no > 1)
  {
    message_no = 0;
    checkSMS();
  }
}

void loadSMS()
{
  int counter1;
  if(smsdata[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
    MSG_RCVD == false;
    checkSMS();
  }
   
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = pgm_read_byte(&(character_data[(smsdata[char_pointer] - 0x20)][counter1])); //read the byte at this location
  }
 
  Display_Ram[37] = 00;
  char_pointer++;
 
}

thanks! smiley-grin
Logged

Don't stop Learning.

Arduino Projects:

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Make a bigger array and hold it there until something comes along to take its place.
Consumes more RAM - I think at some point you'll want to add serial SRAM to hold stuff, or move to a '1284 with its 16K of SRAM (twice that of a '2560).
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think at some point you'll want to add serial SRAM to hold stuff, or move to a '1284 with its 16K of SRAM (twice that of a '2560).

how can i add serial SRAM? changing of boards is quite far fetched right now, since the submission is really close. (Monday here in the Philippines.) I think i saved up some SRAM space due to PROGMEM. I'll try it out this afternoon. and post another video if i make some progress. hehe. thanks again!
Logged

Don't stop Learning.

Arduino Projects:

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Get a part like this
http://www.digikey.com/product-detail/en/23LC512-I%2FP/23LC512-I%2FP-ND/3543089

Do SPI.transfer()s to/from it.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Oh no, additional hardware. smiley-neutral ahaha. getting broke because of this project.  smiley-money

could you suggest a way how i could store a whole array as a member of another array?

i'm thinking its like this:

Code:
smsdata[] = " Hello! "; // message i sent to the GSM shield

sms_data[] = smsdata; // store to display over and over again


and when another text message comes along, it would delete the previous data from smsdata and restore it as a next member of SMS_DATA.

any suggestions?
Logged

Don't stop Learning.

Arduino Projects:

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

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you please give me an example of making an array of arrays? i'm thinking it would be like this:

Code:
char smsdata[160] // would hold the recieved message. with a maximum of 160 characters.

int inbox[inbox_no] //would store smsdata at index 0 and increment to store the next smsdata.

//smsdata would then clear and wait for the next message recieved.

if (inbox_no < 5), it would reset inbox_no = 0


i can't seem to code this. i've tried using typedef and other methods, but i think i'm doing something wrong. any help please?

i would like to set the
Logged

Don't stop Learning.

Arduino Projects:

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27089
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope, that's beyond my programming skills.  I'm still working on pointers into a single array.
Maybe just have 1 array and different sets of pointers into it?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope, that's beyond my programming skills.  I'm still working on pointers into a single array.
Maybe just have 1 array and different sets of pointers into it?

some one from the programming forums gave me some advice. i would use string dump and use a pointer array. smiley I made a test sketch and I did it! smiley-grin Here's what i made:

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

char smsdata[160];
char numberRx[20];
int i = 0;
int x = -1;
char *inbox[5];
boolean MSG_RCVD = false;

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

void loop()
{
  checkSMS();
}

void checkSMS()
{
  if(gsm.readSMS(smsdata, 160, numberRx, 20))
  {
    Serial.print("SMS Recieved: ");
    while (smsdata[i+1] != '\0')
    {
      Serial.print(smsdata[i]);
      i++;
    }
    i = 0;
    x++;
    Serial.println("");
    store();
  }
  else
  {
    Serial.println("No Messages");
  }
}

void store()
{
  int y;
  inbox[x] = strdup(smsdata);
  Serial.print("Inbox 1: ");
  Serial.println(inbox[0]);
  Serial.print("Inbox 2: ");
  Serial.println(inbox[1]);
  Serial.print("Inbox 3: ");
  Serial.println(inbox[2]);
  Serial.print("Inbox 4: ");
  Serial.println(inbox[3]);
  Serial.print("Inbox 5: ");
  Serial.println(inbox[4]);
  Serial.print("Inbox 6: ");
  Serial.println(inbox[5]);


  Serial.println("");
 
  if (x > 5)
  {
    x = 0;
  }
  MSG_RCVD = false;
}

it stores the text messages in inbox array, and i'll apply this in the LED MATRIX+GSM code. I'll post the code after running some tests. smiley-grin

thanks again! smiley-grin
Logged

Don't stop Learning.

Arduino Projects:

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

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was able to store the messages in another array! smiley i checked the Serial Monitor and it showed the messages. the only problem is it only displays the last received message.

i need to loop these text messages along with the fixed messages. i'm getting dizzy from all these programming. @_@ any help please?

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

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

//-----------------LED MATRIX PINS------------------

#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

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

boolean MSG_RCVD    = false;            // no message recieved as initial value
boolean started     = false;            // set gsm as off initally
const char regnum[] = "639339182267";   // admin number
const char passRx[] = "default#";       // holds password, must be 8 char only! and ends with #
char smsdata[160];                      // sms only accept 160 characters
char numberRx[20];                      // holds sender number


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

char Display_Ram[38];                   // locates the the ASCII Character Map Display
char count;                             // counter for
unsigned char char_pointer = 0x00;      // character pointer for smsdata and LED_DATA arrays
unsigned char mask;                     // for masking the display
unsigned char shift_counter;            // for scrolling the message

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};
                   
unsigned int d;
int message_no;                            // message counter
int message_no2;                           // message counter
char *LED_DATA = announcement(message_no); // LED_DATA pointer
//char *SMS_DATA = announcement2(message_no2);
char *inbox[5];
int x = -1;
int message_count;


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

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

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;
  if(gsm.readSMS(smsdata, 160, numberRx, 20))
  {
    if (strncmp (numberRx, regnum, 11) == 0)
    {
      if (strncmp (smsdata, passRx, 8) == 0)
      {
        while (smsdata[i] != '\0')
        {
          smsdata[i] = smsdata[i+8];     
          i++;                 
        }
        x++;
        message_count = x;
        MSG_RCVD = true;
        if (x == 5)
        {
          x = -1;
        }
        inbox[x] = strdup(smsdata);
        Serial.print("INBOX: ");
        Serial.println(inbox[x]);
      }
    }
  }
  else
  {
    MSG_RCVD = false;
  }
}

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 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;
 
//    while(MSG_RCVD == true)
//    {
      loadSMS();
//    }
//   else
//    {
//      load_data();
//    }
  }
}

void load_data(void)
{
  int counter1 = 0;
  char *LED_DATA = announcement(message_no);
 
  if(LED_DATA[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
    message_no++;
  }
   
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = pgm_read_byte(&(character_data[(LED_DATA[char_pointer] - 0x20)][counter1])); //read the byte at this location
  }
 
  Display_Ram[37] = 00;
  char_pointer++;
 
  if (message_no > 1)
  {
    message_no = 0;
    checkSMS();
  }
}

void loadSMS()
{
  int counter1 = 0;
 
  char *SMS_DATA = announcement1(message_count);
 
  Serial.print("SMS_DATA: ");
  Serial.println(SMS_DATA);
 
  while(SMS_DATA[char_pointer+1]  == '\0')
  {
    char_pointer = 0;
    MSG_RCVD = false;
  }
   
  for(counter1 = 0; counter1 < 5; counter1++)
  {
    Display_Ram[32 + counter1] = pgm_read_byte(&(character_data[(SMS_DATA[char_pointer] - 0x20)][counter1])); //read the byte at this location
  }
 
  Display_Ram[37] = 00;
  char_pointer++;
 
}

char *announcement1(int message_no2)
{
  char *LED_message[]={"    LCoES Announcements         ",
                       "    Hello Letranites!           "};
     
  char *SMS_message[] = { inbox[0] ,
                          inbox[1] ,
                          inbox[2] ,
                          inbox[3] ,
                          inbox[4] };
 
 
 
  if (message_no >= 1)
  {
    return LED_message[message_no2];
  }
  else if (message_no < 1 && message_no >= 6)
  {
    return SMS_message[message_no2];
  }
  else if (message_no <= 7)
  {
    message_no = 0;
    return SMS_message[message_no2];
  }
}

would really appreciate it. smiley the deadline's on monday already. smiley-sad
Logged

Don't stop Learning.

Arduino Projects:

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if you post me the part of code which read the last message i will try to help you , my gsm shield is not here , so i didn't read how it works.
Logged

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

if you post me the part of code which read the last message i will try to help you , my gsm shield is not here , so i didn't read how it works.

weren't you the one asking me about GSM shields in the messages? smiley the whole code is there.
Logged

Don't stop Learning.

Arduino Projects:

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes my friend im the one smiley , your problem is at loadSMS() or at checkSMS() ?
Logged

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes my friend im the one smiley , your problem is at loadSMS() or at checkSMS() ?

it's just the looping of the text messages. i can't seem to loop them properly.
Logged

Don't stop Learning.

Arduino Projects:

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes my friend im the one smiley , your problem is at loadSMS() or at checkSMS() ?

it's just the looping of the text messages. i can't seem to loop them properly.

yes i know that , but which part of the code loops through the messages ?  i want to see that code to help you
Logged

Philippines
Offline Offline
Jr. Member
**
Karma: 5
Posts: 81
Graduating Computer Engineering Student
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


yes i know that , but which part of the code loops through the messages ?  i want to see that code to help you

look for the shift and load functions. that's where the loop and shift happens.

Logged

Don't stop Learning.

Arduino Projects:

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

Pages: 1 2 [3] 4 5   Go Up
Jump to: