• 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

DS3231

Q&A Forum › Category: ESP32 › DS3231
0 Vote Up Vote Down
self.raymond asked 6 years ago

I am using a ds3231 RTC on the esp32 and also with an esp8266 in Micro-python. Looking for a little help
Ray

5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Ray.
I’ve found this library: https://github.com/micropython-Chinese-Community/mpy-lib/tree/master/misc/DS3231
I’ve tested setting the time and reading the time with the ESP32 and it seems to work fine (it should also work with ESP8266).
First, make sure you import the library: https://github.com/micropython-Chinese-Community/mpy-lib/blob/master/misc/DS3231/DS3231.py
Then, you can use the library to set and request the time and set alarms. See their example on the library page.
Also, don’t forget to set the right I2C pins for ESP32 (SDA=21, SCL=22) and ESP8266 (SDA=4, SCL=5).
Let me know if you need further help.
Regards,
Sara
 

0 Vote Up Vote Down
self.raymond answered 6 years ago

Need further help!!!  Need instruction on hooking the ds3231 up. I have used 5k pull up resister on both lines and try the i2c scan does not return device.  Importing the external library into Upycraft needs more instruction. after reset I get this on the i2c scan Need a little help
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4732
load:0x40078000,len:7496
load:0x40080400,len:5512
entry 0x4008114c

[0;32mI (399) cpu_start: Pro cpu up.[0m
[0;32mI (399) cpu_start: Single core mode[0m
[0;32mI (400) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (403) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m
[0;32mI (409) heap_init: At 3FFC0E00 len 0001F200 (124 KiB): DRAM[0m
[0;32mI (415) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m
[0;32mI (422) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (428) heap_init: At 400915E0 len 0000EA20 (58 KiB): IRAM[0m
[0;32mI (434) cpu_start: Pro cpu start user code[0m
[0;32mI (5) cpu_start: Starting scheduler on PRO CPU.[0m

OSError: [Errno 2] ENOENT

Start your code here

import machine
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
print(‘Scan i2c bus…’)
devices = i2c.scan()
if len(devices) == 0:
print(“No i2c device !”)
else:
print(‘i2c devices found:’,len(devices))
for device in devices:
print(“Decimal address: “,device,” | Hexa address: “,hex(device))

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.
I’m sorry for taking so long to get back to you.

I’m not sure if the resistors are really needed. I didn’t add any resistors and the sensor worked fine. But I’m using a DS1307.

Note that if you’re using an ESP32, the SDA is GPIO21 and the SCL is GPIO22 by default. So, use those pins instead.

Did you test the example sketch provided in the library page?

See this page and scroll down to the example.https://github.com/micropython-Chinese-Community/mpy-lib/tree/master/misc/DS3231
Then, change the SDA and SCL pins to GPIO21 and GPIO22, respectively.
Also, make sure that you have uploaded the library first.
With that library you don’t need to scan for an I2C device. It automatically detects the device.

Are you having trouble uploading the library?

Can you test the example first and see if it works?

Let me know how you are doing.

Regards,
Sara

0 Vote Up Vote Down
self.raymond answered 6 years ago

Yes uploading the external library took some time.  But I got that figure out.  The 2k resistors are working and I was able to run the i2c scan.  I found out the address of the ds3231 is (address = 87, 104), After I added that to the program all work fine.  Thank you for your help.  This has been a steep learning curve for me but I am slowing catching on. Again thanks for the help 

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

I’m glad you’ve figured it out and it is working now.
If you need further help, you just need to open a new question.
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.