Go Down

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

maskinao

Hi! :) 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. :( 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: [Select]
#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! :D
Don't stop Learning.

Arduino Projects:

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

CrossRoads

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).
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.

maskinao


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!
Don't stop Learning.

Arduino Projects:

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

CrossRoads

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.
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.

maskinao


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.



Oh no, additional hardware. :| ahaha. getting broke because of this project.  $)

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: [Select]
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?
Don't stop Learning.

Arduino Projects:

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

maskinao

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

Code: [Select]
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
Don't stop Learning.

Arduino Projects:

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

CrossRoads

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?
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.

maskinao


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. :) I made a test sketch and I did it! :D Here's what i made:

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

thanks again! :D
Don't stop Learning.

Arduino Projects:

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

maskinao

I was able to store the messages in another array! :) 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: [Select]
#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. :) the deadline's on monday already. :(
Don't stop Learning.

Arduino Projects:

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

invader7

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.

maskinao


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? :) the whole code is there.
Don't stop Learning.

Arduino Projects:

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

invader7

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

maskinao


Yes my friend im the one :) , 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.
Don't stop Learning.

Arduino Projects:

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

invader7



Yes my friend im the one :) , 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

maskinao



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.

Don't stop Learning.

Arduino Projects:

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

Go Up