I am using a ds3231 RTC on the esp32 and also with an esp8266 in Micro-python. Looking for a little help
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.
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
mode:DIO, clock div:2
[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
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 !”)
print(‘i2c devices found:’,len(devices))
for device in devices:
print(“Decimal address: “,device,” | Hexa address: “,hex(device))
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.
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