Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread and irq don't go #9271

Closed
schamu opened this issue Sep 10, 2022 · 4 comments
Closed

Thread and irq don't go #9271

schamu opened this issue Sep 10, 2022 · 4 comments

Comments

@schamu
Copy link

schamu commented Sep 10, 2022

  • 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:

  • firmware file name
  • git commit hash and port/board
  • version information shown in the REPL (hit Ctrl-B to see the startup message)
  • 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 syncronisieren

second_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
#print(signal,end="")
#print("Puls: {:0>2d} - {:0>1d} - {:0>3d} - {:0>4d} - {:0>4d} - {:0>1d}".format(bitnr, signal, laenge_high, laenge_low, laenge_puls, dcf_sync))
if ticks_diff(ticks_ms(), start_high) > 1050:
if bitnr == 59:
#print("sync: 59")
if dcf_sync != 0:
dcf_sync = 1
timeInfo = dcf_bits
dcf_bits = []
bitnr = 0
start_high = ticks_ms()
if isSekunde > 0:
isSekunde = 0
t = localtime()
print(50-z50hz, 60-zSekunde, t[5])
if t[4] == 59 and t[5] == 50: dcf_sync = 4 # Stündlicher DCF-Sync
ldr_liste.append(ldr.read_u16())
ldr_liste.pop(0)
licht = int(statistics.median(ldr_liste))
if oled_sync < 2:
oled.fill_rect(0,20,80,8,0)
oled.text("ldr: {:.0f}".format(licht),0,20)
oled.fill_rect(0,32,128,8,0)
oled.text("{:0>2d}:{:0>2d} - {:0>2d}:{:0>2d} {:1d}".format(s[0],s[1],s[2],s[3], nacht),0,32)
oled.fill_rect(0,44,127,8,0)
oled.text("{:s}{:s}{:0>2d}.{:0>2d}.{:0>2d} {:s}".format(wt[t[6]],do[dcf_sync],t[2],t[1],t[0]-2000, sz[sommerzeit]),0,44)
oled.fill_rect(0,56,127,8,0)
oled.text("{:0>2d}:{:0>2d}:{:0>2d} ({:0>2d}:{:0>1d})".format(t[3],t[4],t[5], bitnr, dcf_sync),0,56)
oled_sync = 1
helligkeit = anzeige_helligkeit
if nacht == 1: helligkeit = 1
if nacht == 2: helligkeit = 6
if helligkeit > 1 and licht > 5000: helligkeit = 1
#print(helligkeit, licht, ldr_liste, s)
anzeige_schreiben(t, anzeige_farbe, helligkeit, dcf_sync)
if isMinute > 0:
isMinute = 0
nacht = isNacht(t, s)
print("{:s}, {:02d}.{:02d}.{:d} {:02d}:{:02d}:{:02d} {:s}".format(wt[t[6]], t[2], t[1], t[0], t[3], t[4], t[5], sz[sommerzeit]), " Nacht:", nacht)
if isStunde > 0:
isStunde = 0
if isTag > 0:
isTag = 0
print("Tag")
if is4Hz > 0:
is4Hz = 0
#
led.toggle()
if oled_sync == 1:
oled_sync = 0
oled.show()

@schamu schamu added the bug label Sep 10, 2022
@robert-hh
Copy link
Contributor

robert-hh commented Sep 10, 2022

Please use three backticks to enclose code in your post. You have only two. And please tell which firmware version you use.

@schamu
Copy link
Author

schamu commented Sep 10, 2022

It's ma error
please delete

@schamu
Copy link
Author

schamu commented Sep 10, 2022

it is my error, please delete

@schamu schamu closed this as completed Sep 10, 2022
@robert-hh
Copy link
Contributor

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

tannewt added a commit to tannewt/circuitpython that referenced this issue May 31, 2024
…es-9.1.0-beta.3

update frozen modules for 9.1.0-beta.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants