Git Product home page Git Product logo

micropython-dcf77's Introduction

micropython-dcf77

Micropython modul to decode the dcf77 signal delivered by a receiver module.

To use this module you need an dcf77 receiver module connectet to a gpoi pin of your board.

Class

tco_pin = The pin object for the pin where the receiver is connected
false_time = Min/Max time in ms for detecing a 0 pulse
true_time = Min/Max time in ms for detecting a 1 pulse
pause_time = Min/Max time in ms for detecting the beginning of the telegramm
>>> dcf = dcf77.dcf77(machine.Pin(0))

Methods

start

Starting the receiving and decoding of the telegramm.

>>> dcf.start()

stop

Stopping the receiving and decoding of the telegramm.

>>> dcf.stop()

get_LastSignal

Returns the last telegram as list

>>> dcf.get_LastSignal()
[0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0]
>>>

get_DateTime

Returns the actual time and date informations as an 8-tuple which contains: year, month, day, weekday, hours, minutes, seconds, subseconds This tuple can be directly used with the machine.RTC module

  • year contains only the last 2 digest

  • seconds is everytime 0, when with_seconds is TRUE the value will be set to the actual tick

  • subseconds is everytime 0

  • If None is returned the signal is not valid

  • If some value return 999 the decoding failed

>>> dcf.get_DateTime(with_seconds=False)
[23, 11, 10, 4, 16, 33, 0, 0]
>>>

get_Infos

Returns some infos

>>> dcf.get_Infos()
{'Call bit': 0, 'Summer time announcement': 0, 'Found59': True, 'Valid': True, 'Leap second': 0, 'Tick': 49, 'Last pulse length': 102, 'CEST': 0, 'CET': 1}
>>>

get_irq

Enables an custom irq handler for various events.
Mode has to be a list of the following modes:

  • IRQ_MINUTE = irq is fired when the minute changed
  • IRQ_HOUR = irq is fired when the hour changed
  • IRQ_DAY = irq is fired when the day changed
  • IRQ_MONTH = irq is fired when the month changed
  • IRQ_YEAR = irq is fired when the year changed
  • IRQ_DST = irq is fired when the DST flag changes to TRUE
>>> dcf.irq(mode=[dcf.IRQ_DAY, dcf.IRQ_DST], handler=myhandler)

debug

Enable and disable debug messages on the console.

>>> dcf.debug(True)

Sample Code

import machine
import dcf77

dcf = dcf77.dcf77(machine.Pin(0))

# Starting receiving and decoding
dcf.start()

rtc = machine.RTC()

# Cutstom irq handler
def handler():
    print("It's a new day or year.")

dcf.irq([dcf.IRQ_DAY, dcf.IRQ_YEAR], handler)

print("RTC initalized")
datetime = rtc.datetime()
print("Actual time: {:02d}:{:02d} {:02d}.{:02d}.{}".format(datetime[4], datetime[5], datetime[2], datetime[1], datetime[0]))

print("Wait for a valid dcf77 signal")
while not dcf.get_Infos()['Valid']:
    pass

print("Found Valid signal")
datetime = dcf.get_DateTime()
print("DCF77 time: {:02d}:{:02d} {:02d}.{:02d}.{}".format(datetime[4], datetime[5], datetime[2], datetime[1], datetime[0]))

print("Setting RTC")
rtc.datetime(datetime)

micropython-dcf77's People

Contributors

dsiggi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

vtt-info

micropython-dcf77's Issues

Code in date parity not working

the dsiggi micropython dcf77 program is a great piece of work providing kind of a background task for decoding the second pulses of dcf77. Installed on a RPI pico it functioned on a SW testbed together with existing display routines, sensor readings etc without creating delays, hangups or alike.
However there was a misunderstanding of the dcf77 coding scheme. In dcf77 code the time information has an individual parity check for minutes and hours which is correctly implemented. The date, weekday and year information has only one combined parity bit. So the repeated application of the time decoding def __decode_datetime(self,time) produces an error result 999 every time even though the date bits are decoded correctly.
Installed on a RPi pico with a Pollin dcf receiver it needed a little bit of tweaking of the min/max values of dcf's "0" and "1" to higher values. If the signal decoding is split into ...
__decode_time(self,time) : code just as before, and
__decode_date(self,time) without parity check and a third new
__check_date_parity(self,time) that just checks parity of self.signal_last[36:57] it works as perfect as a dcf77 decoder program can.

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.