{"id":12743,"date":"2024-04-02T17:34:58","date_gmt":"2024-04-02T21:34:58","guid":{"rendered":"https:\/\/www.engineeringradio.us\/blog\/?p=12743"},"modified":"2024-04-06T09:58:58","modified_gmt":"2024-04-06T13:58:58","slug":"gps-controlled-clock-based-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.engineeringradio.us\/blog\/2024\/04\/gps-controlled-clock-based-on-raspberry-pi\/","title":{"rendered":"GPS controlled clock based on Raspberry Pi"},"content":{"rendered":"\n<p>This is an adjunct to my previous post on creating a <a href=\"https:\/\/www.engineeringradio.us\/blog\/2023\/04\/what-time-is-it\/\">Stratum 1 NTP time server with a Raspberry Pi<\/a>.  I finished this project about a year ago, and I have to say it has been running flawlessly since then.  I thought that perhaps the inexpensive GPS module designed to work with drones might not hold up.  But it has.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"683\" src=\"https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-1200x683.png\" alt=\"\" class=\"wp-image-12749\" srcset=\"https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-1200x683.png 1200w, https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-650x370.png 650w, https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-150x85.png 150w, https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-768x437.png 768w, https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-1536x874.png 1536w, https:\/\/www.engineeringradio.us\/blog\/wp-content\/uploads\/2024\/04\/Screenshot-from-2024-04-01-20-00-01-2048x1165.png 2048w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\">Midnight in London<\/figcaption><\/figure>\n\n\n\n<p>Wouldn&#8217;t it be nice to use this time source, not just to set hardware clocks but also display the time in varous places?  Yes, yes it would.<\/p>\n\n\n\n<p>Since most of my ideas are not original, I figured a quick internet search may shed some light on how to proceed.  Keith, G6NHU did exactly this a year ago or so.  His project can be viewed here: <a href=\"https:\/\/qso365.co.uk\/2023\/05\/how-to-build-a-shack-clock-using-a-raspberry-pi-and-a-7-touch-display\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/qso365.co.uk\/2023\/05\/how-to-build-a-shack-clock-using-a-raspberry-pi-and-a-7-touch-display\/<\/a><\/p>\n\n\n\n<p>As I suspected, with a few more configuration steps, this NTP server can display the time on the native HDMI port as well as create a simple web page available on the LAN for any computer to access with a web browser.  The web server is Lighttpd, which is a low CPU load, low memory demon, perfect for an older Raspberry Pi 3.<\/p>\n\n\n\n<p>The display I chose is a 7-inch 16&#215;9 non-touch purchased from Amazon for $33.99: <a href=\"https:\/\/www.amazon.com\/gp\/product\/B0BGXB2Y67\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.amazon.com\/gp\/product\/B0BGXB2Y67\/<\/a> (not an affiliate link)<\/p>\n\n\n\n<p>When I created the NTP server last year, I named it ntpserver.  The unit runs headless (no keyboard or monitor) so I use ssh to get into the command line.  Thus, the first command is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh ntpserver@192.168.1.200<\/pre>\n\n\n\n<p>Once in, always do an update:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get update\nsudo apt-get upgrade -y<\/pre>\n\n\n\n<p>The following programs need to be added to the Pi:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install xorg openbox xserver-xorg xinit unclutter lighttpd -y<\/pre>\n\n\n\n<p>If the OS is off the shelf Raspian, then Chromium should already be installed, but if not, then add it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install chromium-browser -y<\/pre>\n\n\n\n<p>Once that is done, some things need to be configured.  Using whatever text editor you like the xserver so that anyone can access it.  Open the Xwrapper file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/X11\/Xwrapper.config<\/pre>\n\n\n\n<p>Then add line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">allowed_users=anybody<\/pre>\n\n\n\n<p>Exit and save.  Next open the xserverrc file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/home\/ntpserver\/.xserverrc<\/pre>\n\n\n\n<p>Add the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/sh\n#Start the X server session with no power management so the display never sleeps\nexec \/usr\/bin\/X -s 0 -dpms -nolisten tcp \"$@\"<\/pre>\n\n\n\n<p>Exit and save.  Next open the xsession file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/home\/ntpserver\/.xsession<\/pre>\n\n\n\n<p>Add the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/sh\n#Start Chromium at startup\nchromium-browser --start-fullscreen --window-size=800,480 --disable-infobars --noerrdialogs --incognito --kiosk http:\/\/localhost<\/pre>\n\n\n\n<p>Exit and save.  Note the display size can be configured to any screen resolution.  This affects the HDMI port, not the web page.  The 7-inch Raspberry Pi monitor that I purchased from Amazon has an 800 x 480 screen resolution. If you are using a different screen resolution, change as needed. Next open the clock.service file (it will be created when you save the file):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/systemd\/system\/clock.service<\/pre>\n\n\n\n<p>Add the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\nDescription=Clock\nAfter=network-online.target\nDefaultDependencies=no\n\n[Service]\nUser=clock\nExecStart=\/usr\/bin\/startx\nRestart=always\nRestartSec=10\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n\n\n\n<p>Exit and save.<\/p>\n\n\n\n<p>The web page that will be displayed on the HDMI port as well as served to local hosts on the LAN is a java script page.  It was originally developed by Nayuki: <a href=\"https:\/\/www.nayuki.io\/page\/full-screen-clock-javascript\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.nayuki.io\/page\/full-screen-clock-javascript<\/a> You can download whatever format you like from that site (I copied the page source) or you can download a 24-hour format from Keith&#8217;s site:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/var\/www\/html\nsudo wget https:\/\/qsl.net\/g6nhu\/clock\/index.html<\/pre>\n\n\n\n<p>The colors can be edited:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/var\/www\/html\/index.html<\/pre>\n\n\n\n<p>The background, foreground, and font type can be changed as desired.<\/p>\n\n\n\n<p>Next start the clock service and reboot:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl enable clock<br>sudo systemctl start clock<br>sudo reboot now<\/pre>\n\n\n\n<p>Here is a quick video of the web page on my desktop computer.  I have the GPS monitor from the ntpserver up and running in the left upper corner.  That shows the GPS data going into the Raspberry Pi from the serial port along with some scratchy WWV audio.  The actual clock sync is from the 1PPS output of the GPS module.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"GPS synced Raspberry PI clock\" width=\"660\" height=\"371\" src=\"https:\/\/www.youtube.com\/embed\/qfhXfM13Gtc?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>I could see this being used as an inexpensive master clock system somewhere.  With an HDMI splitter (or a better name would be Distribution Amp), this could be sent to many locations.<\/p>\n\n\n\n<p> Now all I need to do is figure out how to get a GPS synced 10 MHz output capable of driving multiple devices.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an adjunct to my previous post on creating a Stratum 1 NTP time server with a Raspberry Pi. I finished this project about a year ago, and I have to say it has been running flawlessly since then. I thought that perhaps the inexpensive GPS module designed to work with drones might not &hellip; <a href=\"https:\/\/www.engineeringradio.us\/blog\/2024\/04\/gps-controlled-clock-based-on-raspberry-pi\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">GPS controlled clock based on Raspberry Pi<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":12764,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102,4],"tags":[306,101],"class_list":["post-12743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-audio","category-tech-stuff","tag-audio","tag-studio"],"_links":{"self":[{"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/posts\/12743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/comments?post=12743"}],"version-history":[{"count":15,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/posts\/12743\/revisions"}],"predecessor-version":[{"id":12767,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/posts\/12743\/revisions\/12767"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/media\/12764"}],"wp:attachment":[{"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/media?parent=12743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/categories?post=12743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.engineeringradio.us\/blog\/wp-json\/wp\/v2\/tags?post=12743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}