Dual Core Programming for the Raspberry Pi Pico, ESP32, and ESP32-S3 Using the Arduino IDE

  Рет қаралды 38,420

Gary Explains

Gary Explains

Күн бұрын

The RP2040 (found in the Raspberry Pi Pico), the ESP32, and the ESP32-S3 are all dual-core microcontrollers, with two CPU cores. All three can be programmed using the Arduino IDE. Here is a look at how to program both cores on those chips using the Arduino IDE, including a unified sketch that will work on RP2040 based boards and on ESP32/ESP32-S3 boards.
---
Source code: github.com/gar...
Let Me Explain T-shirt: teespring.com/...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains

Пікірлер: 93
@KangJangkrik
@KangJangkrik 2 жыл бұрын
I remember back then Lord Gary mostly explain Android, now he explain every technology! Respect for this guy :)
@1MarkKeller
@1MarkKeller 2 жыл бұрын
The Professor professes!
@pau1976
@pau1976 2 жыл бұрын
I use the two cores of ESP32 for robotics, one for communication with the host and another for closed loop control. This way I get a very low latency in the control loop and I still can change the target position and sample current positions at relatively high frequencies.
@TomLeg
@TomLeg 2 жыл бұрын
Good timing! I'm starting a project for a digital audio synthesizer, and I'm planning to use dual cores, and a little later, RTOS, so very useful!
@rossmyers8448
@rossmyers8448 Жыл бұрын
Coming from MicroPython on the Pi Pico this is so simple to implement it hurts, thank you for the video.
@GaryExplains
@GaryExplains Жыл бұрын
You are welcome!
@sethmitchell840
@sethmitchell840 3 ай бұрын
This code saved me learning a lot about C++!! Thanks a lot :)
@murugesh9338
@murugesh9338 11 ай бұрын
Thanks Gary. watched this videos 4 times for sharp understanding. and read all the below comments. now I'm handson. cheers😁
@rcstann
@rcstann 2 жыл бұрын
¹1¹st; I've been in computers over a half century, and I find Gary's presentations particularly relevant with extraordinary clarity.
@youssubernfissi5559
@youssubernfissi5559 2 жыл бұрын
Just to clarify to anyone interested in parallel programing (since I didn't know this when I bought the esp32) the esp32 can run more than 2 tasks at once thanks to freeRTOS(I don't know about the pico) that is why the code for the esp32 is a bit more complicated,some people say they got around 50 tasks running without any problems Ps core 0 is responsible for wifi and Bluetooth so if you are using those don't overload it with complex tasks
@1MarkKeller
@1MarkKeller 2 жыл бұрын
*GARY!!!* Good afternoon Professor! Good afternoon fellow classmates! Stay safe out there everyone!
@GaryExplains
@GaryExplains 2 жыл бұрын
MARK ‼️
@avejst
@avejst 2 жыл бұрын
Great video as always Love the theme Thanks for sharing your expirence with all of us 👍 😀
@GaryExplains
@GaryExplains 2 жыл бұрын
Thanks for watching!
@bjarke.gotfredsen
@bjarke.gotfredsen 2 жыл бұрын
Your code also works on ESP32-C3 - without any modifications, it just runs both loops on same core. It's useful if you want the same code to run on various platforms, even single core, but make use of both cores if you have it...
@arfjreyes
@arfjreyes 2 жыл бұрын
Looking forward for ypur explanations of mutex, semaphores and synchronizations. Thanks in advance
@aliencray7269
@aliencray7269 8 ай бұрын
Very nice reference to Gibson.
@byronwatkins2565
@byronwatkins2565 2 жыл бұрын
Reads will correct themselves and will not inherently corrupt the data; however, if multiple reads are required (e.g. long on 8b processor or double on 32b), then you might read some bytes before the value changed and the rest after the value changed. In this case this particular value is corrupt. If you don't lock your reads, be careful how you use the result. This corrupt value might otherwise cause the code to branch incorrectly or to perform incorrect calculations and/or to store incorrect values.
@Alkatross
@Alkatross 6 ай бұрын
Got to use semaphore
@markmaker2488
@markmaker2488 2 жыл бұрын
Always interesting and informative! Please do a video on semaphores etc. can’t wait 👍
@bertblankenstein3738
@bertblankenstein3738 2 жыл бұрын
This info will be very useful. Thank you.
@ronaldronald8819
@ronaldronald8819 2 жыл бұрын
I want to separate communication i2c out to core 0 the technique you showed is a nice start. Thanks
@MD-vs9ff
@MD-vs9ff 2 жыл бұрын
Reads can absolutely become corrupted if you're reading a multi-word structure. Unless you're absolutely sure your read operation is atomic you should definitely lock the mutex on reading. Also for the locking/unlocking problem with mutexes, and easy way to solve the problem is to create a MutexLocker class that takes a mutex reference and locks it in the constructor, and unlocks it in the destructor. That way you can be guarenteed that any way you exit out of a function (even if an exception is thrown up the stack) the mutex when be unlocked when the MutexLocker goes out of scope.
@johnstogner6397
@johnstogner6397 2 жыл бұрын
Outstanding explanation! Thanks
@GaryExplains
@GaryExplains 2 жыл бұрын
Glad it was helpful!
@muddyexport5639
@muddyexport5639 2 жыл бұрын
Great vid with a cool explanation that can, as you said, be a template for other codings (simple or complex). Please keep the technical threads coming on multi-thread processing with all their nuances and your videos on other programming languages.
@henkoegema6390
@henkoegema6390 2 жыл бұрын
Very helpful. 😀
@GaryExplains
@GaryExplains 2 жыл бұрын
Glad you think so!
@OMNI_INFINITY
@OMNI_INFINITY 5 ай бұрын
Hey gary: "while". That was a fancy for(;;) though.
@BigB59
@BigB59 2 жыл бұрын
Круто! Спасибо Gary!
@cprashanthreddy
@cprashanthreddy 2 жыл бұрын
Really good content. Post more of these videos.👍
@GaryExplains
@GaryExplains 2 жыл бұрын
Any suggestions on what topics you would like to see me cover?
@cprashanthreddy
@cprashanthreddy 2 жыл бұрын
@@GaryExplains For example, ESP32 Running WiFi (connected to MQTT) in Core-1 and Running LoRa Functionality (connected to a LoRa Module) in Core-2. Here this device (ESP32 + LoRa Module) is functioning as a Gateway.
@michaelthompson8251
@michaelthompson8251 2 жыл бұрын
cool. is there a python example of accessing both cores
@retroandgaming
@retroandgaming 2 жыл бұрын
Are any objects inherently thread-safe in this arduino/pico "land"? In some other languages you have objects e.g. queues that are thread-safe amongst others. Meaning that the standard library handle the locking for you. Would be nice to get an overview of that. I'm glad however that you touched upon this because two threads working seperatly without communicating with each other is rearly usefull in my experience.
@jarrod-smith
@jarrod-smith Жыл бұрын
This was *exactly* the video I needed, but unfortunately I'm missing something. I just installed the latest IDE (2.2.1) with the current MBED RP2040 board manager package (4.0.8). The locking example does not compile for me. It seems to not find semphr.h, nor freeRTOS.h, even if I install the freeRTOS library through library manager. Thoughts? I need to have one sensor reading data on core 0, and another reading its data (asyncrhonously) on core 1. The data on core1 needs to periodically get shared back to core0 via a global float, so the "current" values of both sensors can be output synchronously via serial. Any advice appreciated.
@radnukespeoplesminds
@radnukespeoplesminds 2 жыл бұрын
What core do interupts run on?
@MarlinFirmware
@MarlinFirmware 2 жыл бұрын
Thanks! This is very helpful for our needs as we work on support for the impressive RP2040.
@hudsonator7259
@hudsonator7259 8 ай бұрын
Is this the official arduino rp2040 core or is it the community earle philhower rp2040 core
@allnicksweretaken
@allnicksweretaken 2 жыл бұрын
How does dual core work with serial communications? Do you do the lock/unlock on a variable, and then use that to determine which core gets to use the serial port, or is there a better way?
@manfredbogner9799
@manfredbogner9799 7 ай бұрын
Sehr gut
@joshuaoduroadu5376
@joshuaoduroadu5376 2 жыл бұрын
Thanks for the splendid video. Very informative. I guess the same programming will work on an Arduino RP2040 connect, right?
@GaryExplains
@GaryExplains 2 жыл бұрын
Yes, the template should work on the Arduino RP2040 connect.
@Build_the_Future
@Build_the_Future 2 жыл бұрын
12:00 COM57 how many USP ports do you have, why so many?
@GaryExplains
@GaryExplains 2 жыл бұрын
I have published lots of microcontroller related videos recently and I have been testing a lot of board. Please see my microcontrollers playlist.
@supercrosser6005
@supercrosser6005 Жыл бұрын
Great video, but unfortunately I cannot get the code to give output from the second core on my actual Pico board, I only get output from loop0. I haven't got a Seed board to try. I am using Arduino IDE 2.0.4 and ArduinoMbed OS RP2040 v4.02 is installed. I used Serial.print rather than Serial.printf as I haven't added a library to support it. so- Serial.print ("loop1"); Serial.println(count1); I would be very grateful for any suggestions as i'm at a bit of a dead end.
@supercrosser6005
@supercrosser6005 Жыл бұрын
I have just realised I have a Pico W rather than the regular Pico, so perhaps this is the problem.
@bennguyen1313
@bennguyen1313 2 жыл бұрын
How does this change if using the ST Microcontrollers? For example, if the peripheral assigned to each core.. can they be changed at run-time? For example, can the cores communicate, such that one passes UART access to the other? Would love to see an overview example on how the memory works in dual-core applications. For example the STM32H745 has 2MB of flash, and 1MB of RAM, but how can you allocate most of it to the M7, and the remaining to the M4? Is it possible to debug both simultaneously thru a single JTAG/SWD connector? How does communication work between cores?
@GaryExplains
@GaryExplains 2 жыл бұрын
AFAIK the STM32H745/755 aren't supported in Arduino via STM32duino.
@RoyalTech_2024
@RoyalTech_2024 Жыл бұрын
Hi, I have 3 DS18B20 sensors connected to ESP32, how can I pass this sensor reading from one to another core. Can anyone help me? Is there any example to refer?
@GaryExplains
@GaryExplains Жыл бұрын
I thought I covered that in the video??? 🤷‍♂️ The example code "unified_dual_core_with_lock" is here: github.com/garyexplains/examples/tree/master/Dual_Core_for_RP2040_ESP32_ESP32-S3
@RoyalTech_2024
@RoyalTech_2024 Жыл бұрын
@@GaryExplains Sorry. I couldn't understand why you use 'return r' and what if I have 3 temperature variables to deal with. Also couldn't understand why set function put rnum to r and get function do it viceversa. Sorry I am not a good programmer more of a hardware guy.
@GaryExplains
@GaryExplains Жыл бұрын
"set" and "get" are opposite functions, so of course one puts and the other does viceversa. If you have three temperate sensors then you need 3 globals called something like temp1, temp2, temp3. Then you need three set_ and get_ functions that use the same lock (i.e. bigLock_lock(); and bigLock_unlock(); ). So you need set_temp1(), set_temp2(), set_temp3(), get_temp1(), get_temp2(), and get_temp3(). There are other ways to do it, but for your level of programming this is the easiest. Overall one core will "set" the number and the other core will read it with "get".
@RoyalTech_2024
@RoyalTech_2024 Жыл бұрын
@@GaryExplains 👍
@RoyalTech_2024
@RoyalTech_2024 Жыл бұрын
@@GaryExplains Can't I set 3 variables in one set function itself?
@bbbrung9571
@bbbrung9571 2 жыл бұрын
How do you add the raspberry pi pico to the arduino IDE? Is it through the board manger?
@GaryExplains
@GaryExplains 2 жыл бұрын
Yes, see the Installing via the Arduino Boards Manager section on this page: github.com/earlephilhower/arduino-pico
@chewbaccabg
@chewbaccabg 2 жыл бұрын
Can't quite figure out... are *all* esp32 dual core?
@GaryExplains
@GaryExplains 2 жыл бұрын
No they are not. For example, the ESP32-S2 and ESP32-C3 are both single core.
@chewbaccabg
@chewbaccabg 2 жыл бұрын
@@GaryExplains Where can I find detailed info on which is single and which dual ?
@GaryExplains
@GaryExplains 2 жыл бұрын
On the manufacturer's website, e.g. www.espressif.com/en/products/socs/esp32-c3
@bluegizmo1983
@bluegizmo1983 2 жыл бұрын
I've always been under the assumption that you can't use both cores of an ESP32 if your using WiFi or Bluetooth as those systems are dedicated to one core if you enable them so your code is limited to the other core... Is that not true?
@GaryExplains
@GaryExplains 2 жыл бұрын
If that was true then you couldn't use WiFi at all on any of the single core ESP processors like the ESP8266, the ESP32-C3, or the ESP32-S2.
@oliverschutz7822
@oliverschutz7822 2 жыл бұрын
My Arduino 2.0.0 IDE does not show the "Tools/Arduino runs On" entry in the menue ??? and ARDUINO_RUNNING_CORE is not declared ?
@GaryExplains
@GaryExplains 2 жыл бұрын
Do you have an ESP32 board selected? The menus are context sensitive.
@oliverschutz7822
@oliverschutz7822 2 жыл бұрын
@@GaryExplains Yes, board manager boards: esp32 by Espressif 1.0.6 choosen board ESP32 Dev Module
@oliverschutz7822
@oliverschutz7822 2 жыл бұрын
@@GaryExplains xTaskCreatePinnedToCor(Task1code, "Task1“, 10000, Null,1, &Task1, 0 or 1 ) works
@adrianalanbennett
@adrianalanbennett 2 жыл бұрын
This is a very interested and useful video. Do you know how I can use the Arduino IDE to change the clock speed on the Raspberry Pico? I know it is possible to overclock it by quite a bit, but I have not been able to figure out how to do it.
@GaryExplains
@GaryExplains 2 жыл бұрын
Just click the clock speed you want from Tools->CPU Speed.
@adrianalanbennett
@adrianalanbennett 2 жыл бұрын
@@GaryExplains Thank you for taking the time to read my comment and reply. I do not see an option for the pico in the Tools menu. I have a Teensy 4.1 also and the speed option does show up in the menu for this board; however, it does not for the pico. I have upgrade to the Arduino 2.0 IDE also.
@GaryExplains
@GaryExplains 2 жыл бұрын
Do you have the Pico board installed as described under "Installing via Arduino Boards Manager" here: github.com/earlephilhower/arduino-pico
@adrianalanbennett
@adrianalanbennett 2 жыл бұрын
@@GaryExplains I got it all working - dual cores and overclocking - following your video and using the link you provided for the install. Thanks so much!
@seanocansey5673
@seanocansey5673 2 жыл бұрын
which core does this work on? official Arduino core, or the core by Earle Philhower?
@GaryExplains
@GaryExplains 2 жыл бұрын
Boards supported by Earle Philhower's core.
@kheavmady8780
@kheavmady8780 2 жыл бұрын
Will it effects power consumption?
@GaryExplains
@GaryExplains 2 жыл бұрын
Yes, that is the topic of an upcoming video.
@DataDashy
@DataDashy Жыл бұрын
Show the s3 compiler options in the ide ffs
@matthews4159
@matthews4159 2 жыл бұрын
skip>>> 2m45s why the flash card,, count zero ,, william gibson
@GaryExplains
@GaryExplains 2 жыл бұрын
😂 Think about it, listen to what i said at that moment.
@francoisleveille409
@francoisleveille409 Жыл бұрын
@@GaryExplains Actually I understood why and found that very funny!!
@aldob5681
@aldob5681 2 жыл бұрын
time to switch to 2.0
@GaryExplains
@GaryExplains 2 жыл бұрын
Me or you?
@aldob5681
@aldob5681 2 жыл бұрын
@@GaryExplains me of course, ide 1.x is so old fashion....
@GaryExplains
@GaryExplains 2 жыл бұрын
Cool! I did a video covering the main new features of 2.0 here: kzbin.info/www/bejne/nJLLmKOkqNt_Z5o
@raelseba
@raelseba Жыл бұрын
good explanation but the thumbnail not that good
@GaryExplains
@GaryExplains Жыл бұрын
😂
Raspberry Pi  Pico PIO  - 8 Little Processors You Can Program
31:55
Gary Explains
Рет қаралды 96 М.
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН
451 Which Processor can kill the ESP32?
11:24
Andreas Spiess
Рет қаралды 359 М.
#370 Raspberry Pi Pico vs ESP32 (-S2) and STM32 Blackpill
15:53
Andreas Spiess
Рет қаралды 395 М.
Arduino vs Pico - Which is the Best Microcontroller For You?
20:38
Gary Explains
Рет қаралды 310 М.
Raspberry Pi Pico W: Wireless Weather Station
17:13
ExplainingComputers
Рет қаралды 304 М.
In-depth: Raspberry Pi Pico's PIO - programmable I/O!
17:19
stacksmashing
Рет қаралды 144 М.
Raspberry pi Pico programming in C -- microwave oven monitor and reminder
13:46
Matthias random stuff
Рет қаралды 41 М.
Pi Pico W with the Arduino IDE | Using WiFi
49:26
DroneBot Workshop
Рет қаралды 164 М.