In my mainthread, running on Core 0 of the Pico, I connect to a NB-IoT modem using the hardware UART and AT commands. (I'm having some difficulties there too with processing data while receiving it, see another post.) I decided to have the second core dedicated to treating the I/O logic. For getting started using the second core, I chose the easiest task one can imagine: blink an LED, quite easy I guessed.
But: while Core 0 is doing quite some UART operations (for modem set-up and communication) and some file operations for logging purposes, I see the LED stops blinking. That shouldn't be the case with multithreading on two cores, I would guess or am I missing something fundamental?
I've put my second thread in a separate module and added a lock to exit the infinite loop.
Code: Select all
import time
import _thread
from machine import Pin
from iopins import *
def main(log, mainThreadRunningSemaphore):
print("Starting up second Thread...")
while mainThreadRunningSemaphore.locked():
time.sleep(1)
OUT_1.toggle()
# We release the traffic light lock
#lock.release()
print("Exiting second Thread")
_thread.exit()
Code: Select all
...
mainThreadRunningSemaphore = _thread.allocate_lock()
mainThreadRunningSemaphore.acquire()
#startup logging
...
#create communication class instance
...
_thread.start_new_thread(secondThread.main, [log, mainThreadRunningSemaphore])
#do the modem things here (infinitely)
...
#after modem main thread stops
mainThreadRunningSemaphore.release()
...
Would there be a way to start a second micropython interpreter on the second core in order to have more independance?
Or should I switch to C instead of micropython to have better independance?
Or is this problem maybe hardware interrupt related?