Go Down

Topic: 7 Segment Display clock - TIME (Read 68 times) previous topic - next topic

Portyy

Hello guys,

so basically, my idea is a clock on 2 multiplexed 7SD, and minutes and hours will be switching with period 2 secs with LED indicator which one is active now. I did that, its working fine but i have big issues with getting time from PC (they will be near PC so...). I downloaded Time library, and used reference code to get time from unix timestamp entered to serial monitor. But the problem is, i put in timestamp from 1 1 1970 and somehow that stamp is saved, so everytime i try to save a actual one, it still displays in serial monitor that is 1 1 1970 00 00 00 ... idk whats happening, where is problem. I restarted arduino, turn off/on power... nothing. Here is the code, designed mostly in slovak but you may understood at least where can the problem with Time may be..
Code: [Select]

#include <Time.h>

#define TIME_MSG_LEN 11
#define TIME_HEADER 'T'
#define TIME_REQUEST 7

//T1262347200

int timer = 150;                                        //            DISPLEJ
int a = 6;                                              //            ---a---     
int b = 7;                                                //          |     |
int c = 8;                                                  //        f     b
int d = 5;                                                    //      |     |
int e = 4;                                                      //    ---g---
int f = 2;                                                        //  |     |
int g = 3;                                                       //   e     c
int dot = 9;                                                    //    |     |
int horny = 11;                                               //      ---d---   .h
int dolny = 10;                                               
int hrLED = 12;
int minLED = 13;
int hod = hour();
int mins = 1;


void setup() {
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(dot, HIGH);
}

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

void hodiny() {
  // hodiny
  if (hod == 9) {
   
      //disp1
      delay(1);
      digitalWrite(a, 1);
      digitalWrite(b, 0);
      digitalWrite(c, 0);
      digitalWrite(d, 1);
      digitalWrite(e, 0);
      digitalWrite(f, 0);
      digitalWrite(g, 1);
      digitalWrite(horny, 0);
      digitalWrite(dolny, 1);
      delay(1);
      //disp2
      digitalWrite(a, 0);
      digitalWrite(b, 1);
      digitalWrite(c, 0);
      digitalWrite(d, 0);
      digitalWrite(e, 1);
      digitalWrite(f, 0);
      digitalWrite(g, 1);
      digitalWrite(horny, 1);
      digitalWrite(dolny, 0);
      delay(1);
   
  }
  if (hod == 7) {
 
      //disp 1
      digitalWrite(a, 0);
      digitalWrite(b, 0);
      digitalWrite(c, 0);
      digitalWrite(d, 0);
      digitalWrite(e, 0);
      digitalWrite(f, 0);
      digitalWrite(g, 1);
      digitalWrite(horny, 1);
      digitalWrite(dolny, 0);
      digitalWrite(hrLED, 1);
      digitalWrite(minLED, 0);
      delay(1);
      //disp 2
      digitalWrite(a, 0);
      digitalWrite(b, 0);
      digitalWrite(c, 0);
      digitalWrite(d, 1);
      digitalWrite(e, 1);
      digitalWrite(f, 1);
      digitalWrite(g, 1);
      digitalWrite(horny, 0);
      digitalWrite(dolny, 1);
      digitalWrite(hrLED, 1);
      digitalWrite(minLED, 0);
      delay(1);
  }

}

void digitalClockDisplay(){
 
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){

  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {

  while(Serial.available() >=  TIME_MSG_LEN ){
    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') ;   
        }
      }   
      setTime(pctime);
    } 
  }
}


again, problem is that arduino have stored timestamp T1262347200 which stands for 1st of january 1970 midnight, and everytime i run program and opens serial monitor arduino displays that time and wants to synchronize (get a new stamp) at the same time which is weird and i can´t find the problem.. :/ any help is welcome :)

ghlawrence2000

You appear to be a little confused about the sync process and the value you are using. Here is a sample of the serial monitor output from your sketch :-

Code: [Select]
0:00:25 1 1 1970
waiting for sync
0:00:26 1 1 1970
waiting for sync
0:00:27 1 1 1970
waiting for sync
0:00:28 1 1 1970
waiting for sync
0:00:29 1 1 1970
waiting for sync
0:00:30 1 1 1970
T12:00:00 1 1 2010
12:00:01 1 1 2010
12:00:02 1 1 2010
12:00:03 1 1 2010
12:00:04 1 1 2010
12:00:05 1 1 2010
12:00:06 1 1 2010
12:00:07 1 1 2010


