Closed schamu closed 2 years ago
Please use three backticks to enclose code in your post. You have only two. And please tell which firmware version you use.
It's ma error please delete
it is my error, please delete
No problem. You can delete it yourself, but the history remains. But it also my experience that writing up a problem for others to read helps a lot to find a solution. And it is important that this text is actually sent. In that respect, it is good that you have sent it
Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab or raise a documentation request instead.
In your issue, please include a clear and concise description of what the bug is, the expected output, and how to replicate it.
If this issue involves external hardware, please include links to relevant datasheets and schematics.
If you are seeing code being executed incorrectly, please provide a minimal example and expected output (e.g. comparison to CPython).
For build issues, please include full details of your environment, compiler versions, command lines, and build output.
Please provide as much information as possible about the version of MicroPython you're running, such as:
Remove all placeholder text above before submitting.
I think here is an error in the modul treaed and irq RP2040 here is the code:
``# 10.09.2022 by Thomas Steffen from machine import Pin, Timer, I2C, ADC, RTC, UART from time import sleep, sleep_ms, ticks_ms, ticks_diff, localtime, mktime, time from astrodata import isSommerzeit, tagnacht, isNacht from sh1106 import WIDTH, HEIGHT, SH1106_I2C as DISPLAY import sys, statistics, _thread
from dcf77_anzeige_matrix import anzeige_schreiben
from dcf77_anzeige_streifen import anzeige_schreiben
version = sys.implementation.version version = "("+str(version[0])+"."+str(version[1])+"."+str(version[2])+")" print("
~~~~~~~~~~~~~~") print("RPi-Pico MicroPython Ver:", sys.version, version) print("~~~~~~~~~~~~~~")Test / Uhr
dcf_pin = Pin(28, Pin.IN, Pin.PULL_UP) # GPIO-Pin für DCF-Signal (2) (22) dcf_led = Pin("LED", Pin.OUT) # GPIO-Pin für interne LED (7) (25) ldr = ADC(27) # GPIO-Pin für Lichtsensor (27) (27) anzeige_helligkeit = 10 # Helligkeit der LEDs (0-255) anzeige_farbe = 6 #0 aus #1 rot #2 grün #3 blau #4 gelb #5 violett #6 türkis #7 weiß ldr_liste = [800]*10 rtc = RTC() uart = UART(0, baudrate=115200, rx=Pin(1), tx=Pin(0)) i2c = I2C(0, scl=Pin(9), sda=Pin(8))
DCF77 Deklarationen
puls_start, puls_stop = False, False start_high, start_low = 0, 0 laenge_high, laenge_low = 0, 0 timeInfo = [] # DCF-Bits zur Auswertung dcf_bits = [] # DCF-Bits der laufenden Minute dcf_sync = 3 # 0-OK; 1-Sekunde 59 erkannt; 2-Fehler; 3-Start; 4-StundenSync bitnr, signal, sommerzeit, nacht = 0, 2, 2, 0 wt = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"] sz = ["MEZ", "MESZ",""] do = [",", ",", ":", ":", ";"] s = [] # Sonnenaufgang/Untergang
Ticker Deklarationen
isSekunde, isMinute, isStunde = 0, 0, 0 isTag, is50hz, is4Hz = 0, 0, 0 z50hz, zSekunde, zMinute, zStunde = 50, 60, 60, 24
def computeTime(): global timeInfo, wt, sz if timeInfo[0] != 0 or timeInfo[20] != 1 or sum(timeInfo[21:29]) % 2 != 0 or sum(timeInfo[29:36]) % 2 != 0 or sum(timeInfo[36:59]) % 2 != 0 or sum(timeInfo[17:19]) != 1: print("Empfangsfehler: parity bits or constant bits have unexpected values") return 2 sommerzeit = timeInfo[17] minute = timeInfo[21] + 2 timeInfo[22] + 4 timeInfo[23] + 8 timeInfo[24] + 10 timeInfo[25] + 20 timeInfo[26] + 40 timeInfo[27] stunde = timeInfo[29] + 2 timeInfo[30] + 4 timeInfo[31] + 8 timeInfo[32] + 10 timeInfo[33] + 20 timeInfo[34] tag = timeInfo[36] + 2 timeInfo[37] + 4 timeInfo[38] + 8 timeInfo[39] + 10 timeInfo[40] + 20 timeInfo[41] wochentag = timeInfo[42] + 2 timeInfo[43] + 4 timeInfo[44] monat = timeInfo[45] + 2 timeInfo[46] + 4 timeInfo[47] + 8 timeInfo[48] + 10 timeInfo[49] jahr = timeInfo[50] + 2 timeInfo[51] + 4 timeInfo[52] + 8 timeInfo[53] + 10 timeInfo[54] + 20 timeInfo[55] + 40 timeInfo[56] + 80 * timeInfo[57] rtc.datetime((2000+jahr, monat, tag, wochentag-1, stunde, minute, 0, 100)) print("{:s}, {:02d}.{:02d}.{:d} {:02d}:{:02d}:{:02d} {:s} syncronisiert".format(wt[wochentag-1], tag, monat, 2000+jahr, stunde, minute, 0, sz[sommerzeit])) return sommerzeit def handle_interrupt(dcf_pin): global puls_start, start_high, laenge_low
global puls_stop, start_low, laenge_high, bitnr, dcf_bits, signal if dcf_pin.value() == 1: # Puls Start if dcf_sync != 7: dcf_led.value(1) start_high = ticks_ms() laenge_low = ticks_diff(ticks_ms(), start_low) puls_start = True
else: # Puls Ende dcf_led.value(0) start_low = ticks_ms() laenge_high = ticks_diff(ticks_ms(), start_high) signal = 2 if laenge_high > 40 and laenge_high < 130: signal = 0 if laenge_high > 150 and laenge_high < 220: signal = 1
dcf_bits.append(signal) bitnr += 1 puls_stop = True
def core1_thread(): global isSekunde, isMinute, isStunde, isTag, is4Hz t2 = localtime() c = 0 while True: t1 = localtime() if c == 40: is4Hz, c = 1, 0
if t1[5] != t2[5]: isSekunde = 1 if t1[4] != t2[4]: isMinute = 1 if t1[3] != t2[3]: isStunde = 1 if t1[2] != t2[2]: isTag = 1 t2 = t1 sleep(0.01) c += 1
t = localtime() sommerzeit = isSommerzeit() s = tagnacht(t, sommerzeit) nacht = isNacht(t, s) oled_sync = 2 # kein oled angeschlossen if i2c.scan(): # scanne i2c-Bus oled_sync = 0 # oled angeschlossen print("I2C Configuration: "+str(i2c)) # Display I2C config for x in i2c.scan(): print("I2C Address : "+hex(x).upper()) # Display device addresses print("
~~~~~~~~~~~~~~") oled = DISPLAY(128, 64, i2c) # Init oled display (WIDTH, HEIGHT, i2c) oled.fill(0) # Clear the oled display in case it has junk on it. oled.text("Pi Pico dcf77",12,0) # Add some text oled.hline(10,9,108,1) # Linie drunter oled.show() print("Uhrzeit: {:0>2d}:{:0>2d}:{:0>2d}".format(t[3],t[4],t[5])) zSekunde = 60 - t[5] # Sekunden syncronisieren zMinute = 60 - t[4] # Minuten syncronisieren zMinute = 24 - t[3] # Stunden syncronisierensecond_thread = _thread.start_new_thread(core1_thread, ()) dcf_pin.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler = handle_interrupt)
while True:
if puls_start: puls_start = False if dcf_sync == 1:
result = computeTime() if result < 2: t = localtime() z50hz = 50 # 50Hz syncronisieren zSekunde = 60 # Sekunden syncronisieren zMinute = 60 - t[5] # Minuten syncronisieren zStunde = 24 - t[4] # Stunden syncronisieren dcf_sync = 0 sommerzeit = result s = tagnacht(t, sommerzeit) nacht = isNacht(t, s) print("Aufgang: {:0>2d}:{:0>2d}".format(s[0],s[1]), " Untergang: {:0>2d}:{:0>2d}".format(s[2],s[3]), " Nacht:", nacht) else: dcf_sync = 2
laenge_puls = laenge_high + laenge_low