Pages: [1]   Go Down
Author Topic: having problem in programming to show current date  (Read 669 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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();
}


* date.ino (1.82 KB - downloaded 6 times.)
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 4384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah! I tried this and my display works well
Logged

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

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
Logged

The Netherlands
Offline Offline
Edison Member
*
Karma: 50
Posts: 1708
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
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 ?
Logged

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

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 4384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
There is no reason to always use the same pins for an LCD display and there are provisions for using 6, 7, 10 or 11 connections between the LCD and the Arduino.  That is why the comment says: "// put your pin numbers here".

This information is documented but the documentation is hard to find, and there is only one poor example that does not really explain the syntax.  Look here: --> http://arduino.cc/en/Reference/LiquidCrystalConstructor


Don
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 4384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you having problem with your 'screen' which I would interpret as the serial monitor, with your 'display' which I would interpret as the LCD, or both?

Don
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I commetted out the serial instructions in your code, set c to a dummy value and changed the lcd declaration as Norman said.  If today was January 1, 1970 your code would be perfect.
Logged

Pages: [1]   Go Up
Jump to: