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.
To add a bit more to my last comment, I did a some more investigation and it appears that the minimum execution time of a GPIO interrupt handler is 5 us (i.e. even if it does nothing) which seems like an awful lot of overhead. I searched the data sheet for the processor and the SDK documentation and source code but could find no explanation for this behaviour. Probably someone more familiar with the ARM processor architecture will know. Cheers!
Micropython seems to have a "hard = true" option when assigning an IRQ to a pin. Maybe this would also make it a bit faster. Maybe I might try this someday.... docs.micropython.org/en/latest/library/machine.Pin.html
@@AndreasSpiess Reset buttons are also a danger. I've pressed them inadvertently too many times. You could pull the other end of the usb cable to spare the soldered on connector. (Great content and presentation by the way! And that's a cool cat :))
I got so annoyed with having to do this when working on MCU breakout boards, I made a small PCB pass-through board with a gang switch on it to break all USB connections. A small but very nice quality of life improvement.
You don't even need a button. Just connect a Wire from ground to the RUN pin, and you reser the device. I think you need to add that, so we Will stop this nonsens with pulling the USB-cable to reset the device. Just ground RUN pin on the device!
Two 32-bit core running at 1330 x faster than the Apollo 15bit guidance computer. 1960s Apollo engineer: what are you using this awesome power for? Maker: I make LED go on and off! Apollo engineer: wtf 🙄
freeRTOS !! Yea, I just started reading the official docs last week. Half way through mastering freeRTOS already. Cool stuff in there. These topics will advance/enhance our lives 4 sure
Agreed, a reset button is important on any board that will go through many development cycles. It's not just about resetting when it locks up, but also about watching what happens when it is powered up. Yes, there are ways of doing it by button, but 5p extra for a reset button is something I'd happily pay. That said, leave the button off but put pads on the board for me to add it.
This is super helpful. I might use C++ instead for my project if the SNES clock/latch pin is too fast for my project. I hope so, because then i might be able to get away with using 0 shift registers instead of 2 per emulated controller
Twist: now that we have watched the video as all pico users do, we are no more in the 99% club. Because Andreas educated *all* pico users. The 99% already know about interrupts, two cores etc 😎 Hurry up if you want to be in the 1%-range (for a second).
This is a great presentation. Lots of good information to use when I can get my hands on a supply of these boards. The only ones currently available in the US are from scalpers charging 3 times or more than companies taking back orders. Perhaps I'll just have to suck it up and wait until March 17 when legitimate orders are fulfilled at a reasonable price. I think there will be a version at some point with WIFI and Blue Tooth to compete with the Esp-32 if the price is comparable. I hope you have a great day.
@@AndreasSpiess I would settle for LoRa over wifi. It would be nice to read sensor data over a distance. In fact I think LoRa would be more useful anyway.
@@kosmasraptis8374 I saw that it was available, unfortunately they will only let you buy 1 and I want 10. I guess I can suck it up and buy just one. I just hate to pay huge shipping charges on something that cost 6 dollars..I already have a project in mind so I might as well buy the one before they are all gone. The device is technically bluetooth ready but it's not currently activated.
What is the issue with the RESET? Since you're already connecting external components to it, you might as well add a tactile button between GND and pin 30 (confusingly called RUN) to reset the chip.
@@AndreasSpiess That wasn't quite clear from the video or I missed it. I can totally understand why they haven't added one; if you're a maker and hooking up external components on a breadboard anyway you might as well add a reset button (the pullup is already there) if you need it but if you're integrating the board on your own circuits you may not have a need for it or it could potentially be in the way if you don't want users to fool around with it (I certainly have removed reset buttons in the past). Either way I think it is fine as is and just wasn't sure whether you knew about the exposed NRST pad...
Your professional approach just made the two cores act like a single core. The problem with locks is called deadlock, where the key or keys are not released and the thread process dies. If you want the software to safe all passing of variables needs to be atomic, as in a single atomic particle. If you have to read, modify and write to global variable you would place a lock around it so three actions become the same as one atomic action. So the variable cant be changed by another thread while its being worked on. With deadlocks the reset may be your only friend.
You are right. We will talk about that in my RTOS video. I think, here, the firmware takes care of the blocking. But still, I needed a reset button from time-to-time...
Python on microcontrollers is a nice idea for absolut beginners and nontechnitions. It makes no sense for me to use really fast microcontrollers to slow them down, using python, to the level of the first generation arduinos. I thing that is the reason, why the original micropython board uses a STM32F405 running at 120MHz and a STM32F407 board runs with 168MHz. It may also be possible that I'm still to old to understand this nonsense. The time that I have learnt to program is long gone now, but I use the very first two programming languages a lot until today. These are Assembler and Pascal. Then I've learned C/C++ programming for Applications on microcontrollers and PC's. The goal was allways to write the fastest running code. Mostly real ugly code. But the only way to the jobs done and many critical realtime problems to solve. Micropython/ Python isn't something that can be used to solve critical realtime problems. I don't like Python. And the hype that made around Python doesn't change my mind. That leads to the conclusion, that as long as there is no usefull development environment for C/C++ I don't see any need for a Pi pico.
We had this discussion in my video about MicroPython. I think there are two ways to look at it: To preserve (cheap processor time) or to protext (expensive) programmer's time. The size of the series decides which is cheaper...
@@AndreasSpiess It is counter intuitive. It also works for accesing the mass storage mode without disconnecting the USB, assert RUN low, hold the button, release RUN. I don't feel like a lot of people know this, would you put a short video about it?
@@AndreasSpiess I did now, the whole thing resets. Edit: according to RP2040's datasheet: "The chip-level reset subsystem resets the whole chip, placing it in a default state. This happens at initial power-on, during a power supply brown-out event or when the chip’s RUN pin is taken low. "
The Raspberry Foundation will make a SWD Debugger to run on one core, to debug the second. This was mentioned on "The Amphour" podcast. Maybe the will be even a Segger implementation one day 😊
I would already be glad if we could stop and single step the Python program as with the Raspberry Pi... One core for debugging, one core for the button, and one core for the execution? We already run out of cores ;-)
Dear Mr. Spiess, I really like your videos and I wondered since you review so many different boards, if you have ever come accross the M5 Stick C. This ESP32 powered board costs 10 Dollars and comed with so many things installed it's amazing. Battery, LCD Display, Gyroscope, Microphone, 3 Buttons, a grove board and a few GPIO pins. I would love if you could tell me what you think of this board. Greetings from Austria!
at least we have some innovative people here, I wish more engineers are like you and well done, problems can be solved easily with a bit of innovation instead of complaining
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
Great as always Andreas. I do have to say I really dislike the use of interpreted languages(python) on embedded systems since it is such a waste of processing power compared to compiled languages(C/C++). It does however open up the world to people that would otherwise not be able use these products at all. I have worked with RTOSs for over 30 years and remember people getting fired for using blocking functions such as delay loops, sleep, pause, etc instead of interrupts/message queues. Nice to see you re-introducing this concept to the next generation.
We had this discussion in my video about MicroPython. I predict that high level languages will take over in the next few years for prototype projects where programmer's time is much more expensive than processing time. RTOS are still a very good thing and for me also a "higher level" language where the programmer does not control everything. And you are right: They allow a very different programming style.
Also, it's good for many hobbyists who just create fun trash stuff like me. In such projects, speed often doesn't matter, but the fun and convenient process of development does. I used to program Arduino a lot, but RP Pico is a lot more fun for me.
A bit late to the show, but if you see this: - Could you add info on how the Interrupt timing would change using Arduino C++ on the PIco ? - Is threading possible in Arduino C++ ? I did not get that from the video, maybe I overheard it.
Just a bit of info: I want to program a "simple" software LockIn-Amplifier on a Pico. The Interrupts or DMA would be useful to get the phase of the reference signal, but 55us would limit the frequency and accuracy considerably.
@@AndreasSpiess Ah, too bad, but understandable. Found one of the answers: you can program both cores on the Arduino IDE using "setup1" and "loop1" for the second core.
When you made this video, I was miles away from securing a job in engineering. No degree, no money, self-study. A year later, Mr. Spiess set me on a journey with the pico that allowed me to secure a job as an RF Technician (en route to engineering position) for municipal districts and emergency service radios. Thank you for all the immensely valuable information and education and it is not for granted!
@@AndreasSpiess Hello sir, I am trying to use PIO to measure the timing between two rising edges on two input pins, but have trouble getting the accurate measurement. Whats the best approach I should go with. I need it at least 400ns accuracy. Thanks
Did someone eventually make the pulse counter PIO? I want to read the LMT01 digital temperature sensor but the interrupts are too slow. I also hard-wired it to GP22 so that's a PWM-A pin. Otherwise I could have used it as a PWM clock input pin. My only hope is PIO at this point.
Andreas!!! Lovely video as *ALWAYS!!* After this video you TRIGGERED me to wish that you eventually make a C++ video for Raspberry Pico, please!!!!!!! Thank you for all your hard work.
Another great video Andreas, A little favour, could you or any of your followers reply with a link for an add on board that would support 5 or more cheap 433 MHz key fobs, it's for a gate control project. Yes I know I can use wi-fi and will, but split arse can't be bothered to get her phone out.
@@AndreasSpiess yes, I’ve got code working cleanly using uasyncio on the Pico. I’m now, after watching this video, very interested in adding in _threads and seeing how they all work together. Fun times! (PS: great video).
@@AndreasSpiess it'll be great :p take care with interrupts. They come with a warning not only in MicroPython but in lots of general programing. You want the interrupt itself to be as short as possible, get the data you need into memory only, then return to the main code to actually use it. docs.micropython.org/en/latest/reference/isr_rules.html docs.micropython.org/en/latest/reference/isr_rules.html
Diska doesn't look very interested in the Pi.. Thanks for bring me to the 99 percentile of Pi Pico programming. However, still haven't seen the killer functionality of it compared to esp32 but maybe with time :)
I would not say we are at 99% of programming. We are only know more than 99% of the programmers. I assume we can learn many new things in the future...
The Pico is designed for streamlined education. It's easier for the Pi foundation to produce and distribute educational material for microcontrollers (like that MicroPython book) when they also control the Chip and the Board, rather than when they have to depend on Chinese ESP32 manufacturers. I'd still say the Pico could outperform the Teensy on a bang for buck basis in certain applications with the right C++ programming.
You do not need the reset button. Just press Ctrl+D and it will reboot Use help in repl to see more shortcuts. Python is made for automation, leave manual resetting for arduino :)
@@AndreasSpiess I tried it with _thread with no problem. You need to terminate the running program with Ctrl+C before. I also found that you don't need bootsel button nether. You can just stop a program by Ctrl+C to access repl, and then type: from machine import bootloader bootloader()
Thank you! In reality, it looks like a castrated version of capabilities available with ESP32 Multicore programming. But on another hand, ESP32 runs full blown FreeRTOS, at the same time Pico is limitted to MicroPython capabilities and limitations. Also, I believe threads work faster on ESP32 because of the native code implementation vs interpreted byte-code of MicroPython for Pico. It's interesting to compare native Pico C/C++ library threads vs ESP32. According to official documentation datasheets.raspberrypi.org/pico/raspberry-pi-pico-c-sdk.pdf it's already implemented, just check 2.8. Multi-core support .
Quality content as always. - And not a mix-up of examples from the book, another unboxing, introduction etc. - He sets the bar high for other UA-camrs. Thank you!
I think, the reset button is missing, because the board uses on-chip USB to flash program. Resetting would "break" USB connection, so you would have to unplug and plug the cable to renew the connection anyway.
I really like the quality of your explanations. Great visualization and you show the examples very detailed. Thanks for enlightening me so often. I am still pretty new to the topic, but I had lots of fun so far.
Even though, micropython is slower than c++, there are ways to make it faster. Decorators like @micropython.native require almost no changes in code, @micropython.viper requires a strictly typed code and you can also compile native c modules to .mpy and add run them in micropython, or even go for assembly level with @micropython.asm_thumb. I had experience only with esp boards, so I'm not sure what of these features are available with Pi Pico and ARM cpu.
Good info. I knew from Scott from Adafruit that he codes a lot of critical functions in C++. But I did not know how to do it. If you are good in that respect I would be glad to have a chat with you. Maybe you contact me on Twitter or Facebook messenger?
Thank you Andreas, I have been looking for these topics on the Pi Pico and now you provided them in a excellent manner. This is great stuff! Now I only have to find out how to use the Pi Pico as an I2C slave device. I can easily find info on how to use it as master, but nothing on how to use it as a slave. Could you be persuaded to look into this, I think it will be highly appreciated by many people using the Pi Pico:-)
Your video on the ATTiny85 controlled array of ultrasonic sensors communicating over I2C was excellent, and I learned a great deal from it. And you made it look relatively easy, so I began to think that I was missing something since I couldn't find anything on the Pi Pico as an I2C slave device. Is it really that different from the usage as a master? From my perspective the main diffrence is that slave devices have to have an address assigned, the rest is "just" sending and receiving - but I've never made an I2C library, so of course I wouldn't know the gory details.
Andreas, have you ever applied this tech to sailing? Seems to be a natural use, where the sailing community can set up spontaneous networks at anchor and perhaps even at sea.
I must say, the esphome framework has made me pretty "lazy". The only time I need to deviate from it into C(++) on my ESP devices is when it comes to deep sleep stuff. If they had a "do task and then sleep for x function" I'd be set.....
I am a retired software engineer and seen enough about Python to know I want nothing to do with it, heck I would be more interested in old fashioned Basic. So I don't suppose you have a similar video in C or C++. I recently got some Seeed Xiao RP2040's which is the reason I started watching the video.
As usual a great video with excellent resource links. The Getting started book is worth five pounds, whatever that is in dollars. Threads and interrupts were explained so that mere mortals can grasp it. Keep broadcasting!!
The weekend I was looking into C++ programming of the Pico and found your example interesting for quick testing a project. C++ is a total overkill for 99% of most projects. But industrial applications may be time critical.
Python on a microcontroller uggghhhhhh... Massive memory footprint and not very battery friendly because it’s interpreted, which comes with a lot of cycle overhead. I’d rather code this in C/C++ or even assembler. I assume it’s ARM assembler being a raspberry (or is it some sort of Atmel?)
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.
Hey, just as a head's up to people using the ESP-32 and Micropython, while many versions of the ESP-32 are dual core, Micropython only runs on one of them and reserves the other to perform peripheral tasks such as managing wifi without it interrupting the main micropython core. This is true even if you are creating multiple threads! So be aware that even though you're getting true preemptive multitasking in multiple threads, all of those threads still run on a single core. For evidence, look in the ports/esp32/mpthreadport.c and you'll see that all tasks/threads are bound to the same MP_TASK_COREID constant.
Nice work! Could you help me? Chinese calliper data reading pi pico micropyton is the few lines of code that do this! Unfortunately, I couldn't find a sample example of such a thing anywhere!
Micropython on the ESP32 supports multiple threads, there is no documentation to the contrary as I just tested on my ESP32 TTG0 board to verify. And to answer the question whether I was paid well in Switzerland, every time I made a deposit at my local Zurich Volks Bank, the teller would remark, "Mr. Schlemowitz, I see your account is doing very well'. Sadly, when my assignment ended and I went to withdraw my money I was told that I could only withdraw twenty percent at a time. I got so pissed off I left my money there. That bank was subsequently sold to another larger bank and yet again to another larger bank until finally it was purchased by Credit Suisse who coincidentally by that time was my employer as I was in charge of IT support for the derivatives desk at the New York City branch. On my last trip to Zurich Switzerland, late 90's, on an assignment for Credit Suisse I dipped into my now CS account to take a quick side trip to Venice just after Carnival. Which reminds me, Schöni Fasnacht !! A memorable evening I will never forget is the last night of Fasnacht which I only discovered by accident after finishing dinner at a restaurant in the Niederdorf and going downstairs to the bar to find a medley of costumed bands taking turns playing and then from there to other bars until finally at the end of the night when all the bars had closed to a final convocation of bands in a small park square, dancing and playing.
No reset button to save the couple of cents and also encourage you to buy an up market (read more expensive) board. That's the only way the suppliers can afford to support the RP2040, upselling to their own higher margin board. Cunning marketing.
I find the treatment of global/local variables in Python intensely annoying and a sure cause of programming faults (one of several things I don't like about Python). When programming in c/c++ and declaring variables I always use a naming standard that distinguishes between their scope. It isn't functional of course, but it makes the code unambiguous as to what I'm dealing with. I should add what's really required to use something as sophisticated as the Pi Pico in complex applications is a real time OS. I'm not familiar with FreeRTOS, but I do like the idea of a proper framework for things like pre-emptive multi-tasking, driving devices, semaphores, message passing and so on. Many years ago I wrote the core of such a thing running on a Z80 machine which controlled the timing on a race track. It drove a number of displays, a couple of printers, car identifiers, timing beams, control lights and so on. I found the framework of being able to write several task that had to run concurrently, some of high priority (like handling timing) and some of lower priority (like driving a printer), and the operator interface to make the whole thing a lot more logical to put together. I find those stereotypical controller programs which comprise a large loop handling device status and also handling any user interface to be painful and illogical. So something that encourages proper multi-tasking is great, even if you have to, sort of, DIY it as here. I should add that there is lots of potential for "gotchas" in complex applications which require co-ordinating of multiple tasks without tripping one another up. There's a whole lot that could be presented about how to do more complex applications.
Hey Andreas I love your videos, always with interesting information, and thanks for add spanish subtitles, It allows me to share your videos with my studends. Greetings from México
One thing I am curious on with the Pico, is how fast can it handle external interrupts? Or, basically, how fast can it read pin changes? Say I want to use the Pico to drive a 4 MHz CPU (6502), is the Pico fast enough to act as RAM for that CPU? I was wondering if one core could simply read the pins while the other core handles internal stuff.
The M0 cores of the pico are not the fastest. If you need speed you probably have to go a different route. 4MHz clock with bit-banging is quite fast...
"time is money" micro python - ~55us c++ ~ 3us lets think c++ is 3x more time consuming than micro python for development tasks 55/3 = 18 time is real money... cheap things don't come for free😀
Seems to me a good way to use the 2 processors is to have one only doing the communication protocols (wifi, serial port if needed), and use the other one to run the main program. Does that make sense to you? BTW, the PIO is much faster with I/O, so i would use that for a pulse counter.
It is common place to name a group based on what it's in, not what it's not in. So based on this your use of "the 95% club" and "the 99% club" would commonly be referred to as "the 5% club" and "the 1% club" respectively. It's not a rule, just a common standard so you are not wrong, just going against the flow so to speak 🙂
Where in the documentation did you found that multithreading is implemented using multicore ? The MicroPython documentation regarding threads is quite minimalist and point to the CPython page, which does not speak about cores... Beside MicroPython also run on single core platform... Thanks
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
You are right. But currently, the Pico is not supported by the Arduino IDE. And I like MicroPython because it is fast for programming (as said in the video). But it is slower at execution. So if somebody wants to start with a project it is good to know how much slower and when to chose C++. The C++ benchmarks done by a viewer are in the pinned comment, if you are interested. And they are of course much faster.
One weakness of the ESP32 with Arduino C++ is it cannot be a slave_receiver/slave_sender in an I2c 'Wire'' communications setup. Does the Pico have that capability ?
As an old programmer, I learned long ago that non-compiled programs, aka interpretted, are always slower and more bloated. You are not going to catch me doing python on one of these little processors.
Maybe our sons or daughters will use it. It is the natural way. I used punch cards, then assembler, then PLM and C. The next step will be a higher language...
Very interesting video, thank you. I don't really understand why you would ever want to use python on a micro. I see many videos on youtube about micro python but I don't really see what it enables you to do that is better than C/C++. For sure I see Python as extremely useful on a PC when it enables fast development of complex custom calculations with minimal coding knowledge but I can't see how that translates to anything very useful on a small micro. I wonder if micro python is just a curiosity or if it has real value.
Python is easier to use for a lot of people and has some advantages over C++ like String handing. Another advantage is that you only need to learn one language if you work on the PC/Raspberry and on micros. Back in the day C++ was like Python today: More productivity vor programmers who used assembler. Now Python promises more productivity for programmers who use C++. We will see if it becomes true...
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
I hope you also heard the advantages like faster programming for prototypes. But it is important to know the limitations before you start a project. Otherwise you loose a lot of time.
Please don't teach people to use global variables. It opens up so many problems down the road, especially when dealing with threads. Also, why not stick to conventional coding terms like mutable, mutex, singelton pattern etc. Why use "baton"?
You are right. I assume things are a little different with this implementation of Microopython. Otherwise I would not understand the Pi foundation to print the example in their book. But at least I added the proper method and also called it "professional"...
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.
Agreed for many mechanical systems. The needed sample time of sensors and speed of PID controllers depend of course of the eigenfrequency of the system. For some systems they have to be quite fast.
The ESP32 and the STM32 would run just as fast as the PiPico if they did not run a compiled code as that is not a fair comparison between Arduino C++ and Micropython as both are pretty much the same uncompiled to any processor
We all know that, I think from my other videos. But if I have to decide if I can use MicroPython for a particular project I need to know how fast it is. You find the result using c++ in the pinned comment.
I can at *least* help with the USB connection. Go to Amazon, and look for Wsken magnetic cables and connectors. They do data transfer, too. Plug the connector into the Pico, plug the other end into the Pi, and then, no more yanking out a micro USB connector. Just be careful not to smack the connector loose.
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...
on the pico pi , ctrl D will perform a soft reboot. and if you place a button between Ground and Run pin, it works to program like on the esp8266 and the 32.
Multi threading in this way is not working properly in Pi Pico. It seems that the second thread is sharing the CPU time with the main thread, so the main thread will be slower 50% than before. Any idea?
The Commodore VC20 anc C-64 didn't feature a reset button either. I earned a little money in the 1980s selling reset buttons to my friends and classmates which were assembled inside an empty DIN-connector shell which could be plugged into the serial connector of the 1541 floppy drive.... So the Pi-team are not the first to "forget" the reset button.
Pico reset: you wire the GND and RUN pins together and add an extra momentary contact button to your breadboard. Pushing the button will reset the board.
Looks like the RUN pin is actually the reset input. Use a push to make switch on this pin to ground to reset. Has an internal pull up. First time I've ever seen a reset pin called RUN.
Why can you reprogram atmel and esp chips without using the reset button or power cycling, but not stm or pico? Would using an external serial chip fix this?
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.
To add a bit more to my last comment, I did a some more investigation and it appears that the minimum execution time of a GPIO interrupt handler is 5 us (i.e. even if it does nothing) which seems like an awful lot of overhead. I searched the data sheet for the processor and the SDK documentation and source code but could find no explanation for this behaviour. Probably someone more familiar with the ARM processor architecture will know. Cheers!
Thank you for testing it. This seems to be ok. Of the 1.3 us of the STM32, about half was to set the pin (Arduino is not very fast in this discipline)
@@RocketManRC-Electronics How did you measure the execution time of the isr?
Micropython seems to have a "hard = true" option when assigning an IRQ to a pin. Maybe this would also make it a bit faster. Maybe I might try this someday....
docs.micropython.org/en/latest/library/machine.Pin.html
@@rianderous8761 python will always be slower as it needs an interpreter to run.
The cat says: "no more interrupts".
:-))
shorting the pico's RUN pin to ground causes a hardware reset, it's a pity that there isn't a built in reset button, but adding one isn't too hard
You are right. I still think it should not be the task of the buyer...
@@AndreasSpiess Reset buttons are also a danger. I've pressed them inadvertently too many times. You could pull the other end of the usb cable to spare the soldered on connector.
(Great content and presentation by the way! And that's a cool cat :))
I got so annoyed with having to do this when working on MCU breakout boards, I made a small PCB pass-through board with a gang switch on it to break all USB connections. A small but very nice quality of life improvement.
I’m not entirely sure, but BenHeck I believe did some magic with the onboard button and a single wire to act as a reset.
You don't even need a button.
Just connect a Wire from ground to the RUN pin, and you reser the device.
I think you need to add that, so we Will stop this nonsens with pulling the USB-cable to reset the device.
Just ground RUN pin on the device!
Nothing like your weekly dosage of your guy with the swiss accent. :)
:-)
If you're afraid of wearing out the connector you can always try unplugging the other end of the cable ;-)
You are right. Theoretically. I used a Raspberry pi with an SSD Ethernet, HDMI, and a mouse. Not really convenient to unplug it there...
@@AndreasSpiess I would use one of those usb cord with an inline power switch in that case.
@@VisDeuxMany of those are power only, not data, Finding a data cable with a switch is hard
@@DinoFancellu make your own?
The easy answer is to use a simple usb extension and pull it there
you can reset the pico by connecting the "run" pin to ground.
You are right. This is what I do now.
Two 32-bit core running at 1330 x faster than the Apollo 15bit guidance computer.
1960s Apollo engineer: what are you using this awesome power for?
Maker: I make LED go on and off!
Apollo engineer: wtf 🙄
Exactly. But the engineer also started small, I assume ;-)
Ok that's the most adorable snoring cat on the internet. I will become a Patreon now just so you can give her more treats.
Thank you! Indeed, she is very good in snoring!
freeRTOS !! Yea, I just started reading the official docs last week. Half way through mastering freeRTOS already. Cool stuff in there. These topics will advance/enhance our lives 4 sure
True! But we have to change our programming styles a little...
@@AndreasSpiess and changing programming style from Arduino are just fine, and Good.
Agreed, a reset button is important on any board that will go through many development cycles. It's not just about resetting when it locks up, but also about watching what happens when it is powered up. Yes, there are ways of doing it by button, but 5p extra for a reset button is something I'd happily pay. That said, leave the button off but put pads on the board for me to add it.
I agree. Pads would have been a good alternative. I solved the problem differently (in another video)
This is super helpful. I might use C++ instead for my project if the SNES clock/latch pin is too fast for my project. I hope so, because then i might be able to get away with using 0 shift registers instead of 2 per emulated controller
Glad you found the content useful!
Twist: now that we have watched the video as all pico users do, we are no more in the 99% club. Because Andreas educated *all* pico users. The 99% already know about interrupts, two cores etc 😎
Hurry up if you want to be in the 1%-range (for a second).
Interesting point of view. Maybe a topic for a PhD work for a a budding epidemiologist ;-)
This is a great presentation. Lots of good information to use when I can get my hands on a supply of these boards. The only ones currently available in the US are from scalpers charging 3 times or more than companies taking back orders. Perhaps I'll just have to suck it up and wait until March 17 when legitimate orders are fulfilled at a reasonable price. I think there will be a version at some point with WIFI and Blue Tooth to compete with the Esp-32 if the price is comparable. I hope you have a great day.
We will see if they are able to add WiFi. This seems not so easy...
@@AndreasSpiess I would settle for LoRa over wifi. It would be nice to read sensor data over a distance. In fact I think LoRa would be more useful anyway.
Well, a WiFi version just came out 2 days ago, not sure if they will make a Bluetooth one too
@@kosmasraptis8374 I saw that it was available, unfortunately they will only let you buy 1 and I want 10. I guess I can suck it up and buy just one. I just hate to pay huge shipping charges on something that cost 6 dollars..I already have a project in mind so I might as well buy the one before they are all gone. The device is technically bluetooth ready but it's not currently activated.
@@rickhunt3183 Perhaps you can get a Bluetooth shield for that
What is the issue with the RESET? Since you're already connecting external components to it, you might as well add a tactile button between GND and pin 30 (confusingly called RUN) to reset the chip.
I know and I did it, of course. But is this my job in 2021?
@@AndreasSpiess That wasn't quite clear from the video or I missed it. I can totally understand why they haven't added one; if you're a maker and hooking up external components on a breadboard anyway you might as well add a reset button (the pullup is already there) if you need it but if you're integrating the board on your own circuits you may not have a need for it or it could potentially be in the way if you don't want users to fool around with it (I certainly have removed reset buttons in the past). Either way I think it is fine as is and just wasn't sure whether you knew about the exposed NRST pad...
Nice ...you have the Rasta colors on your lights :)
:-)
waiting for your RTOS videos!
Coming soon!
Amazing as always! Thank you. Kisses to your cat from my cat!
You are welcome. I will tell her...
We all know who is the star of the show.
Your professional approach just made the two cores act like a single core. The problem with locks is called deadlock, where the key or keys are not released and the thread process dies. If you want the software to safe all passing of variables needs to be atomic, as in a single atomic particle. If you have to read, modify and write to global variable you would place a lock around it so three actions become the same as one atomic action. So the variable cant be changed by another thread while its being worked on. With deadlocks the reset may be your only friend.
You are right. We will talk about that in my RTOS video. I think, here, the firmware takes care of the blocking. But still, I needed a reset button from time-to-time...
@@AndreasSpiess if you deadlock without an RTOS your are dead in the water. only a reset will get you going.
Python on microcontrollers is a nice idea for absolut beginners and nontechnitions. It makes no sense for me to use really fast microcontrollers to slow them down, using python, to the level of the first generation arduinos. I thing that is the reason, why the original micropython board uses a STM32F405 running at 120MHz and a STM32F407 board runs with 168MHz. It may also be possible that I'm still to old to understand this nonsense. The time that I have learnt to program is long gone now, but I use the very first two programming languages a lot until today. These are Assembler and Pascal. Then I've learned C/C++ programming for Applications on microcontrollers and PC's. The goal was allways to write the fastest running code. Mostly real ugly code. But the only way to the jobs done and many critical realtime problems to solve. Micropython/ Python isn't something that can be used to solve critical realtime problems. I don't like Python. And the hype that made around Python doesn't change my mind.
That leads to the conclusion, that as long as there is no usefull development environment for C/C++ I don't see any need for a Pi pico.
We had this discussion in my video about MicroPython. I think there are two ways to look at it: To preserve (cheap processor time) or to protext (expensive) programmer's time. The size of the series decides which is cheaper...
The reset pin is the pin 30, is labeled "run", pull it down for reset.
Thanks for the tip. I already have my reset pin. But a beginner?
@@AndreasSpiess It is counter intuitive.
It also works for accesing the mass storage mode without disconnecting the USB, assert RUN low, hold the button, release RUN. I don't feel like a lot of people know this, would you put a short video about it?
Did you try with two cores?
@@AndreasSpiess I did now, the whole thing resets.
Edit: according to RP2040's datasheet: "The chip-level reset subsystem resets the whole chip, placing it in a default state. This happens at initial power-on, during
a power supply brown-out event or when the chip’s RUN pin is taken low. "
I tried it too now. I did not see a difference if I pressed the reset together with the boot button or not. It always resets.
The Raspberry Foundation will make a SWD Debugger to run on one core, to debug the second. This was mentioned on "The Amphour" podcast.
Maybe the will be even a Segger implementation one day 😊
I would already be glad if we could stop and single step the Python program as with the Raspberry Pi... One core for debugging, one core for the button, and one core for the execution? We already run out of cores ;-)
I came here for my daily fix of Cute Cat Clips. I wasn't disappointed. Now, where can I find some footage of men with Swiss accents? Oh... wait..
:-))
Dear Mr. Spiess, I really like your videos and I wondered since you review so many different boards, if you have ever come accross the M5 Stick C.
This ESP32 powered board costs 10 Dollars and comed with so many things installed it's amazing.
Battery, LCD Display, Gyroscope, Microphone, 3 Buttons, a grove board and a few GPIO pins.
I would love if you could tell me what you think of this board.
Greetings from Austria!
I made myself a cable with a reset button. Works for every mcu =)
at least we have some innovative people here, I wish more engineers are like you and well done, problems can be solved easily with a bit of innovation instead of complaining
I soldered a fitting button across the two pins. But is this my task in 2021?
@@AndreasSpiess A great innovative and engineering task accomplished, well
done : )
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
Cool, thanks!
Great as always Andreas. I do have to say I really dislike the use of interpreted languages(python) on embedded systems since it is such a waste of processing power compared to compiled languages(C/C++). It does however open up the world to people that would otherwise not be able use these products at all. I have worked with RTOSs for over 30 years and remember people getting fired for using blocking functions such as delay loops, sleep, pause, etc instead of interrupts/message queues. Nice to see you re-introducing this concept to the next generation.
We had this discussion in my video about MicroPython. I predict that high level languages will take over in the next few years for prototype projects where programmer's time is much more expensive than processing time.
RTOS are still a very good thing and for me also a "higher level" language where the programmer does not control everything. And you are right: They allow a very different programming style.
Also, it's good for many hobbyists who just create fun trash stuff like me. In such projects, speed often doesn't matter, but the fun and convenient process of development does. I used to program Arduino a lot, but RP Pico is a lot more fun for me.
Hi Andreas! I learned a lot from you. Thank you for elevating us to the top 1%!
Welcome in the club ;-)
A bit late to the show, but if you see this:
- Could you add info on how the Interrupt timing would change using Arduino C++ on the PIco ?
- Is threading possible in Arduino C++ ? I did not get that from the video, maybe I overheard it.
Just a bit of info:
I want to program a "simple" software LockIn-Amplifier on a Pico. The Interrupts or DMA would be useful to get the phase of the reference signal, but 55us would limit the frequency and accuracy considerably.
The Pico did not get a lot of traction in my viewer community. So I stopped covering this chip :-(
@@AndreasSpiess Ah, too bad, but understandable.
Found one of the answers: you can program both cores on the Arduino IDE using "setup1" and "loop1" for the second core.
When you made this video, I was miles away from securing a job in engineering. No degree, no money, self-study. A year later, Mr. Spiess set me on a journey with the pico that allowed me to secure a job as an RF Technician (en route to engineering position) for municipal districts and emergency service radios. Thank you for all the immensely valuable information and education and it is not for granted!
Congratulations! I am always happy if I can be of help for somebody.
@@AndreasSpiess
Hello sir,
I am trying to use PIO to measure the timing between two rising edges on two input pins, but have trouble getting the accurate measurement. Whats the best approach I should go with. I need it at least 400ns accuracy.
Thanks
@@yeanic I never used the PIO functionality 😞
Did someone eventually make the pulse counter PIO? I want to read the LMT01 digital temperature sensor but the interrupts are too slow. I also hard-wired it to GP22 so that's a PWM-A pin. Otherwise I could have used it as a PWM clock input pin. My only hope is PIO at this point.
I do not know. Yes, 88kHz is probably quite fast for an interrupt. Should be possible with the PIO.
You can add a reset button (shop.pimoroni.com/products/captain-resetti-pico-reset-button), or simply wire a button between the GND & RUN yourself.
Thanks for the link. For half the price of the board? I found a cheaper solution ;-)
Andreas!!! Lovely video as *ALWAYS!!* After this video you TRIGGERED me to wish that you eventually make a C++ video for Raspberry Pico, please!!!!!!! Thank you for all your hard work.
I wait till it is supported by the Arduino IDE.
Oh thanks! I want this board and work with c++. Have a lot of potential!
You can do that already now.
@@AndreasSpiess of course! I just need to buy it 🤣 I'm from Colombia
Another great video Andreas, A little favour, could you or any of your followers reply with a link for an add on board that would support 5 or more cheap 433 MHz key fobs, it's for a gate control project. Yes I know I can use wi-fi and will, but split arse can't be bothered to get her phone out.
Thank you.
You find plenty of such 433MHz videos, I think. Probably not for the Pico, but you can port it if it is important for you.
A video about uasyncio/asyncio for (single core) multitasking would also be useful to many users in my opinion.
Is it available on Micropython?
@@AndreasSpiess Yes. :-D Have a look at the uasyncio module.
@@AndreasSpiess yes, I’ve got code working cleanly using uasyncio on the Pico. I’m now, after watching this video, very interested in adding in _threads and seeing how they all work together. Fun times! (PS: great video).
I will have a look at it.
MicroPython is awesome - it's the future for us hobbyist and makers. Can you do Asyncio next?
We will see how things go with Micropython...
@@AndreasSpiess it'll be great :p take care with interrupts. They come with a warning not only in MicroPython but in lots of general programing. You want the interrupt itself to be as short as possible, get the data you need into memory only, then return to the main code to actually use it.
docs.micropython.org/en/latest/reference/isr_rules.html docs.micropython.org/en/latest/reference/isr_rules.html
Thank you for the link.
Diska doesn't look very interested in the Pi.. Thanks for bring me to the 99 percentile of Pi Pico programming. However, still haven't seen the killer functionality of it compared to esp32 but maybe with time :)
I would not say we are at 99% of programming. We are only know more than 99% of the programmers. I assume we can learn many new things in the future...
The Pico is designed for streamlined education. It's easier for the Pi foundation to produce and distribute educational material for microcontrollers (like that MicroPython book) when they also control the Chip and the Board, rather than when they have to depend on Chinese ESP32 manufacturers. I'd still say the Pico could outperform the Teensy on a bang for buck basis in certain applications with the right C++ programming.
Thanks Andreas. Being that old (the cat obviously ;-) snoring is allowed.
Also for the owner, if he has a separate room ;-)
@@AndreasSpiess 😂
You do not need the reset button.
Just press Ctrl+D and it will reboot
Use help in repl to see more shortcuts.
Python is made for automation, leave manual resetting for arduino :)
Unfortunately not :-( I tried.
@@AndreasSpiess It is working for me :(
Did you try the dual core stuff? Only there it did not work (with this "core1 busy" message).
@@AndreasSpiess No, I didn't. For now uasyncio module was enough for my needs.
@@AndreasSpiess I tried it with _thread with no problem. You need to terminate the running program with Ctrl+C before. I also found that you don't need bootsel button nether. You can just stop a program by Ctrl+C to access repl, and then type:
from machine import bootloader
bootloader()
Thank you! In reality, it looks like a castrated version of capabilities available with ESP32 Multicore programming. But on another hand, ESP32 runs full blown FreeRTOS, at the same time Pico is limitted to MicroPython capabilities and limitations. Also, I believe threads work faster on ESP32 because of the native code implementation vs interpreted byte-code of MicroPython for Pico. It's interesting to compare native Pico C/C++ library threads vs ESP32. According to official documentation datasheets.raspberrypi.org/pico/raspberry-pi-pico-c-sdk.pdf it's already implemented, just check 2.8. Multi-core support
.
I wait for the Arduino support before I will use C++ on the Pico
@@AndreasSpiess Well a real RT os would be useful I recall doing this using RT-11 on DEC PDP's in 1980 or so in this case Fortan 66
Quality content as always. - And not a mix-up of examples from the book, another unboxing, introduction etc. - He sets the bar high for other UA-camrs. Thank you!
You are welcome!
I think, the reset button is missing, because the board uses on-chip USB to flash program. Resetting would "break" USB connection, so you would have to unplug and plug the cable to renew the connection anyway.
You do not need to unplug the USB after reboot. At least not with MicroPython.
@@AndreasSpiess Ok, my thoughts were based on experience with STM32 (not MicroPython, but C and SWDIO).
Please write "Python" in the title so I wont waste time clicking the vid.
I understand your point. But at that point, the Pico was only MicroPython.
I really like the quality of your explanations. Great visualization and you show the examples very detailed. Thanks for enlightening me so often. I am still pretty new to the topic, but I had lots of fun so far.
Glad it was helpful! And welcome aboard the channel!
Even though, micropython is slower than c++, there are ways to make it faster. Decorators like @micropython.native require almost no changes in code, @micropython.viper requires a strictly typed code and you can also compile native c modules to .mpy and add run them in micropython, or even go for assembly level with @micropython.asm_thumb. I had experience only with esp boards, so I'm not sure what of these features are available with Pi Pico and ARM cpu.
Good info. I knew from Scott from Adafruit that he codes a lot of critical functions in C++. But I did not know how to do it. If you are good in that respect I would be glad to have a chat with you. Maybe you contact me on Twitter or Facebook messenger?
Thank you Andreas, I have been looking for these topics on the Pi Pico and now you provided them in a excellent manner.
This is great stuff!
Now I only have to find out how to use the Pi Pico as an I2C slave device. I can easily find info on how to use it as master, but nothing on how to use it as a slave.
Could you be persuaded to look into this, I think it will be highly appreciated by many people using the Pi Pico:-)
I2C slave is not easy and it tool a while till I found it out for the ATTiny back in the day. In addition, here we need it for Micropython...
Your video on the ATTiny85 controlled array of ultrasonic sensors communicating over I2C was excellent, and I learned a great deal from it. And you made it look relatively easy, so I began to think that I was missing something since I couldn't find anything on the Pi Pico as an I2C slave device.
Is it really that different from the usage as a master? From my perspective the main diffrence is that slave devices have to have an address assigned, the rest is "just" sending and receiving - but I've never made an I2C library, so of course I wouldn't know the gory details.
I do not know if it was difficult. Maybe somebody with the knowledge should create it.
Andreas, have you ever applied this tech to sailing? Seems to be a natural use, where the sailing community can set up spontaneous networks at anchor and perhaps even at sea.
It is possible to add a physical reset button for programing it Ben Heck has done it in the video
ua-cam.com/video/il4bgA76E1M/v-deo.html
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
I wait till it is supported by the Arduino IDE. 73 de HB9BLA
I must say, the esphome framework has made me pretty "lazy".
The only time I need to deviate from it into C(++) on my ESP devices is when it comes to deep sleep stuff.
If they had a "do task and then sleep for x function" I'd be set.....
To bring my comment onto the actual topic at hand, I wonder if/when the rpi pico will be supported in the esphome framework.
We will see. The momentum seems to be quite high. But this can change after the first hype...
I am a retired software engineer and seen enough about Python to know I want nothing to do with it, heck I would be more interested in old fashioned Basic. So I don't suppose you have a similar video in C or C++. I recently got some Seeed Xiao RP2040's which is the reason I started watching the video.
The Pi Pico is now supported by the Arduino IDE. So you can use C++. Google should show you a video by "Gary Explains" (UA-cam does not support links)
You can surely reset the pico by pulling the RUN pin LOW that reset the pico and its written in the manual
You are right. I solved the issue with a tiny button. I still think it should not be the task of the buyer...
@@AndreasSpiess yes you are right its shouldn't be our issue
and thnx for the replay
I love your videos
Grüße aus Deutschland
Now you did it.This video will pump views because of the cat strategy :)
Thank you for staying till the end ;-)
The baton is like a "token "which is used on databuses, it the token=taken then everything else has to wait.
You are right.
Awesome video!!! I put a button between ground and PIN run in pico.
Now I can connect and disconnect using it
I know and I did it. But on a beginners board in 2021?
As usual a great video with excellent resource links. The Getting started book is worth five pounds, whatever that is in dollars. Threads and interrupts were explained so that mere mortals can grasp it. Keep broadcasting!!
I agree. The foundation does a good job documenting their products.
It's not this time that you will find the Saint Andreas Fault, Das ist ganz perfekt!
The weekend I was looking into C++ programming of the Pico and found your example interesting for quick testing a project. C++ is a total overkill for 99% of most projects. But industrial applications may be time critical.
I think, MicroPython is great for prototyping. Creating teh two core synchronization example in C++ is much harder, for example.
using both cores from the Arduino IDE
#include "pico/multicore.h"
static mutex_t TheMutex;
void Core_1_test()
{
while(true)
{
mutex_enter_blocking(&TheMutex);
Serial.println(">");
delay(5000);
mutex_exit(&TheMutex);
}
}
void setup()
{
Serial.begin(115200);
mutex_init(&TheMutex);
multicore_launch_core1(Core_1_test);
delay(5000);
}
void loop()
{
mutex_enter_blocking(&TheMutex);
Serial.println(">>>> Core 0
Thank you for your example code!
Python on a microcontroller uggghhhhhh...
Massive memory footprint and not very battery friendly because it’s interpreted, which comes with a lot of cycle overhead.
I’d rather code this in C/C++ or even assembler. I assume it’s ARM assembler being a raspberry (or is it some sort of Atmel?)
It uses ARM cores.
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.
You are right, this is possible. It is probably a mixture of both: The flag is a global variable and you program the behavior of a mutex.
Hey, just as a head's up to people using the ESP-32 and Micropython, while many versions of the ESP-32 are dual core, Micropython only runs on one of them and reserves the other to perform peripheral tasks such as managing wifi without it interrupting the main micropython core. This is true even if you are creating multiple threads! So be aware that even though you're getting true preemptive multitasking in multiple threads, all of those threads still run on a single core. For evidence, look in the ports/esp32/mpthreadport.c and you'll see that all tasks/threads are bound to the same MP_TASK_COREID constant.
Thank you for the information!
There are few things that warms my heart like a peacefully snoring sleeping cat 💕
:-)
Nice work! Could you help me? Chinese calliper data reading pi pico micropyton is the few lines of code that do this! Unfortunately,
I couldn't find a sample example of such a thing anywhere!
Unfortunately, I do not frequently use MicroPython. So you have to ask somebody else.
Micropython on the ESP32 supports multiple threads, there is no documentation to the contrary as I just tested on my ESP32 TTG0 board to verify. And to answer the question whether I was paid well in Switzerland, every time I made a deposit at my local Zurich Volks Bank, the teller would remark, "Mr. Schlemowitz, I see your account is doing very well'. Sadly, when my assignment ended and I went to withdraw my money I was told that I could only withdraw twenty percent at a time. I got so pissed off I left my money there. That bank was subsequently sold to another larger bank and yet again to another larger bank until finally it was purchased by Credit Suisse who coincidentally by that time was my employer as I was in charge of IT support for the derivatives desk at the New York City branch. On my last trip to Zurich Switzerland, late 90's, on an assignment for Credit Suisse I dipped into my now CS account to take a quick side trip to Venice just after Carnival. Which reminds me, Schöni Fasnacht !! A memorable evening I will never forget is the last night of Fasnacht which I only discovered by accident after finishing dinner at a restaurant in the Niederdorf and going downstairs to the bar to find a medley of costumed bands taking turns playing and then from there to other bars until finally at the end of the night when all the bars had closed to a final convocation of bands in a small park square, dancing and playing.
Unfortunately, we have no "Fasnacht" this year (as last year). Because of Corona :-(
No reset button to save the couple of cents and also encourage you to buy an up market (read more expensive) board. That's the only way the suppliers can afford to support the RP2040, upselling to their own higher margin board. Cunning marketing.
I find the treatment of global/local variables in Python intensely annoying and a sure cause of programming faults (one of several things I don't like about Python). When programming in c/c++ and declaring variables I always use a naming standard that distinguishes between their scope. It isn't functional of course, but it makes the code unambiguous as to what I'm dealing with.
I should add what's really required to use something as sophisticated as the Pi Pico in complex applications is a real time OS. I'm not familiar with FreeRTOS, but I do like the idea of a proper framework for things like pre-emptive multi-tasking, driving devices, semaphores, message passing and so on. Many years ago I wrote the core of such a thing running on a Z80 machine which controlled the timing on a race track. It drove a number of displays, a couple of printers, car identifiers, timing beams, control lights and so on. I found the framework of being able to write several task that had to run concurrently, some of high priority (like handling timing) and some of lower priority (like driving a printer), and the operator interface to make the whole thing a lot more logical to put together. I find those stereotypical controller programs which comprise a large loop handling device status and also handling any user interface to be painful and illogical. So something that encourages proper multi-tasking is great, even if you have to, sort of, DIY it as here.
I should add that there is lots of potential for "gotchas" in complex applications which require co-ordinating of multiple tasks without tripping one another up. There's a whole lot that could be presented about how to do more complex applications.
I made a video about FreeRTOS on the ESP32. It is quite useful for complex applications.
Hey Andreas I love your videos, always with interesting information, and thanks for add spanish subtitles, It allows me to share your videos with my studends. Greetings from México
I do not add the Spanish CCs. It is Luciana, an Argentinean student. I only provide the small fee ;-)
Great video as always Andreas, you made this look quite simple! May I ask you to raise the volume of the audio a bit? Thanks!
I always use the standard for podcasting. But I do not know what UA-cam does with it.
One thing I am curious on with the Pico, is how fast can it handle external interrupts? Or, basically, how fast can it read pin changes? Say I want to use the Pico to drive a 4 MHz CPU (6502), is the Pico fast enough to act as RAM for that CPU? I was wondering if one core could simply read the pins while the other core handles internal stuff.
The M0 cores of the pico are not the fastest. If you need speed you probably have to go a different route. 4MHz clock with bit-banging is quite fast...
"time is money"
micro python - ~55us
c++ ~ 3us
lets think c++ is 3x more time consuming than micro python for development tasks
55/3 = 18
time is real money... cheap things don't come for free😀
My clock rate is way lower, I clock (charge) in hours (but with a quite high price attached to these hours).
Seems to me a good way to use the 2 processors is to have one only doing the communication protocols (wifi, serial port if needed), and use the other one to run the main program.
Does that make sense to you?
BTW, the PIO is much faster with I/O, so i would use that for a pulse counter.
Yes, this makes sense to me.
It is common place to name a group based on what it's in, not what it's not in. So based on this your use of "the 95% club" and "the 99% club" would commonly be referred to as "the 5% club" and "the 1% club" respectively. It's not a rule, just a common standard so you are not wrong, just going against the flow so to speak 🙂
That is ok. I did not think too much about it, I have to admit. 99% club sounded good in my ears ;-)
Where in the documentation did you found that multithreading is implemented using multicore ?
The MicroPython documentation regarding threads is quite minimalist and point to the CPython page, which does not speak about cores...
Beside MicroPython also run on single core platform...
Thanks
I do not remember where I read about it :-(
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
You are right. But currently, the Pico is not supported by the Arduino IDE. And I like MicroPython because it is fast for programming (as said in the video). But it is slower at execution. So if somebody wants to start with a project it is good to know how much slower and when to chose C++.
The C++ benchmarks done by a viewer are in the pinned comment, if you are interested. And they are of course much faster.
One weakness of the ESP32 with Arduino C++ is it cannot be a slave_receiver/slave_sender in an I2c 'Wire'' communications setup. Does the Pico have that capability ?
I do not know.
As an old programmer, I learned long ago that non-compiled programs, aka interpretted, are always slower and more bloated. You are not going to catch me doing python on one of these little processors.
Maybe our sons or daughters will use it. It is the natural way. I used punch cards, then assembler, then PLM and C. The next step will be a higher language...
Very interesting video, thank you. I don't really understand why you would ever want to use python on a micro. I see many videos on youtube about micro python but I don't really see what it enables you to do that is better than C/C++. For sure I see Python as extremely useful on a PC when it enables fast development of complex custom calculations with minimal coding knowledge but I can't see how that translates to anything very useful on a small micro. I wonder if micro python is just a curiosity or if it has real value.
Python is easier to use for a lot of people and has some advantages over C++ like String handing. Another advantage is that you only need to learn one language if you work on the PC/Raspberry and on micros.
Back in the day C++ was like Python today: More productivity vor programmers who used assembler. Now Python promises more productivity for programmers who use C++. We will see if it becomes true...
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
I hope you also heard the advantages like faster programming for prototypes. But it is important to know the limitations before you start a project. Otherwise you loose a lot of time.
one important note, we can use the two cores OF PICO on arduinoIDE earlephilhower's board by simply calling void setup1() and void loop1() .
Thank you for the info!
Please don't teach people to use global variables. It opens up so many problems down the road, especially when dealing with threads. Also, why not stick to conventional coding terms like mutable, mutex, singelton pattern etc. Why use "baton"?
You are right. I assume things are a little different with this implementation of Microopython. Otherwise I would not understand the Pi foundation to print the example in their book. But at least I added the proper method and also called it "professional"...
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.
Agreed for many mechanical systems. The needed sample time of sensors and speed of PID controllers depend of course of the eigenfrequency of the system. For some systems they have to be quite fast.
Fastastic and practical info on the fundamentals of utilizing multiple cores! Your explanations are so clear and concise, thank you!
You're very welcome!
The ESP32 and the STM32 would run just as fast as the PiPico if they did not run a compiled code as that is not a fair comparison between Arduino C++ and Micropython as both are pretty much the same uncompiled to any processor
We all know that, I think from my other videos. But if I have to decide if I can use MicroPython for a particular project I need to know how fast it is. You find the result using c++ in the pinned comment.
Great job with the video as always 👍
Thanks for sharing your knowledge to all of us 👍😊
My pleasure!
I can at *least* help with the USB connection.
Go to Amazon, and look for Wsken magnetic cables and connectors. They do data transfer, too. Plug the connector into the Pico, plug the other end into the Pi, and then, no more yanking out a micro USB connector. Just be careful not to smack the connector loose.
Good idea! Thanks
FWIW, my sparkfun thing plus rp2040 just arrived and I’ve come to appreciate the inclusion of a reset button. :)
Thank you for the update. But we also have to say that it is not 4 dollars ;-)
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...
So far I have no such plans.
on the pico pi , ctrl D will perform a soft reboot. and if you place a button between Ground and Run pin, it works to program like on the esp8266 and the 32.
You are right. I added this button in one of ma next videos ;-)
Your accent does not sound swiss, but something undefined :D Thanks for this Video tho, subbed
Welcome aboard the channel!
Multi threading in this way is not working properly in Pi Pico. It seems that the second thread is sharing the CPU time with the main thread, so the main thread will be slower 50% than before. Any idea?
As the Pico did not catch a lot of traction in the Maker community I do not look too much into it :-(
The Commodore VC20 anc C-64 didn't feature a reset button either. I earned a little money in the 1980s selling reset buttons to my friends and classmates which were assembled inside an empty DIN-connector shell which could be plugged into the serial connector of the 1541 floppy drive.... So the Pi-team are not the first to "forget" the reset button.
Nice story! Like Pimironi now: They charge 2 dollars for the button ;-)
@@AndreasSpiess I know, ... ordered 4 yesterday
And I just published a video about it ;-)
So informative! I have a question: how does this interacts with python's GIL? does micropython have it?
I do not know micropython that well. Maybe Google knows?
Pico reset: you wire the GND and RUN pins together and add an extra momentary contact button to your breadboard. Pushing the button will reset the board.
You are right. I did a similar thing in my next video ;-)
Can't wait for raspberry pi pico Wireless version
Keep an eye on the Arduino Nano RP2040 Connect.
I do not think if will appear soon. What we will see is a Pico and an ESP32 for WiFi from Arduino.
@@AndreasSpiess maybe an topic for the next video. Using an Esp01 as wifi addon for the Pico...
I wait for the code for the -C3...
Looks like the RUN pin is actually the reset input. Use a push to make switch on this pin to ground to reset. Has an internal pull up. First time I've ever seen a reset pin called RUN.
You are right. I added a small switch across RUN and GND.
Why can you reprogram atmel and esp chips without using the reset button or power cycling, but not stm or pico? Would using an external serial chip fix this?
You can program the Pico without a reset button. But if it screws up, as the Arduino, you need a reset button for restart.
Hi, do you know about the Parallax Propeller microcontroller ??
Why is so powerfull because have 8 cores in one chip
I heard about it. But unfortunately it is not well known.
See's the word about measuring interrupts in the title 😁 then hears the word "Python" 😢 and leaves the noob to his PC world view...
You seem to be a pro. Cool!
Yes, not designing in a reset button IS a beginner's mistake. It is also one that the RPi people have not learned from since the very first Raspberry.
On a Linux system I would argue that a reset button can be dangerous because you have to shut it down. On an MCU this argument does not work...