• 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

ds1302

Q&A Forum › ds1302
0 Vote Up Vote Down
Philip Borg asked 10 months ago

Dear Ms Santos,
Following your suggestion on how to download the driver for the ds1302, I tried to adapt the code on page 456 to suit the ds1302. The modified code is shown hereunder:
import time
import ds1302
from machine import I2C, Pin
days_of_week = [‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Sunday’]
# Initialize RTC (connected to I2C)
#i2c = I2C(1, scl=Pin(15), sda=Pin(14))
rtc = ds1302.DS1302(Pin(5), Pin(14), Pin(15))
# Set the current time using a specified time tuple
# Time tuple: (year, month, day, day of week, hour, minute, seconds, milliseconds)
#initial_time = (2024, 1, 30, 1, 12, 30, 0, 0)
# Or get the local time from the system
initial_time_tuple = time.localtime() # tuple (MicroPython)
initial_time_seconds = time.mktime(initial_time_tuple) # local time in seconds
# Convert to tuple compatible with the library
initial_time = ds1302.seconds2tuple(initial_time_seconds)
# Sync the RTC
rtc.datetime(initial_time)
while True:
current_datetime = rtc.datetime()
print(‘Current date and time:’)
print(‘Year:’, current_datetime.year)
print(‘Month:’, current_datetime.month)
print(‘Day:’, current_datetime.day)
print(‘Hour:’, current_datetime.hour)
print(‘Minute:’, current_datetime.minute)
print(‘Second:’, current_datetime.second)
print(‘Day of the Week:’, days_of_week[current_datetime.weekday])
time.sleep(1)
 
When trying to run the code I get the error for line 21 “‘module’ object has no attribute ‘seconds2tuple'”.
Can you please help?
 
Philip

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 10 months ago

Hi.
That means the library you’re using doesn’t have a function called seconds2tuple.
You need to look at the library file code and see if it has a similar method that does the same thing.
 
Regards,
Sara

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.