Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4872

MicroPython • Re: multithreading with Raspberry Pi Pico

$
0
0
@Kodiak228
Thats a good bit of logic to overcome the continued running of the second core, but bear in mind the eventual program you will deploy to run on your pico will not be connected to a development IDE, and would usually be expected to continually run until switched off. The continued running of the second thread can be a frustration during the development process, but is often of no consequence for the eventual live running.

Also worth mentioning that using the second core would normally only be used when the load on the main core is depleting resources and warrants its use, but with the warning that its use can be a bit tricky. Most programs, including those needing to multi-task, will quite happily run on just one core. For things like flashing LED's, responding to button pushes, triggering relays etc one core is more than sufficient.

I see you have made a good start in you micropython journey but I see a few things you may like to get a greater learning on and the use of the 'global' stands out so I give a link to a short tutorial on using globals in python.
https://realpython.com/python-use-globa ... -function/

Also this article on using threading on the pico may be of value.
https://bytesnbits.co.uk/multi-thread-c ... cropython/

To advance to your goal of using button to activate a relay then this article may be good food for thought.
https://electrocredible.com/raspberry-p ... cropython/

Finally, its often the case of a bit of headscratch as to the best way to get a program that seems to need serval while loops to be running at the same time in order to achieve its goal, and using the other core to get another loop running (though only one extra while loop) can be seen as a solution. However, as you advance along your python path you may like to get asynchronous programming under your belt and theres no better tutorial on this than Peter Hinches tutorial and example programs as seen in the following link.
https://github.com/peterhinch/micropyth ... UTORIAL.md

I hope you enjoy your evolving python / micropython expertise and I'm sure you will soon get your first goal accomplished and no doubt greater goals will soon follow :-)

Statistics: Posted by SirFico — Sun Sep 29, 2024 9:58 am



Viewing all articles
Browse latest Browse all 4872

Trending Articles