Package: micropython-ds1307
MicroPython DS1307MicroPython driver for DS1307 RTCGeneralMicroPython driver for DS1307 RTC📚 The latest documentation is available atMicroPython DS1307 ReadTheDocs📚InstallationInstall required toolsSetupInstall package with upipGeneralSpecific versionTest versionManuallyUpload files to boardUsageContributingUnittestsCreditsInstallationInstall required toolsPython3 must be installed on your system. Check the current Python version
with the following commandpython--version
python3--versionDepending on which commandPython 3.x.y(with x.y as some numbers) is
returned, use that command to proceed.python3-mvenv.venvsource.venv/bin/activate

pipinstall-rrequirements.txtSetupInstall package with upipConnect the MicroPython device to a network (if possible)importnetworkstation=network.WLAN(network.STA_IF)station.active(True)station.connect('SSID','PASSWORD')station.isconnected()GeneralInstall the latest package version of this lib on the MicroPython deviceimportmipmip.install("github:brainelectronics/micropython-ds1307")For MicroPython versions below 1.19.1 use theupippackage instead ofmipimportupipupip.install('micropython-ds1307')Specific versionInstall a specific, fixed package version of this lib on the MicroPython deviceimportmip# install a verions of a specific branchmip.install("github:brainelectronics/micropython-ds1307",version="feature/initial-implementation")# install a tag versionmip.install("github:brainelectronics/micropython-ds1307",version="0.1.0")For MicroPython versions below 1.19.1 use theupippackage instead ofmipimportupipupip.install('micropython-ds1307')Test versionInstall a specific release candidate version uploaded toTest Python Package Indexon every PR on the
MicroPython device. If no specific version is set, the latest stable version
will be used.importmipmip.install("github:brainelectronics/micropython-ds1307",version="0.1.0-rc1.dev1")For MicroPython versions below 1.19.1 use theupippackage instead ofmipimportupip# overwrite index_urls to only take artifacts from test.pypi.orgupip.index_urls=['https://test.pypi.org/pypi']upip.install('micropython-ds1307')See alsobrainelectronics Test PyPi Server in Dockerfor a test PyPi server running on Docker.ManuallyUpload files to boardCopy the module to the MicroPython board and import them as shown below
usingRemote MicroPython shellOpen the remote shell with the following command. Additionally use-b 115200in case no CP210x is used but a CH34x.rshell--port/dev/tty.SLAB_USBtoUART--editornanoPerform the following command inside thershellto copy all files and
folders to the devicemkdir/pyboard/lib
mkdir/pyboard/lib/ds1307

cpds1307/*/pyboard/lib/ds1307

cpexamples/main.py/pyboard
cpexamples/boot.py/pyboardUsagefromds1307importDS1307frommachineimportI2C,Pinfromtimeimportgmtime,time# DS1307 on 0x68I2C_ADDR=0x68# DEC 104, HEX 0x68# define custom I2C interface, default is 'I2C(0)'# check the docs of your device for further details and pin infos# this are the pins for the Raspberry Pi Pico adapter boardi2c=I2C(0,scl=Pin(13),sda=Pin(12),freq=800000)ds1307=DS1307(addr=I2C_ADDR,i2c=i2c)# get the current RTC timeprint("Current RTC time:{}".format(ds1307.datetime))# set the RTC time to the current system timenow=gmtime(time())ds1307.datetime=nowprint("Current RTC time:{}".format(ds1307.datetime))# Print the date and time in ISO8601 format: 2023-04-18T21:14:22print("Today is{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}".format(ds1307.year,ds1307.month,ds1307.day,ds1307.hour,ds1307.minute,ds1307.second))ContributingUnittestsRun the unittests locally with the following command after installing this
package in a virtual environment# run all testsnose2--configtests/unittest.cfg# run only one specific testsnose2tests.test_ds1307.TestDS1307.test_addrGenerate the coverage files withpythoncreate_report_dirs.py
coveragehtmlThe coverage report is placed atreports/coverage/html/index.htmlCreditsBased onMike Causer's MicroPython TinyRTC I2C moduleand thePyPa sample project