Тёмный

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

Gary Explains
Подписаться 311 тыс.
Просмотров 36 тыс.
50% 1

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

Опубликовано:

 

3 окт 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 90   
@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 4 месяца назад
Thanks Gary. watched this videos 4 times for sharp understanding. and read all the below comments. now I'm handson. cheers😁
@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.
@bertblankenstein3738
@bertblankenstein3738 Год назад
This info will be very useful. Thank you.
@johnstogner6397
@johnstogner6397 Год назад
Outstanding explanation! Thanks
@GaryExplains
@GaryExplains Год назад
Glad it was helpful!
@avejst
@avejst Год назад
Great video as always Love the theme Thanks for sharing your expirence with all of us 👍 😀
@GaryExplains
@GaryExplains Год назад
Thanks for watching!
@aliencray7269
@aliencray7269 2 месяца назад
Very nice reference to Gibson.
@rossmyers8448
@rossmyers8448 7 месяцев назад
Coming from MicroPython on the Pi Pico this is so simple to implement it hurts, thank you for the video.
@GaryExplains
@GaryExplains 7 месяцев назад
You are welcome!
@BigB59
@BigB59 Год назад
Круто! Спасибо Gary!
@arfjreyes
@arfjreyes Год назад
Looking forward for ypur explanations of mutex, semaphores and synchronizations. Thanks in advance
@ronaldronald8819
@ronaldronald8819 Год назад
I want to separate communication i2c out to core 0 the technique you showed is a nice start. Thanks
@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
@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.
@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.
@1MarkKeller
@1MarkKeller Год назад
*GARY!!!* Good afternoon Professor! Good afternoon fellow classmates! Stay safe out there everyone!
@GaryExplains
@GaryExplains Год назад
MARK ‼️
@manfredbogner9799
@manfredbogner9799 Месяц назад
Sehr gut
@MarlinFirmware
@MarlinFirmware Год назад
Thanks! This is very helpful for our needs as we work on support for the impressive RP2040.
@rcstann
@rcstann Год назад
¹1¹st; I've been in computers over a half century, and I find Gary's presentations particularly relevant with extraordinary clarity.
@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.
@markmaker2488
@markmaker2488 Год назад
Always interesting and informative! Please do a video on semaphores etc. can’t wait 👍
@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?
@michaelthompson8251
@michaelthompson8251 Год назад
cool. is there a python example of accessing both cores
@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.
@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.
@jarrod-smith
@jarrod-smith 9 месяцев назад
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.
@radnukespeoplesminds
@radnukespeoplesminds Год назад
What core do interupts run on?
@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
@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!
@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.
@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.
@hudsonator7259
@hudsonator7259 2 месяца назад
Is this the official arduino rp2040 core or is it the community earle philhower rp2040 core
@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...
@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.
@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
@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?
@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
@DataDashy
@DataDashy 8 месяцев назад
Show the s3 compiler options in the ide ffs
@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 Год назад
@@GaryExplains Actually I understood why and found that very funny!!
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-fahgpnsvL18.html
@raelseba
@raelseba 11 месяцев назад
good explanation but the thumbnail not that good
@GaryExplains
@GaryExplains 11 месяцев назад
😂
Далее
ПОМОГЛА НАЗЫВАЕТСЯ😂
00:20
Просмотров 2,5 млн
I built my own graphics card
15:34
Просмотров 1,4 млн
Raspberry Pi 400: New All-in-One Pi!
14:34
Просмотров 842 тыс.
Pi Pico W with the Arduino IDE | Using WiFi
49:26
Просмотров 149 тыс.
The Petabyte Pi Project
22:27
Просмотров 2,2 млн