• 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

DS1307 RTC on Pi Pico doesn’t keep it’s initialization.

Q&A Forum › Category: Raspberry Pi › DS1307 RTC on Pi Pico doesn’t keep it’s initialization.
0 Vote Up Vote Down
Renaud Richard asked 3 weeks ago

Hi,
I cabled three DS1307 RTC on three Pico as described in module 10.4 of your book “Learn Raspberry Pi Pico/Pico W with MicroPython”
I am experiencing the same trouble with the three different Pico (W and W2) and three RTC.
After having run 10_4_1_sync_rtc then 10_4_2_rtc_display_time_oled, while still connected to Thonny, everythings fine. Actual day and time.
Then of course I named it main.py to run it out of Thonny on a mains usb and the real date is always lost for “01-01-2021 00:00:01”
This happens on any of the three Pico/RTC builts.
I reloaded from your link the 10_4_1_sync_rtc and 10_4_2_rtc_display_time_oled to be sure they were not corrupted but to no avail.
Obviously the RTC doesn’t keep it’s initialization.
Any tips welcome
Renaud

13 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi.
Does your RTC have a battery attached? If not, it cannot maintain the time after being disconnected from the power source.
Regards,
Sara

0 Vote Up Vote Down
Renaud Richard answered 3 weeks ago

Hi Sara,
Yes, all three have their batteries and they are above 3V.
Regards,
Renaud
 

0 Vote Up Vote Down
William Lucid answered 3 weeks ago

Hi Renaud,

What are the battery, measured voltages; disconnected from USB?  Measure with battery installed in the RTC (under load).  Battery may show a good voltage out of the RTC; however, not be able to power the RTC.

If you do not have a voltmeter, try a new, fresh battery.

William

0 Vote Up Vote Down
Renaud Richard answered 3 weeks ago

Hi William,
Thanks but the batteries are indeed above 3V on the RTC when disconnected from USB.
I had a good look at the Maxim specs about the DS1307. Like you I was thinking about a PS trouble. Contrary to what is said nearly everywhere it should NOT be powerered at 3.3V. The specs are 4.5V to 5.5V. Obviously many are operational at 3.3V but some could not be either. Well, I thought that was the culprit as mine was supplied at 3.3. So I happliy plugged it on VSYS but with the same result. Also the BAT min spec is 2V.
Here I am! Any new ideas received gratefully!
Best regards,
Renaud

0 Vote Up Vote Down
William Lucid answered 3 weeks ago

Does your DS1307 have pull up resistors on I2C, SDA and IC2, SCL to Vcc?  Not all Breakout boards have these resistors; values can range from 4.7K to 10K ohms.

Also, check soldering of header pins; for a cold solder joint.  Re-apply soldering iron to heat joint; until solder flows at joint.  

William

0 Vote Up Vote Down
Renaud Richard answered 3 weeks ago

Hi William,
Yes, the pull up resistors were to be my next move. The Maxim specs call for them. 
Yesterday I tried to use the Pico inboard pull ups:

I changed:
i2c_rtc = SoftI2C(scl=Pin(5), sda=Pin(4))

to:
i2c_rtc = SoftI2C(scl=Pin(5,Pin.IN, Pin.PULL_UP, sda=Pin(4) Pin.IN, Pin.PULL_UP))
but got an “invalid syntax” with that. So this morning I added real pull ups on sda/scl but again to no avail.
About a bad solder or connection I have the same result with three builts. Two on breadboards, the third soldered. BTW I have a (too!) long practice at soldering William but that doesn’t exclude bad ones as you say.
Now the same on three different Picos with three different RTC!
Thanks
Renaud

0 Vote Up Vote Down
William Lucid answered 3 weeks ago

Good Morning Renaud,
 
The “invalid syntax” pertains to an error in the code; not hardware.  I am not knowledgeable in the Raspberry Pi Pico or MicroPython; I have coded for a long time in C++.

I did check out a blog post on the Pico and MicroPython; shows how to init the I2C sensor and how to define the pins.  Hope you find it helpful:   Raspberry Pi Pico and I2C
 
Regards,
William

0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi.
Let’s just recap what you need to do. I don’t think your problem is hardware-related.
 
1 – Run the code to sync the RTC. You just need to run this code with the green button while the RTC is connected to the board (don’t upload this code as main.py). It’s the one in this link:
https://github.com/RuiSantosdotme/RPi-Pico-W-MicroPython-eBook/blob/main/Code/Module_10/10_4_rtc/10_4_1_sync_rtc.py
 
2- Upload the second code to your board (this time upload it as main.py). After copying the code to Thonny IDE, go to File > Save as… and select Raspberry Pi Pico. Save the file as main.py. (Don’t run this code with the green button this time).
https://github.com/RuiSantosdotme/RPi-Pico-W-MicroPython-eBook/blob/main/Code/Module_10/10_4_rtc/10_4_2_rtc_display_time_oled.py
 
Now, it should be running as expected.
 
I hope this is clear. Make sure you follow this procedure exactly as I’ve described.
Let me know the results.
 
Regards,
Sara

0 Vote Up Vote Down
Renaud Richard answered 3 weeks ago

Hi,
William: Thanks but as Sara said I don’t think it’s material either. And pull ups have  not improved anything.
Sara I will follow thoroughly your procedure and report here.
Best
Renaud

0 Vote Up Vote Down
Renaud Richard answered 3 weeks ago

Hi,
Yes it works. The RTC init program I always installed it correctly.
So what I did wrongly was that I was running the display time program from Thonny. 
Now I can open it, modify it and run it again. Still fine.
Ok, but why was it wrong?
Thanks Sara anyway.
Renaud

0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi.
I think that what you probably did wrong was actually running the code to synchronize the time as main.py.
That code pulls the time from the system. When you run it from Thonny, it gets the time at compilation from your computer. Which is the correct time.
 
When you run it as main.py, it will run and get the time from the RPi system, which was set by the manufacturer on the RPi chip when they built it. In your case, it was 01-01-2021 00:00:01
 
I hope this makes sense.
 
Regards,
Sara

0 Vote Up Vote Down
Renaud Richard answered 2 weeks ago

Hi Sara,
Sorry for the delay to answer. That’s myself multitasking!
Yes, what you say makes sense obviously. As I needed Picos with both BME280, RTC, multitasking and server I most probably did something wrong somewhere.
I took everything fresh, taking what was needed again from your excellent book, downloading fresh code and adding only carefully my mods where needed. It works  a treat now.
So I believe you can consider this as solved Sara, with my thanks.
Best,
Renaud

0 Vote Up Vote Down
Sara Santos Staff answered 2 weeks ago

That’s great!
Thanks for letting me know.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
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

  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 V1.6 September 9, 2025
  • [eBook Updated] Learn LVGL: Build GUIs for ESP32 Projects – Version 1.5 July 7, 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.