How to use the two Cores of the Pi Pico? And how fast are Interrupts?



The new Pi Pico has two cores. How can we use both? And: If you want to play with the Pico, this video can save you a lot of time because we will discover the main differences between programming an Arduino and a Pi Pico. After this video, you will know more than 99% of all Pi Pico users. And you know how to avoid some quirks.
I am a proud Patreon of @GreatScott!, @ElectroBOOM , @Electronoobs , @EEVblog , and others
No Docker, No Microsoft Teams, Zoom

Links:
Pi Pico: https://amzn.to/2ZyCwao or https://amzn.to/3k2PNSd
Book: https://hackspace.raspberrypi.org/books/micropython-pico

The links above usually are affiliate links that support the channel (no additional cost for you).
Supporting Material and Blog Page: http://www.sensorsiot.org
Github: https://www.github.com/sensorsiot
My Patreon Page: https://www.patreon.com/AndreasSpiess
Discord: https://discord.gg/JfgDSa8
If you want to support the channel, please use the links below to start your shopping. No additional charges for you, but I get a commission of your purchases to buy new stuff for the channel
My Amazon.com shop: https://www.amazon.com/shop/andreasspiess
For Banggood https://bit.ly/2jAQEf4
For AliExpress: http://bit.ly/2B0yTLL
For Amazon.de: http://amzn.to/2r0ZCYI
For Amazon UK: http://amzn.to/2mxBaJf
For ebay.com: http://ebay.to/2DuYXBp

https://www.facebook.com/profile.php?id=100013947273409
https://twitter.com/spiessa
https://www.instructables.com/member/Andreas%20Spiess/
Please do not try to email me. This communication channel is reserved for my primary job
As an Amazon Associate, I earn from qualifying purchases
#no#midroll#ads

source

27 thoughts on “How to use the two Cores of the Pi Pico? And how fast are Interrupts?

  • March 10, 2021 at 8:34 pm
    Permalink

    A great video as always Andreas! I happened to have the C++ dev environment setup on the bench using a Raspberry Pi 4 and therefore was able to quickly measure the interrupt response time with my oscilloscope. This turned out to be 1.1us when built for debug and 1.0us for release. The release version seems to have some jitter of around 0.1us whereas the debug version doesn't which seems a bit unusual.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    greets from ukraine!
    u have very good english, easily understandable even for non english-speaken guys like me.
    doing electronics as hobby for 20 years, but still can get some new knowledge from any of your videos.
    so what we can say about newbies. its a heaven for them.
    keep it up, man

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Having that much cpu power in a tiny board with few pins is like having a v8 engine on a unicycle . Cpu power is usually needed in high resolution graphics rendering , cadcam or dsp audio. A machine control would need a lot more i/o lines .. eg an ECU for a modern car needs 50+ input lines. No sensor really needs that kind of speed as most pid loops can run fine on a 40 mhz 8 or 16 bit processor, because sample time of the sensor is usually very slow.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Hi
    can I run 2 threads using the baton?
    in your case you are running one thread and one loop
    Regards,
    Suded

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    I think you messed up your testing, You used MicroPython to test "Reaction Time" for the Pico and C++ for the ESP and STM why did you not use C++ on the Pico? C++ runs faster on the pico compared to MicroPython which is a known fact, Basically you demonstrated a flawed test to make the Pico look worse than it is

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Is the Keysight giveaway really open to makers or only people in the hardware/firmware industry?

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    I tested the speed of the GPIO pins with a PIO function on the Pico, from MicroPython. The simplest and fastest PIO program for this is a pin toggle with two instructions: set on and set off. It juuust still works with a PIO program frequency of 8 MHz which means the square wave is 4 MHz because each instruction (those two anyway) take one cycle. Code and scope screenshots: https://ee1.nl/misc/PIO.html

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    if passing the baton back and forth means only one core is running at a time, what's the benefit over a single core?

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    This implementation of the _thread module is specific for the RP2040. In the ESP32 it works differently. The second core is not used there.

    Then you assume that automatic memory locking is implemented between threads. However, the documentation states explicitly there is no GIL (Global Interpreter Lock) used. Which means that bad things can happen with shared access to objects. It is probably safe to read objects written by the other thread, but mutual writes, deletes etc might give surprises.

    For interrupts there may be restrictions too. Documentation is a bit sparse in that area. On ESP32 you typically use micropython.schedule() to get out of interrupt mode and continue processing in normal mode. Still need to check how they did this for the rp2 port.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Grüässäch Härr Spiess, when threads communicate with bigger datas you can also use just a flag (like the american mailboxes) "data there and consistent".sender stes the flag, reader resets it. with this, all threads are happy running all the time as for me, it looks like the .aquire stops the others.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Can you make a video about differences in circuitpython and micropython? This kind of threading is not possible in micropython. But in micropython there is no way to use it as usb-device…

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    12:35 don't you have a usb sonoff(or however they are called), you could use that to turn power off and back on to reset

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    How do I contact you if your open to that on a project, or If anyone else see this and you could help me out, please reply I have two projects I would like made and my paralysis is preventing me doing things myself? One I think is simple and will take little time other just a needed wish project that might you might not be interested. Love your Swiss humor..

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Gratuitous comment to boost engagement.
    Also, snoring cats are cute.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    There is a good tutorial somewhere I read the other day that takes you through the steps of adding your own reset button…

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Of course the Pi pico would be slower with interrupts. The code you're running is read by a firmware that interprets Micropython, unlike coding with Arduino, which is literally writing a firmware. Both have their pros and cons. At least if you have a process running, you might not have to totally shutdown your systwm while reprogramming your Pico

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Thanks, very useful video. I especially like the footage of your sleepy lab assistant at the end

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Can you (or have you already done) a video on using C/C++ with the Pico? Python is a nice language for quick prototyping, but C/C++ generates machine code while python is interpreted and therefore slower. (I'm not sure how the runtime of an interpreted language actually handles threads and multiple cores).
    You can HAVE a reset button by connecting a push button to the run pin and ground.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Great video. Can you please consider doing some C++ on the Pico? Python is not my favourite language and I can use my Arduino C skills. 73s

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    you need to buy a micro usb cord with the switch in it. they sell them online very cheap. then you don't need to unplug your pico to reset it – you just click the switch in the cord.

    Reply
  • March 10, 2021 at 8:34 pm
    Permalink

    Thanks for the video, Andreas:)
    PIN30 RUN -> RUN is the RP2040 enable pin, and has an internal (on-chip) pull-up resistor to 3.3V of about ~50K Ohms. To reset
    RP2040, short this pin low.
    2021, Raspberry Pi Pico Datasheet, page 7,8. … RTFD!;)

    Reply

Leave a Reply

Your email address will not be published.