Author Topic: Raspberry Pi Pico and MicroPython Multithreading  (Read 2045 times)

0 Members and 1 Guest are viewing this topic.

Offline rstoferTopic starter

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Raspberry Pi Pico and MicroPython Multithreading
« on: September 06, 2021, 05:44:35 pm »
I have had several Pi Picos laying on my bench for months and I thought I should play with them.  So I bought the Sunfounder Pi Pico Kit (just the usual parts kit) and a breadboard to simplify things.  The breadboard has LEDs, buttons and a buzzer and saves a lot of time while experimenting.

https://www.amazon.com/gp/product/B08XXHGSQ7
https://www.amazon.com/gp/product/B08TM2VHFF

The tutorials are at https://docs.sunfounder.com/projects/thales-kit/

Well, the tutorials start out with the usual boring stuff, a blinking LED, a button input and a fading LED - all rather routine.

Right up until I got to the Traffic Light experiment and they introduce multithreading.  Wait!  What?  That's new!  It's new enough that the MicroPython documentation doesn't want to talk about it so they send you to the CPython documentation:

https://docs.micropython.org/en/latest/library/_thread.html

But it works!  Multithreading in a Pi Pico without the tears!  Very cool...  No, I don't know the limitations and I haven't even looked at the documentation but it works!

I am doing the development work on a Pi 400 with the Thonny IDE.  This is pretty much an ideal way to work with the Pi Pico.

If you have a small project and multithreading seems important, check it out.  The Pi Pico is dirt cheap and one comes with each of the packages above.  Or you can get them from Amazon:

https://www.amazon.com/LANDZO-Raspberry-Pi-Pico/dp/B08VNR5RLF

It seems like they were less expensive when I bought them but $9 isn't all that much.
 

Offline Mr.What

  • Newbie
  • Posts: 1
  • Country: us
Re: Raspberry Pi Pico and MicroPython Multithreading
« Reply #1 on: May 20, 2022, 06:02:30 pm »
I'm starting with this.  They say that the multithreading is limited, since there is no OS.  Questions:
If a thread is already running, does _thread.start_new_thread() block?
   *** IMPORTANT.   If it does  we might want to lock BEFORE starting a worker thread, instead of inside as is typical
Is it OK to release a lock twice?  (I have a situation where this would be convenient.  Could I capture an error ane be ok?)
If I start many worker threads, and it does NOT block....  does it queue the workers (that would be best for most embedded apps)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf