New to Arduino, help sought

Hi, I am new to Arduino. I got interested in it while searching for a digital clock that would display both local time and UTC. Since I am really into amateur radio such a clock would come in handy. Eventually I happened upon Bruce Hall's (W8BH) Arduino based GPS clock. His clock used Adafruit modules and a homebrewed LED display that by his own admission chomped electricity like crazy.

So I decided to go simple. This was around a decade ago so I bought Velleman modules at Fry's (don't y'all miss Fry's?) and a 20 character LCD display from China off Ebay. Then life intervened, as it tends to do.

Over the years I've been copypasta'ing segments of code and drivers from various places on the net, and I finally have something that might work. I'd like to post the code (in .txt at the moment) to the forums to have experienced eyes look it over. I would like guidance with the code, as well as with the use of Velleman Arduino modules. Where should I start posting? Help appreciated.

Phreaking Cow

Are you hinting that you have NEVER test the code or the components of your clock?

Welcome to the forum.

Before posting, this is important for you to read
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966

Where should I start posting?

Depending on the state of your project, I would think the either use one of these categories

Project Guidance
Programming Questions
General Electronics

Nothing else to do, so I wrote some code for an ESP32C3 (from Seeed).
Displays UTC time and local time in the serial monitor.
Just enter your WiFi credentials, time zone string (link in the code) and local pool.
Let me know if you need help with that (need to know where you live).
The prints can also have year/month/date etc included. See this page.
Works of course only within range of WiFi.
Leo..

#include <WiFi.h>  // ESP32
#include "esp_sntp.h"
unsigned long prevTime;
bool reSync;
time_t now;  // epoch
tm tm;       // time struct

void cbSyncTime(struct timeval *tv) {  // sync callback
  Serial.println("Time was updated");
  reSync = true;
}

void setup() {
  Serial.begin(115200);
  WiFi.begin("MySSID", "MyPass");                                  // WiFi credentials
  sntp_set_time_sync_notification_cb(cbSyncTime);                  // enable callback
  configTzTime("NZST-12NZDT,M9.5.0,M4.1.0/3", "nz.pool.ntp.org");  // https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
  Serial.println("Waiting for time sync");
  while (!reSync) yield();
}


void loop() {
  time(&now);
  if (now != prevTime) {                                                  // if time has changed
    prevTime = now;                                                       // remember
    gmtime_r(&now, &tm);                                                  // get epoch
    printf("\nUTC: %02u:%02u:%02u", tm.tm_hour, tm.tm_min, tm.tm_sec);    // print UTC
    localtime_r(&now, &tm);                                               // convert epoch to local time
    printf("\tLocal: %02u:%02u:%02u", tm.tm_hour, tm.tm_min, tm.tm_sec);  // print local
  }
}

So… post your code. Use the IDE Autoformat tool first, then use the IDE Copy for Forum tool and paste it here.

It should look like code:

void setup() {

}

void loop() {

}

If you are feeling adventurous, try the simulator at

where you can wire up a circuit and see if this alleged code does work. If you do, you can share a link to it here so we can play with it.

You will find it the components you are using, or equivalents.

Free. Indestructible.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.