Clock Sync Zones

Hi,

I’ve been building a clock from a 3D printing site. Now the basic clock I’ve been able to get to work with Nano & a DS3231 as the code was provided in the guide to building the clock.

A guy who coded a wifi version has provided the code to get it to work, but refused to help any further. But another guy from Australia has provided me with details of the wifi module he uses and a wiring photograph.

My issue is, I’ve been playing around with the coding and trying to get different timezones to be displayed. As a newbie I’m still learning but some of the coding issues I’m having is trying to get the Nano to get the NTP time that the Wifi module is retrieving and convert it to the timezones I’ve tried to code.

Attached is the coding for the Nano & Wifi module. I hope someone can help or give advice to a newbie lol.

I’m trying to display the follwing:

Red: US PDT TimeZone - But future date (day/month and year)
Green: My TimeZone - actual time
Orange: Aussie TimeZone with past date (day/month and year)

At the moment its showing the correct date and time for me, but showing 2am for RED (US) and 8pm Orange (Aussie). When viewing the monitor on the pc its stating its 1970, so I guess its taking red and orange times from that.

Cheers for any help.

BTW some of the code is not concerned to me for example the ( “Show Power / Battery status” ) as this is from the code provided by the guy who first coded the WIFI version.

Attached the iNO files as the code was too much for the Maximum characters for the post lol.

sketch_nov14c.ino (12.9 KB)

sketch_nov16a.ino (7.37 KB)

Easy peasy. Set your RTC to UTC and use the Time Zone library. I can show you how to do zones in the raw AVR GCC, but it's harder. If you run on an ESP, it's much easier, the native time library implements zones perfectly.

I'm not going to look at 2 huge sketches that you don't understand, though. I'm a volunteer. For me, it would probably be faster to write one from scratch, than try to fix some unknown code from the dark side of the internet.

I'm on my mobile so can't see the attachments at the moment.

NTP gives you UTC time, so you won't get timezone information from that and if you have an RTC, not sure what you want to get from the network (unless you want to sync your clock from time to time?)

basically you should set your RTC at UTC time (or a known delta) and then as you know exactly the delta in hours/minutes between you 3 different locations and the zone used for your RTC, you could just calculate the local time to display.

the arduino RTCLib from Adafruit can handle your RTC and offers convenient classes (DateTime and TimeSpan) to manage operations on time

If you don't have daylight savings time, it's extremely easy to just add the local time offset in seconds to Epoch time, as suggested in the previous post. The main advantage of Jack's library is that it handles daylight savings time changes automatically. Obviously, this is an advantage for a clock because you don't have to set it manually twice a year.

One simple work around, is to just maintain a variable to indicate whether DST is in effect. Then you can change it manually but don't need to reset the time.

Again, if you port to ESP, time and time zones are fully supported so you don't need to worry about it. It's just AVR GCC that is lacking so much that add ons are necessary.

I am using the timezone lib as part of the coding. I was hoping that the nano would be able to read the information the wifi module was retrieving from the ntp server.

The wifi module is retrieving the time and in sync. I wasnt sure if I could connect the rtc module up to the same lines as the wifi module (A4 & A5)

You never told us anything about the wifi module... so it's impossible to comment.

Wifi: ESP8266 NodeMcu LUA WiFi Module CP2102 ESP-12E

RTC: AZDelivery DS3231

Nano: ELEGOO Nano Board CH340/ATmega328P

The ESP8266 module uses serial communications to work with an Arduino. How are your modules connected together? Please post a wiring diagram.

ESP8266 To Nano via

Gnd, 3v3, D1 & D2 (wifi)

A4 & A5, 3v3, gnd (Nano)

That is not a diagram. That is a description which can be interpreted in many different ways. Please find a pencil and paper and make a drawing, take a photo and upload it.

Horrible drawing with finger lol

Edit: forum didn’t allow drawing so just transferring..

victor2173:
Horrible drawing with finger lol

Edit: forum didn’t allow drawing so just transferring..

The quality of the art is not important. Your image may have just been too large. Try posting a smaller file.

