Go Down

Topic: having problem in programming to show current date (Read 699 times) previous topic - next topic

isunshine3

there is no problem when compiling but nothing shows on display. Could anybody help me with it?

#include <LiquidCrystal.h>

#include <Time.h>



#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by Unix time_t as ten ASCII digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message

// T1262347200  //noon Jan 1 2010
LiquidCrystal lcd(12, 11, 10, 6, 4, 3, 2);

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

void loop(){   
  if(Serial.available() )
  {
    processSyncMessage();
  }
  if(timeStatus() == timeNotSet)
    Serial.println("waiting for sync message");
  else     
      digitalClockDisplay(); 
  delay(1000);
}



void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of header & 10 ASCII digits
    char c = Serial.read() ;
    Serial.print(c); 
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();         
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number   
        }
      }   
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    } 
  }
}

void digitalClockDisplay(){
  // digital clock display of the time

  Serial.print(" ");
  Serial.print(day());
  lcd.setCursor(0,0);
  lcd.print(day(),DEC);
  Serial.print(" ");
  Serial.print(month());
  lcd.setCursor(3,0);
  lcd.print(month(),DEC);
  Serial.print(" ");
  Serial.print(year());
  lcd.setCursor(6,0);
  lcd.print(year(),DEC);
  Serial.println();
}


floresta

How about trying something a bit simpler at first to make sure that your display is wired properly?

Code: [Select]

#include <LiquidCrystal.h>

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);      // put your pin numbers here

void setup()
  {
  lcd.begin(16, 2);                          // put your LCD parameters here
  lcd.print("hello, world!");
  lcd.setCursor(0,1)
  lcd.print("it works!");
  }

void loop()
  {
  }


Don

isunshine3

Yeah! I tried this and my display works well

buteman

check the pins you have connected for the LCD are the same as the ones for the Hello World one.
The reason I say that is that you have defined LiquidCrystal lcd(12, 11, 10, 6, 4, 3, 2);  <<<< 7 pins
in your sketch but the Hello World one has LiquidCrystal lcd(7, 8, 9, 10, 11, 12);   <<<< 6 pins
so you may just have it defined differently to how it is connected.
I would suggest you copy and paste what you have for the Hello World sketch and then re-connect the pins of the arduino to your LCD to correspond.
hth
Norman

MAS3

Code: [Select]
void loop(){   
  if(Serial.available() )
  {
    processSyncMessage();
  }
  if(timeStatus() == timeNotSet)
    Serial.println("waiting for sync message");
  else     
      digitalClockDisplay();
  delay(1000);
}


Nothing happens on your display ?
Comment out the first line in that loop:

Code: [Select]
void loop(){   
/*  if(Serial.available() )
/  {
    processSyncMessage();
  }*/
  if(timeStatus() == timeNotSet)
    Serial.println("waiting for sync message");
  else     
      digitalClockDisplay();
  delay(1000);
}


You should see the "waiting for sync message" message on your screen.
What other hardware (Arduino) do you use ?
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Go Up