GithubHelp home page GithubHelp logo

balance19 / micropython_ds3231 Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 9.0 12 KB

A library to run the DS3231 RTC on Raspberry Pi Pico

License: MIT License

Python 100.00%
ds3231 raspberry pi pico rtc micropython micropython-pi 24c32 eeprom

micropython_ds3231's Introduction

micropython_DS3231

Motivation:

I wrote this code mostly to learn new things in coding. I have a lot of experience with Atmel µControllers of course even Arduino's. Normally i code in Python and found out that there is micropython out there. That leads me to buy a "Raspberry Pi Pico"

Why did i build this project:

Honestly i didn't search the internet, wether there is already a solution out there or not. As i already mentioned i want to learn. ;-)

What problem does this project solve:

There isn't really a problem but makes the use of this board pretty easy. In addition the "Raspberry Pi Pico" is now capable to tell the correct time with high precision and more or less two lines of code.

What did I learn:

I learned the following things in this project
  • how to get started with the Raspberry Pi Pico and use VS Code to develope
  • how to work with classes
  • writing a library (never did this before)

What Features will follow in this project:

As my DS3231 Board has a EEPROM (24C32 32kbit) on board, i will include the functionalaty in this project. The Board i use, was originally for Arduino. Sadly i don't know the name of my board anymore.

How to use this library:

  • copy the folder my_lib in your project
  • add "from my_lib import RTC_DS3231" on top of your main file.
  • create the RTC object with "rtc = RTC_DS3231.RTC()"
  • use "rtc.DS3231_SetTime(b'\x00\x14\x18\x28\x14\x07\x21')" (modify the time and date) to set the Time. Do this only once or if you want to correct the Time.
  • use "t = rtc.DS3231_ReadTime(1)" to get the current Time.
  • use "print(t)" to send the time over uart to the PC

micropython_ds3231's People

Contributors

balance19 avatar jose1711 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

micropython_ds3231's Issues

upload to pypi

could you please upload this to pypi so it can be downloaded directly from Thonny?

I have to ask because I added these lines

under class RTC
m = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

under def DS3231_ReadTime
month = self.m[self.bcd2bin(buffer[5])]

in if mode ==
if mode == 2:
mod2_string = str(hour) + ":" + str(minute) + ":" + str(second) + " " + weekday + " " + month + "." + str(day) + "," + str(year)
return mod2_string

and finally change 1
t = rtc.DS3231_ReadTime(2)
yet after slapping it into my raspberry pi pico I'm getting the Error: Is the DS3231 not connected display on a 1602 LCD

Using different I2C ports

When I try to use differnt I2C ports on the pico your code give me an error that it can't find the device:
"Error: is the DS3231 not connected or some other problem ([Errno 5] EIO)
Error: is the DS3231 not connected or some other problem ([Errno 5] EIO)"

I have tried changing the port info in your library but it just doesn't take. I can use a simple I2C scanner and see the clock there.

A error i can't solve ([Errno 5] EIO)

I connected the DS3231 to my Pico: SDA to pin 16, SCL to pin 17, GND to GND and VCC to VSYS.
I copied the example code in main.py and put the RTC_DS3231.py in a my_lib folder. I didn't change any code.

When i tried to run the code I got the error: ([Errno 5] EIO) and when i tried Settime() in the example code I got:
Traceback (most recent call last):
File "", line 13, in
File "my_lib/RTC_DS3231.py", line 26, in DS3231_SetTime
OSError: [Errno 5] EIO

I tried to run a I2C address scan and got 0x57, but when a changed the address it still got the same error massages.

Does someone know how to solve this problem and make it work like intended?

"index out of range" error. Weekday string should be as follows.

When going from Thursday to Friday, program is trying to access in w the eight element. List is only seven elements long.
I replaced :
class RTC:
w = ["SAT","SUN","MON","TUE","WED","THU","FRI"]

with:
class RTC:
w = ["null","SAT","SUN","MON","TUE","WED","THU","FRI"]

Or weekday = self.w[self.bcd2bin(buffer[3])] should be
weekday = self.w[(self.bcd2bin(buffer[3]) - 1)]

Byte for "week" in DS3231_SetTime is for day of the week, not week of the year

I'm not sure if this code is still being maintained, but even if it isn't, this might be useful for other users.
The default NowTime for DS3231_SetTime has x28 for the "week" byte. This byte is actually the day of the week on the DS3231, not the week of the year. It is meant to have values from x01 to x07, with an arbitrary start of the week. If you choose to map the values to the more usual 0-6 system, with Sunday as 0 (like Javascript), then the value should be x04 (Wednesday 14 July 2021), not x28.
Most times it shouldn't matter as the DS3231 ignores the highest 4 bits and unless you are relying on the device for the day of the week, it won't affect the date and time readings.
I suggest that the byte be named "weekday" rather than "week" and the x28 be changed to x04.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.