Hawkeye72
Posts: 2
Joined: Fri May 22, 2020 12:01 pm

Raspberry Pi as a clock for UTC + local time and date

Sun Aug 01, 2021 4:33 pm

Hello,
at the moment I am beginning again with amateur radio. After 25 non active years. 25 years ago you could buy digital radio controlled clocks (here in Germany: DCF77) which worked with a time zone offset. So you could let them display UTC. Unfortunately I can't find such clocks any more.

What I am looking for is a digital clock which displays UTC and local time (middle european time), date and (best) the weekday for the two time zones. On amateur radio, radio contacts are logged in UTC. So I do not want to calculate each time I need UTC - but just see it. I also want to see - at the same "recognition level" - the local time. Not to be too late in real life and get real trouble! ;-)

I also want, that the clock is exactly controlled. First choice is radio controlled (DCF77) but NTP is also fine (and already included in a Raspberry Pi!!!). As I do not want to build an hardware DCF77 receiver for the Raspberry, I prefer a NTP based solution on the Raspberry. By checking the summer-/winter-time I also want that the UTC-offset is always set correctly.

(Of course you might say: Hey - that's a boring job for a Raspberry! Yes you are right! But I have no experience at all in doing the job on an Arduino and this might not be the right forum to ask for! ;-) Ok, if there is a COMPLETE(!!!) solution for this in the WWW, which I would only have to make some minor adaptions on, I would accept it ...)

As output I would use the 7" Raspberry display. Better solutions are welcomed! I only need a (larger) display for my "dark" radio shack.

I have programmed a lot of things on WWW-pages using PHP. And I am little experienced in python. Therefore a PHP solution would be best. Python I would hopefully manage ...

My problem:
1) I have to make a graphical output on the WHOLE Raspberry display. Just as a "normal" digital clock. Can someone please give me a hint, a code example how to do this with PHP (((Python))) and
2) how to start this automatically after the Raspberry booted (code(!) example(!) not concept)?

Thank you very much
Klaus

User avatar
DougieLawson
Posts: 41687
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Pi as a clock for UTC + local time and date

Sun Aug 01, 2021 6:09 pm

Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
neilgl
Posts: 3509
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Raspberry Pi as a clock for UTC + local time and date

Sun Aug 01, 2021 6:19 pm

For 1) have a look at guizero
For 2) look at this excellent guide https://www.raspberrypi.org/forums/vie ... 1&t=314455

User avatar
scruss
Posts: 4294
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Raspberry Pi as a clock for UTC + local time and date

Sun Aug 01, 2021 9:50 pm

Elwood Downey's Ham Clock project looks like it had some thought put into it. The display looks somewhat overkill to me: if I wanted a Geochron, I know which bank I'd need to rob to get one.

Elwood's been working on this project for 4-5 years, and it seems to have many users. I don't see it recommended in the base parts list, but an RTC would be really handy to make sure the clock isn't wildly off on power up.

If you do look at DCF77 sync, Volker Forster of Universal Solder has a really nice low(ish) cost board: CANADUINO DCF77 Atomic Clock Receiver. This board handles all the timesignal data processing, so you get nice clean digital pulses. Volker's store's offline at the moment, as he's just moved his entire operation from Saskatchewan to Ontario.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

knute
Posts: 712
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Raspberry Pi as a clock for UTC + local time and date

Sun Aug 01, 2021 9:57 pm

This is a derivative of what I use for my Ham clock.

Code: Select all

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import static java.awt.RenderingHints.*;
import java.time.*;
import java.time.format.*;
import java.util.*;
import javax.swing.*;

public class JavaClock extends JPanel {
    private final DateTimeFormatter formatter;
    private final javax.swing.Timer timer;
    
    public JavaClock() {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        setPreferredSize(toolkit.getScreenSize());

        timer = new javax.swing.Timer(250,event -> repaint());
        formatter = DateTimeFormatter.ofPattern("EEE yyyy-MM-dd HH:mm zzz");
    }

    public void start() {
        timer.start();
    }

    public void stop() {
        timer.stop();
    }

    public void paintComponent(Graphics g2D) {
        Graphics2D g = (Graphics2D)g2D;
        g.setRenderingHint(KEY_ANTIALIASING,VALUE_ANTIALIAS_ON);

        g.setColor(Color.BLUE);
        g.fillRect(0,0,getWidth(),getHeight());

        g.setColor(Color.WHITE);
        ZonedDateTime local = ZonedDateTime.now();
        String localStr = local.format(formatter);
        ZonedDateTime utc = ZonedDateTime.now(ZoneId.of("UTC"));
        String utcStr = utc.format(formatter);

        FontMetrics fm;
        Font font = new Font(Font.SANS_SERIF,Font.BOLD,12);
        int width = 0;
        do {
            font = font.deriveFont(font.getSize2D() + 10f);
            g.setFont(font);
            fm = g.getFontMetrics();
            width = fm.stringWidth(localStr);
        } while (width < getWidth() * 0.9) ;
        int height = fm.getHeight();

        g.drawString(localStr,(getWidth() - width) / 2,
         getHeight() / 2 - height / 2);
        g.drawString(utcStr,(getWidth() - width) / 2,
         getHeight() / 2 - height / 2 + height);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(() -> {
            JavaClock clock = new JavaClock();
            JFrame frame = new JFrame();
            frame.setUndecorated(true);
            frame.addWindowListener(new WindowAdapter() {
                public void windowOpened(WindowEvent we) {
                    clock.start();
                }
                public void windowClosed(WindowEvent we) {
                    clock.stop();
                }
            });
            frame.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent me) {
                    frame.dispose();
                }
            });
            frame.add(clock);
            frame.pack();
            frame.setVisible(true);
        });
    }
}



Return to “Advanced users”