you should be able to see it now.

You have no 5V to 3.3V level translation between the devices. That can damage the ESP I/O pins. Also, many Nano's can't supply enough current at 3.3V to run an ESP when it runs wifi.

I tried connecting the pins to a level converter but Wifi module wasn't getting enough power even on the signal lines so wasn't able to boot up. As soon as I removed the level converter it booted up straight away.

I'll try that way again tomorrow.

victor2173:
I tried connecting the pins to a level converter but Wifi module wasn't getting enough power even on the signal lines so wasn't able to boot up. As soon as I removed the level converter it booted up straight away.

I'll try that way again tomorrow.

That makes no sense, except that as I pointed out, the Nano is not really capable of powering an ESP. This kind of report is why I almost always ask for a completely labelled and clear wiring diagram. You probably made some kind of connection error.

But as I also said already, you can damage the ESP pins without the level converter, so I think you need to re-think the entire project.

If you are going to use an esp8266 module, why even bother with the Nano?
You can run all the sketch code on the esp module and it is much faster with tons more flash and ram than the AVR based nano.
Also, the esp core includes all the needed NTP support and the standard unix time library functions to do time management including local timezones with DST adjustments.

You do a single function call to set up NTP with your NTP server addresses and set up your timezone information using a POSIX timezone string.
After that time keeping will run in the background - no RTC is needed if you always have a wifi internet connection.

Then, for local time you can use the time library functions like localtime(), ctime(), asctime(), and strftime()
If you use the wifi manager which provides an access-point, you can get and save parameters so you don’t need to hard code the WiFi parameters, or the timezone string.

I have used this in a few clock projects.

— bill

I'm going to connect the level convertor today and check the connections then report back, but I have done a diagram on the project on tinkercad:

you can see all the connections so far and the reason for both cards. As I'm a noob / newbie lol I'm still learning. But I will look at trying to add the RTC in today.

Cheers for the advice.

The diagram on TinkerCad that you linked to, is creative, but completely unreadable. You can't even copy it without a membership. Please make a proper pencil and paper sketch, and post an image. What we're looking for is correctly labelled pins, modules and wires. Include all the connections, don't leave anything to "assume".

The need for this kind of documentation, is explained in the forum introductory threads. Please read them before posting.

Also consider closely, reply #16. It could make your project 10 times easier.

aarg:
The diagram on TinkerCad that you linked to, is creative, but completely unreadable. You can't even copy it without a membership. Please make a proper pencil and paper sketch, and post an image. What we're looking for is correctly labelled pins, modules and wires. Include all the connections, don't leave anything to "assume".

The need for this kind of documentation, is explained in the forum introductory threads. Please read them before posting.

Also consider closely, reply #16. It could make your project 10 times easier.

Its free to make an account on tinker, thats why I posted all on there so show what I was doing. Its only unreadable if you're looking at the preview, once in the project you can read and see everything I have connected.
I did read the post 16 which is why I did the diagram to show that there are 9 displays and the wifi module doesnt have enough pins to connect all the displays up for year, month & time for each row. I labelled everything that I can think of within that tinkercad project file.
I did read the posts regarding before posting and also googled for information BEFORE I even considered posting here asking for some help. I'm not new to posting within forums and do take the time to read them before I post.
As I have already stated I am new to programming arduinos unlike a lot of people within this forum. Its only due to this project that I decided to take a dive into programming, but considering what I've been told so far I might just put this project to bed and keep it in the simplest form.
In your first reply 'Easy peasy' it might be for you, but when theres someone like me thats just starting out in arduino programming not everything is easy peasy. BTW the code was provided by someone who took the same attitude when I asked just two questions regarding the code 'you might want to learn arduino programming before stepping into this.' This was after he stated that I would need to remove some of his own coding for it to work on mine. We both have the same hardware, its just he has it displaying info regarding his separate server which of course I didnt require. After I edited it to try and remove it, I asked him if he could just do a scan to make sure it would work and also to check I had removed his info and thats when I got the sarcastic reply.
I would just like to thank the few that did give some useful info and help.