As you can see it ran for 30 seconds before I entered a time value, once the time value is registered and time is set, the 'waiting for sync' message is gone and the new time I entered is then printed and subsequently increments correctly.


The T1262347200 value you refer to is NOT Midnight 1st January 1970! 00:00.00 1/1/1970 = T0000000000. T1262347200 = 12:00.00 1/1/2010 as can be seen from the serial monitor segment above. Your sketch is working properly!


Regards,


Graham
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

Portyy

oh well thats graphical output.. thus in serial monitor i am getting actual time (UTC) 13-39-45 29.7.2016, i set two if cycles : one for hours() == 13 and one for 0, if 13 it displays 13 if 0 then .. you know, 0. When i did not enter anything displays remain off, which is fine but as soon as i put in actual timestamp (T1469799493) displays show 00 but in serial mon. i am getting actual time... and i dont understand why is that happening. Maybe there is some issues with if statement or something else. I´ll try to fix it by rewriting the code and changing some parts but basic syntax  will be the same as in OP.

ghlawrence2000

First of all, get your 7 segment code working using known numbers. I am not surprised your code is not working properly for the 7 segment display. I don't see anything in your loop() function where you set your variables to read the time!

Regards,

Graham
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

Portyy

Wow man, huge thanks for helping. I sorted it out, the problem lied in that int with hour() lies before setup() and was declared only once. So i put both hour and min int values into loop and what happened :D well it works, but i still need help with 2 minor things. 1st one is that i am in GMT +1 timeline (Bratislava, Prague, Wien...) and that unix time is weird.. currently is 16.31 in here but from the start of my arduino program (16.07 GMT+1) i have switched between 13th and 14th hour of unix time... and i absolutely dont know what is it. I am studying about unix time and why is that gap happening but if you could help... And second thing is that i forget that i will be switching between minutes and hours periodically, hours will be displayed for 2 seconds, minutes for 3 and then back to hours. But due to multiplexing displays without external IC. So when i put delay between displaying minutes and hours, one display is visible but second is blinking in 2 second period for 1ms.. So i don´t know how to switch that. But the positive message is that i finally done the time issue except that time gap :) again big thanks for that

ghlawrence2000

#5
Jul 29, 2016, 04:56 pm Last Edit: Jul 29, 2016, 04:57 pm by ghlawrence2000
Cant you just do something like int hour=hour()+1; ?

How to stop flicker is only update the display if the digit has changed.

eg:-


Code: [Select]
int previoustenhours=0;
int previoushours=0;
int previoustenmins=0;
int previousmins=0;
void loop() {
int tenhours=(hours()+1)/10;
int hours = (hours()+1) %10;
int tenmins=mins()/10;
int mins=mins() % 10;
if(previoustenhours!=tenhours) {
 (draw 10hours digit)  // <= obviously this is not real code you need the draw 10's hours digit
 previoustenhours=tenhours;
}
if(previoushours!=hours) {
 (draw hours digit) // <= obviously this is not real code you need the draw 1's hours digit
 previoushours=hours;
}
if(previoustenmins!=tenmins) {
etc
}

}


Hopefully this will help you.

Regards,

Graham
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

Portyy

well, i absolutely dont understand that code to be honest. Althrought i try it, i put in my variables and rewrite them to yours and put in example code but nothing happens .. i dont know if you know what i meant, i want to swip between hours and minutes and i dont know how to do it because i already set delay(1) to multiplex displays and when i set another delay() one of displays go crazy.. anyways thanks for helping with that time gap :)

ghlawrence2000

Can you give me a rough schematic of your 7 segment display? I don't understand what horny or hod mean. Try to explain better what you you want exactly from your 4 digits......

G
UTFT_SdRaw now included in library manager!! ;) High speed image drawing from SD card to UTFT displays for Mega & DUE.
UTFT_GHL - a VASTLY upgraded version of UTFT_CTE. Coming soon to a TFT near you! 8) Shipping April 1 2016!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy