• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

day-of-week RTC DS3231

Q&A Forum › Category: Raspberry Pi › day-of-week RTC DS3231
0 Vote Up Vote Down
Nicolas Boucquey asked 8 months ago

As specified in the ds3231 technical documentation, the day-of-week is in the buffer address 03h and the Rnage is 1-7.
The day-of-week register increments at midnight. Values that correspond to the day of week are user-defined but must be sequential (i.e., if 1 equals Sunday, then 2 equals Monday, and so on). Illogical time and date entries result in undefined operation.

Therefore I think the implementation in urtc.py (even for ds3231) is not correct as described in “Raspberry PI PICO/PICOW with MicroPython” 10.4. The program failed when the current_datetime.weekday value is incremented and reachs 7. The value is out of range of the days_of_week list.
I’m right or I have missed something.
Thanks a lot by advance.
Kr.

Question Tags: DS3231, Pico, RTC
2 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 8 months ago

Hi.
I’m sorry. At the moment, I’m out of the office to test that.
If current_datetime.weekday returns 7, the days_of_week[] array will be out of range. So, you’ll need to subsctract one to the result of current_datetime.weekday result.
For example:

print('Day of the Week:', days_of_week[current_datetime.weekday-1])

 
Let me know if this fixes the issue.
Again, I don’t have a way to actually test this at the moment.
 
Regards,
Sara

0 Vote Up Vote Down
Gary Scott answered 4 months ago

I found the same issue, but decided to make the change within urtc.py as follows.
Incrementing DoW at the time of write to the RTC register and decrementing DoW following a read from the RTC register, this ensures that outside of the object DoW starts at 0 and is consistent.
Within the RTC the valid DoW range is 1-7, so a 0 should not be written.
Regards
Gary.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.