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

  Переглядів 34,517

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/garyexplains/examp...
Let Me Explain T-shirt: teespring.com/gary-explains-l...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains

КОМЕНТАРІ: 87
@pau1976
@pau1976 Рік тому
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 Рік тому
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!
@KangJangkrik
@KangJangkrik Рік тому
I remember back then Lord Gary mostly explain Android, now he explain every technology! Respect for this guy :)
@1MarkKeller
@1MarkKeller Рік тому
The Professor professes!
@murugesh9338
@murugesh9338 Місяць тому
Thanks Gary. watched this videos 4 times for sharp understanding. and read all the below comments. now I'm handson. cheers😁
@arfjreyes
@arfjreyes Рік тому
Looking forward for ypur explanations of mutex, semaphores and synchronizations. Thanks in advance
@johnstogner6397
@johnstogner6397 Рік тому
Outstanding explanation! Thanks
@GaryExplains
@GaryExplains Рік тому
Glad it was helpful!
@bertblankenstein3738
@bertblankenstein3738 Рік тому
This info will be very useful. Thank you.
@avejst
@avejst Рік тому
Great video as always Love the theme Thanks for sharing your expirence with all of us 👍 😀
@GaryExplains
@GaryExplains Рік тому
Thanks for watching!
@BigB59
@BigB59 Рік тому
Круто! Спасибо Gary!
@rossmyers8448
@rossmyers8448 4 місяці тому
Coming from MicroPython on the Pi Pico this is so simple to implement it hurts, thank you for the video.
@GaryExplains
@GaryExplains 4 місяці тому
You are welcome!
@youssubernfissi5559
@youssubernfissi5559 Рік тому
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
@byronwatkins2565
@byronwatkins2565 Рік тому
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.
@1MarkKeller
@1MarkKeller Рік тому
*GARY!!!* Good afternoon Professor! Good afternoon fellow classmates! Stay safe out there everyone!
@GaryExplains
@GaryExplains Рік тому
MARK ‼️
@ronaldronald8819
@ronaldronald8819 Рік тому
I want to separate communication i2c out to core 0 the technique you showed is a nice start. Thanks
@henkoegema6390
@henkoegema6390 Рік тому
Very helpful. 😀
@GaryExplains
@GaryExplains Рік тому
Glad you think so!
@cprashanthreddy
@cprashanthreddy Рік тому
Really good content. Post more of these videos.👍
@GaryExplains
@GaryExplains Рік тому
Any suggestions on what topics you would like to see me cover?
@cprashanthreddy
@cprashanthreddy Рік тому
@@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.
@muddyexport5639
@muddyexport5639 Рік тому
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.
@rcstann
@rcstann Рік тому
¹1¹st; I've been in computers over a half century, and I find Gary's presentations particularly relevant with extraordinary clarity.
@markmaker2488
@markmaker2488 Рік тому
Always interesting and informative! Please do a video on semaphores etc. can’t wait 👍
@michaelthompson8251
@michaelthompson8251 Рік тому
cool. is there a python example of accessing both cores
@MD-vs9ff
@MD-vs9ff Рік тому
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.
@allnicksweretaken
@allnicksweretaken Рік тому
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?
@joshuaoduroadu5376
@joshuaoduroadu5376 Рік тому
Thanks for the splendid video. Very informative. I guess the same programming will work on an Arduino RP2040 connect, right?
@GaryExplains
@GaryExplains Рік тому
Yes, the template should work on the Arduino RP2040 connect.
@MarlinFirmware
@MarlinFirmware Рік тому
Thanks! This is very helpful for our needs as we work on support for the impressive RP2040.
@retroandgaming
@retroandgaming Рік тому
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.
@radnukespeoplesminds
@radnukespeoplesminds Рік тому
What core do interupts run on?
@jarrod-smith
@jarrod-smith 6 місяців тому
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.
@bennguyen1313
@bennguyen1313 Рік тому
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 Рік тому
AFAIK the STM32H745/755 aren't supported in Arduino via STM32duino.
@adrianalanbennett
@adrianalanbennett Рік тому
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 Рік тому
Just click the clock speed you want from Tools->CPU Speed.
@adrianalanbennett
@adrianalanbennett Рік тому
@@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 Рік тому
Do you have the Pico board installed as described under "Installing via Arduino Boards Manager" here: github.com/earlephilhower/arduino-pico
@adrianalanbennett
@adrianalanbennett Рік тому
@@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!
@bbbrung9571
@bbbrung9571 Рік тому
How do you add the raspberry pi pico to the arduino IDE? Is it through the board manger?
@GaryExplains
@GaryExplains Рік тому
Yes, see the Installing via the Arduino Boards Manager section on this page: github.com/earlephilhower/arduino-pico
@Build_the_Future
@Build_the_Future Рік тому
12:00 COM57 how many USP ports do you have, why so many?
@GaryExplains
@GaryExplains Рік тому
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.
@seanocansey5673
@seanocansey5673 Рік тому
which core does this work on? official Arduino core, or the core by Earle Philhower?
@GaryExplains
@GaryExplains Рік тому
Boards supported by Earle Philhower's core.
@kheavmady8780
@kheavmady8780 Рік тому
Will it effects power consumption?
@GaryExplains
@GaryExplains Рік тому
Yes, that is the topic of an upcoming video.
@oliverschutz7822
@oliverschutz7822 Рік тому
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 Рік тому
Do you have an ESP32 board selected? The menus are context sensitive.
@oliverschutz7822
@oliverschutz7822 Рік тому
@@GaryExplains Yes, board manager boards: esp32 by Espressif 1.0.6 choosen board ESP32 Dev Module
@oliverschutz7822
@oliverschutz7822 Рік тому
@@GaryExplains xTaskCreatePinnedToCor(Task1code, "Task1“, 10000, Null,1, &Task1, 0 or 1 ) works
@chewbaccabg
@chewbaccabg Рік тому
Can't quite figure out... are *all* esp32 dual core?
@GaryExplains
@GaryExplains Рік тому
No they are not. For example, the ESP32-S2 and ESP32-C3 are both single core.
@chewbaccabg
@chewbaccabg Рік тому
@@GaryExplains Where can I find detailed info on which is single and which dual ?
@GaryExplains
@GaryExplains Рік тому
On the manufacturer's website, e.g. www.espressif.com/en/products/socs/esp32-c3
@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?
@bluegizmo1983
@bluegizmo1983 Рік тому
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 Рік тому
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.
@DataDashy
@DataDashy 5 місяців тому
Show the s3 compiler options in the ide ffs
@aldob5681
@aldob5681 Рік тому
time to switch to 2.0
@GaryExplains
@GaryExplains Рік тому
Me or you?
@aldob5681
@aldob5681 Рік тому
@@GaryExplains me of course, ide 1.x is so old fashion....
@GaryExplains
@GaryExplains Рік тому
Cool! I did a video covering the main new features of 2.0 here: ukposts.info/have/v-deo/npGZm6alqqx9kmw.html
@matthews4159
@matthews4159 Рік тому
skip>>> 2m45s why the flash card,, count zero ,, william gibson
@GaryExplains
@GaryExplains Рік тому
😂 Think about it, listen to what i said at that moment.
@francoisleveille409
@francoisleveille409 10 місяців тому
@@GaryExplains Actually I understood why and found that very funny!!
@bjarke.gotfredsen
@bjarke.gotfredsen Рік тому
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...
@raelseba
@raelseba 8 місяців тому
good explanation but the thumbnail not that good
@GaryExplains
@GaryExplains 8 місяців тому
😂
#149 ESP32 Dual Core Programming + Speed 💨Test vs Arduino UNO (fast!)
31:18
Військовослужбовці ЗСУ проводять оповіщення в Полтаві
00:32
Арсенал VS Челсі - Огляд матчу
07:44
Setanta Sports Premier League
Переглядів 284 тис.
451 Which Processor can kill the ESP32?
11:24
Andreas Spiess
Переглядів 330 тис.
Arduino IDE 2.0 - Overview and New Features
9:47
Gary Explains
Переглядів 79 тис.
#372 How to use the two Cores of the Pi Pico? And how fast are Interrupts?
14:25
The Pi Pico has problems, so I made my own, the ProPico
7:17
Dmytro Engineering
Переглядів 31 тис.
In-depth: Raspberry Pi Pico's PIO - programmable I/O!
17:19
stacksmashing
Переглядів 126 тис.
PlatformIO: All you need to know in 10 Minutes!
10:56
J's e-shack
Переглядів 276 тис.
Use BOTH Cores  |  Dual Core Programming on the Raspberry Pi Pico
7:49
Low Level Learning
Переглядів 37 тис.
ESP32-S3 - Which Pins Are Safe To Use?
5:58
atomic14
Переглядів 12 тис.
ESP32 Guide 2024 | Choosing and Using an ESP32 Board
41:06
DroneBot Workshop
Переглядів 196 тис.
Fork and Pthreads - A Guide To Get You Started with Multiprocessing
17:28
Військовослужбовці ЗСУ проводять оповіщення в Полтаві
00:32