Seeking Feedback on first project

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ElliotGarbus
 
Posts: 8
Joined: Thu Jul 07, 2022 4:36 pm

Seeking Feedback on first project

Post by ElliotGarbus »

This is my first CircuitPytyhon project. https://github.com/ElliotGarbus/MagtagWeatherClock
The project uses a MagTag, and presents a clock, weather and weather forecast. The icons are "borrowed" from the project: https://learn.adafruit.com/magtag-weather

I'm primarily interested in feedback around 2 areas:
  • Power management
  • RTC behavior
I'm looking to extend battery life as much as possible, I am disabling the network - unless I am going to access the network. I'm also disabling the neopixel. Is this correct? Any other suggestions?

How often should I be refreshing the RTC from the network to keep time? Originally I was going to update the RTC once a week, and I saw over the course of a day, I was losing minutes. I have moved to updating the RTC every 6 hours. Is this too often or not often enough?

Any other feedback is welcomed!

There are 2 files in the attached repo:
code.py - the main program
persistant_ram.py - a class that uses alarm.sleep_memory to preserve app state.

TIA - I look forward to your feedback

User avatar
rooppoorali
 
Posts: 98
Joined: Sat Jul 16, 2022 12:04 pm

Re: Seeking Feedback on first project

Post by rooppoorali »

What is the main processor here? Is it ESP32?

User avatar
ElliotGarbus
 
Posts: 8
Joined: Thu Jul 07, 2022 4:36 pm

Re: Seeking Feedback on first project

Post by ElliotGarbus »

The processor is the ESP32-S2.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Seeking Feedback on first project

Post by adafruit_support_mike »

ElliotGarbus wrote: Tue Sep 20, 2022 1:32 am How often should I be refreshing the RTC from the network to keep time? Originally I was going to update the RTC once a week, and I saw over the course of a day, I was losing minutes. I have moved to updating the RTC every 6 hours. Is this too often or not often enough?
Hmm.. minutes per day is pretty high. Are you using an external RTC or the thing called an "RTC" in the microcontroller?

'Real Time Clock' is a badly abused term. Marketing departments use it to mean anything that provides output in an days:hours:minutes:seconds format, whether the output has any relation to the actual time or not. The ones described in microcontroller datasheets are usually driven by the chip's CPU clock, which typically has about a 3% tolerance on absolute accuracy and a 5% tolerance on drift.

Standalone devices that call themselves RTCs do better, but there are still grades of performance. The DS1307 and PCF8523 keep reasonably good time for intervals of a few hours, but have an expected drift of about 30ppm (+/-3 seconds per day). They use a quartz crystal oscillator, but don't have any hardware to limit or compensate for the crystal's drift relative to temperature:

https://www.adafruit.com/product/3296
https://www.adafruit.com/?q=PCF8523&sort=BestMatch

The next step up are devices like the DS3231. It has a quartz crystal built into the package and calibrated at the factory, plus what's known as a 'thermal compensation table'.. bascially the manufacturer has measured a large set of crystals at different temperatures, and worked out how much drift to expect at any temperature in the chip's operating range. That information is written into the chip as a lookup table, and the chip has a built-in thermometer to measure the crystal's temperature at any moment.

The oscillator still has the same 30ppm drift as a DS1307 or PCF8523, but the compensation table is good enough to keep the reported time stable to within a few seconds per year:

https://www.adafruit.com/?q=DS3231&sort=BestMatch

The next step up from there are thermally controlled quartz oscillators (TCXOs), whose accuracy and stability approach the low end of the atomic clock system (1 part in 1e19.. about 1 nanosecond every 300 years).

We don't carry TCXOs, and they wouldn't be appropriate to your project anyway.. they're power-hungry and require careful handling.

Somewhere in the middle are GPS modules. Their internal clocks are about as good as a DS1307 or PCF8523, but when they have a fix, they adjust the clock at the beginning of each GPS-second. The GPS satellites are synced to the international atomic clock system, and if you let GPS modules hold a fix for a few hours, they'll synchronize their clocks to within 10ns of the GPS clock system. In effect, they have no drift over time as long as they continue to have a fix:

https://www.adafruit.com/?q=GPS&sort=BestMatch

If you're using the ESP32's we-call-it-an-RTC, try stepping up to a PCF8523. That will keep your drift within about 3 seconds if you sync the clock once a day, or within about 30 seconds worst-case if you sync once a week.

User avatar
ElliotGarbus
 
Posts: 8
Joined: Thu Jul 07, 2022 4:36 pm

Re: Seeking Feedback on first project

Post by ElliotGarbus »

@adafruit_support_mike,
Thanks for the detailed response. I am using the "ESP32's we-call-it-an-RTC", so that explains the lack of accuracy. Given my primary interest is extending battery life the question would be does it use less power to update the clock every other hour - or to use a real RTC. I'll just do more frequent updates for now. I have also decided (but not yet implemented) that I do not need to update the time or weather late night - from midnight to 6am. This will further reduce the number of network access - and I assume further extend the battery life.

Time for more experiments!
Thanks again!

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Seeking Feedback on first project

Post by adafruit_support_mike »

Consider an RTC that has a battery backup: those can keep the clock running from a coin cell while the main power is shut down, and will give you proper time with negligible delay when the system powers up again.

A single coin cell can keep the RTC running for months.

User avatar
ElliotGarbus
 
Posts: 8
Joined: Thu Jul 07, 2022 4:36 pm

Re: Seeking Feedback on first project

Post by ElliotGarbus »

An RTC with a backup coin cell is a great idea - but I don't think I'll need to go that route.

I have made a number of tweaks to the network access strategy to improve battery life.
I update the weather every 30 min from 6am to 7pm. I update the weather once and hour from 8pm to 11pm. I do not update the weather between 11pm and 6am.
I update the RTC from the network once every 3 hours.

Updating the RTC on the ESP32-S2 every 3 hours provides sufficient accuracy. This was not done on the basis of a detailed study. 6 hours was too long, 3 hours works fine.

This seems to provide a balance between battery live, clock accuracy and timeliness of data. I have ordered a larger rechargeable battery for the Magtag. I'm looking forward to seeing how long a charge will last.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Seeking Feedback on first project

Post by adafruit_support_mike »

As long as you've found something that works for you, it's good. Happy hacking!

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”