Coder Social home page Coder Social logo

micropython-ds1302-rtc's Introduction

Micorpython DS1302 RTC Clock driver

This is a pure Micropython DS1302 RTC Clock driver. This is based on microbit code of microbit-lib https://github.com/shaoziyang/microbit-lib

This has been tested and working on ESP32 but should work with any micropython supported device.

Dirver documentation

(Adapted from https://github.com/shaoziyang/microbit-lib/blob/master/misc/DS1302/README.md)

DS1302 is real-time clock (RTC) with serial interface, 31 * 8 data ram.

API

  • __init__(clk, dio, cs)
    set i/o pins

  • start()
    start RTC.

  • stop()
    stop/pause RTC

  • date_time(DT = None)
    get / set DateTime. If no paramter given, it will return current datetime, otherwise it will set datatime.
    datatime format: [Year, month, day, weekday, hour, minute, second]

  • year(year = None)
    get / set year.

  • month(month = None)
    get / set month.

  • day(day = None)
    get / set day.

  • weekday(weekday = None)
    get / set month.

  • hour(hour = None)
    get / set hour.

  • minute(minute = None)
    get / set minute.

  • second(second = None)
    get / set second.

  • ram(reg, dat = None)
    get / set ram data (31 bytes).

example

from machine import Pin
import ds1302

ds = ds1302.DS1302(Pin(5),Pin(18),Pin(19))

ds.date_time() # returns the current datetime.
ds.date_time([2018, 3, 9, 4, 23, 0, 1, 0]) # set datetime.

ds.hour() # returns hour.
ds.second(10) # set second to 10.

micropython-ds1302-rtc's People

Contributors

omarbenhamid avatar yunline avatar

Stargazers

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

Watchers

 avatar  avatar

micropython-ds1302-rtc's Issues

ESP8266 12E

I have a esp8266 with micropython on and this does not work at all , the date can not be set at all
keep getting [2000, 0, 0, 0, 0, 0, 0] as the date even if I explicitly set the date with ds.date_time([2022, 0, 0, 0, 0, 0, 0])
ds.year() still returns 2000

My Pins config
RTC CONNECTIONS:
DS1302 CLK/SCLK --> D5
DS1302 DAT/IO --> D4
DS1302 RST/CE --> D2
DS1302 VCC --> 3.3v - 5v
DS1302 GND --> GND

ds = DS1302(Pin(5), Pin(4), Pin(2))
ds.start()
ds.date_time() output is [2000, 0, 0, 0, 0, 0, 0]

Upload to pypi

Could you please upload this to pypi.org so that one can easily install the package from e. g. Thonny? Thanks.

Question about wiring

Hello,

thanks for your code.

I try to figure out the wiring, because some pins on my pico are already connected.
In your code we read:
ds = ds1302.DS1302(Pin(5),Pin(18),Pin(19))

Which are pins 5, 18 et 19 ?
5 is GP2 / SPI0-SCK OR GP3/SPI0-Tx OR GP5 ?
18 is gnd OR I2C SDA/SPI-SCK/GP14 OR GP18 ?
19 is I2C SDA/SPI-SCK/GP14 OR I2C SCL/SPI-TX/GP15 OR GP19 ?

I've tried with the following wiring:

Pico ==>>> UTC
GND -> GND
3.3V -> VCC
I2C0-SDA (pin 1) -> DAT
I2C0-SCL (pin 2) -> CLK
GP4 (pin 6) -> RST

with no success.

Thanks for you help.

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.