#149

  Переглядів 60,076

Ralph S Bacon

Ralph S Bacon

4 роки тому

An absolute beginners' introduction to dual-core processing using the keenly-priced ESP32 processor boards from Espressif.
Happy Birthday to PCBWay.com who are celebrating their 5th birthday all this month (June 2019)!
They want to share some goodies with you so visit
www.pcbway.com/anniversary5sa... and see what might take your fancy.
PCB Prototype the Easy Way - Full feature custom PCB prototype service.
$5 for 10 PCBs: www.pcbway.com/
All this and more on my GitHub:
github.com/RalphBacon/ESP32-D...
Boards entry: File -- Preferences
then click right down the bottom of the page to Additional Boards Manager URLs, to add this line:
dl.espressif.com/dl/package_e...
Wemos D1 Mini32 ESP32 as used in the demo.
Note, UK warehouse price same as China price but get it in two days!
bit.ly/2Wx5Cbd
An Arduino-sized ESP32 board (TTGO ESP32) with all the relevant pins marked up, I have one myself:
UK warehouse: bit.ly/2wKa5rI
CN warehouse: bit.ly/2K77Qrd
There are various TTGO ESP32 boards available, different formats, different prices, worth browsing before buying.
Other ESP32-related links:
Hardware design reference: public.robotical.io/Datasheet...
Getting started with the ESP32: docs.espressif.com/projects/e...
Nothing to do with this video, but I bought a dual solder reel holder, works like a charm and very solid. I'll show you this in a future video on SMD soldering:
bit.ly/2ZdlgFy
All this and more on my GitHub:
github.com/RalphBacon/ESP32-D...
If you like this video please give it a thumbs up, share it and if you're not already subscribed please consider doing so and joining me on my Arduinite journey
My channel and blog are here:
------------------------------------------------------------------
/ ralphbacon
ralphbacon.blog
------------------------------------------------------------------

КОМЕНТАРІ: 383
@GeekMustHave
@GeekMustHave 4 роки тому
Very nice video on running multiple threads on the two cores of the ESP32, I had no idea how but, now I do. Thanks. Keep broadcasting!!
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, GeekMustHave, noted and appreciated!
@peterheartfield8106
@peterheartfield8106 4 роки тому
Thanks Ralph. Great video, yes please do more.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Peter Heartfield, noted and appreciated!
@neverendingrefit759
@neverendingrefit759 4 роки тому
Great stuff, and yes please, more like this! Lots blogs etc about esp blink but not so much dipping your toe deeper into the ESP32
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Boat data systems, noted and appreciated!
@bipolarchemist
@bipolarchemist 4 роки тому
I've never (knowingly) tried this for processes running on different cores, but you might be able to use a variable of portMUX_TYPE to handle synchronization between the cores. Any variables you plan to change between cores might need to be declared volatile and then you add some wrappers around the variables to you want to modify to keep them from being modified by various processes at the same time. // Declared globally portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; // In function to modify shared variables portENTER_CRITICAL(&mux); // modify/update variable here portEXIT_CRITICAL(&mux); This works great for interrupt handlers and might work with multiprocessor task as well.
@george12121979
@george12121979 4 роки тому
very usable. in a very simple way how exactly the two-core system works in esp32. It is a very interesting field for applications of esp32 and would like if you can continue on this field.
@RalphBacon
@RalphBacon 4 роки тому
And continue I will, George! Stay tuned!
@ytbone9430
@ytbone9430 4 роки тому
Thank you Ralph! o) I'm new to the microcontroller space and I really like your videos. The way you talk and present, it's very pleasant to watch and learn. I wouldn't mind more coding related videos. I am a software dev myself, but I have issues understanding on how to throw all the things together in loops/interrupts (say you want wifi, mqtt, config via webserver, read multiple sensors and drive a display with menu at the same time). Doing this on a microcontroller is quite different to desktop development, I surely have a lot to learn, thank you for getting me started. o)
@RalphBacon
@RalphBacon 4 роки тому
And I'm glad to have you along, ytbone! If you're a dev then programming the Arduino and similar µControllers is not going to be difficult. In fact, the ESP32, with its operating system, feels like home to me! Keep tuned for further videos...
@Thomas72B
@Thomas72B 4 роки тому
Very interesting Video ! Please more videos about the ESP32 !
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Thomas, noted and appreciated!
@heyok
@heyok 4 роки тому
Ralph, thank you for the time and effort you put into this as I really appreciate it. I always seem to learn something.
@RalphBacon
@RalphBacon 4 роки тому
Thanks for that, heyok, nice to hear from you.
@hmb2a
@hmb2a 3 роки тому
Thank you, Ralph. Not only the contents but also the effects of your video are excellent. Please continue.
@RalphBacon
@RalphBacon 3 роки тому
Thanks, will do! Well, once my house move has completed and I have a new workshop!
@paulyorke1437
@paulyorke1437 4 роки тому
I've been subscribing to your channel for a few weeks now Ralph. Excellent work and at a pace I can cope with. Brilliant. Just bought a couple of these ESP32s and started with your RTC sketch. Now can't wait for next episode re sharing variables between cores. Yes, more on the ESP32 please !!!
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Paul, noted and appreciated!
@michaelhyde9971
@michaelhyde9971 4 роки тому
Great video as usual. I was thinking about getting an esp32 now I will thanks :)
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Michael Hyde, noted and appreciated!
@OsoPolarClone
@OsoPolarClone 4 роки тому
Ralph another awesome video. I have seen other ESP32 videos but yours is the BEST! You did things I have never seen before. AWESOME!!!!!!
@RalphBacon
@RalphBacon 4 роки тому
Wow! I'm glad you enjoyed the video, Bruce. It's a subject that is interesting for quite a few people. I shall have to do at least one further video.
@magic.marmot
@magic.marmot 4 роки тому
Oh my, thank you so much! I work with FreeRTOS all the time on the professional side, and have some ESP-32 boards for experimenting and making new things at home. This gives me a whole 'nother level of being able to mix the two "under the hood", and has opened up a whole new bunch of ideas on how to meld the two.
@RalphBacon
@RalphBacon 4 роки тому
With your RTOS experience you should be quite at home with the ESP32 then, Rob. The Arduino-style implementation doesn't expose all RTOS functions but if you read the Espressif web pages they tell you what to edit in their implementation header files to add functions. You might even prefer the ESP-IDF development environment. docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html Fun times ahead!
@libertywool
@libertywool 4 роки тому
Instead of doing delay(1) in your main Arduino loop, you can use taskYIELD() to let the scheduler know to go do other more important work (Ready tasks with a priority equal to or greater than your task). Because, as you mentioned, in Arduino the main loop is just called repeated from an outer method, the scheduler does not stop running that task unless we allow it (unless we are running the preemptive scheduler). So that will work for core 0, but not core 1. Now since the Arduino loop is running on core 1 with priority 1, calling yield will not work if your task is on core 1 with priority 0, as that is less than the current priority. So to make the task run on core 1, change the priority to 1 or greater. Then calling taksYIELD() will run the task on core 1. And this also takes me back to why delay(1) works. Delay is going to pause the current task (Arduino loop) and yield control to the scheduler. This will put the Arduino loop task into a blocked state (ie not Ready), so the scheduler will then run lower priority tasks (ie your core 1 priority 0 task). Hope that helps explain what you were seeing...
@vonries
@vonries 4 роки тому
I hate showing my stupidity so early in the game, but wtf? It sound very informative, but I have no idea what you're talking about.
@mikelopez9893
@mikelopez9893 4 роки тому
+vonries A real time operating system splits work into several tasks which share cpu time. Tasks can be in one of several states (blocked, ready to run, running). The system has a timer and the scheduler gets control each timer tick. It suspends the current task and switches to the highest priority task in ready state. The esp32 has two cores: protocol (#0) and application (#1). It runs a modified version of free RTOS. Each core has its own scheduler and the two cores are NOT synchronised. For example disabling interrupts on one will NOT disable interrupts on the other and does NOT protect data from corruption. Communicating across cores needs expert knowledge - lots of traps for young players! There is some good info on all this at docs.espressif.com Ps: the 8266 also has RTOS not just the esp32
@vonries
@vonries 4 роки тому
@@mikelopez9893 thanks, very cool.
@RalphBacon
@RalphBacon 4 роки тому
Since doing this video, Toby, I've been looking into this a bit. Yes, a typical British understatement if ever you heard one! *taskYIELD()* doesn't give the expected results, I'm afraid, as neither does *vPortYield()* which is what taskYIELD() expands to. Whilst we're on the subject, *yield()* doesn't do it either as that just calls vPortYield(). What I've discovered is that if we _really_ don't want to use the standard loop() then just execute a *vTaskDelete(NULL)* to get rid of it once and for all. Everything else just keeps running as expected. However, I've begun to use loop() as a "master" controller in some of my sketches that can control things (eg suspend/resume tasks, very useful) and keep a watching brief on what is happening. Task orchestration, if you will, which reminds me strongly of an event listener framework I developed for work using JavaScript. What goes round comes around... More of this and other stuff in a future video! Thanks for your input, Toby, you have a lot of experience in this area and your continued feedback is greatly appreciated. Nice to hear from you.
@mikelopez9893
@mikelopez9893 4 роки тому
Ralph S Bacon I think the issue is just priorities. TLDR - use priority 1. Here’s the espressif scheme: Priorities 10 to 14 are reserved for the system. For example, 14 is the watchdog timer, 10 is the TCP/IP stack. Priorities 1 to 9 are for general use. For example, WiFi events use priority 2. Priority 0 is the idle task. There are three ways a time slot can end. 1) it can voluntarily yield and the state goes to ready. 2) it can block waiting for something to happen - the state goes to blocked. 3) The time is used up - the state goes to ready. At the end of the time slot the scheduler takes the highest priority task in ready state and runs it. If several ready tasks have the same priority they are allocated “round robin” (but see caveat below) Caveat: the above is correct for the esp8266, but the esp32 does not have a complete multiprocessor implementation of free RTOS and can not guarantee equal round robin treatment across cores. I am concerned that you used priority zero which is reserved for idle. Essentially you are telling the system “nothing important to run here”. Hope this helps.
@marinehm
@marinehm 4 роки тому
Ralph: Thank you so much for your videos! I bought my ESP32 when they 1st come out but at the time there was limited support. Now I feel confident I can load the board definitions into my IDE and press forward.
@RalphBacon
@RalphBacon 4 роки тому
Quite right, Nick, when I did my first video on the ESP32, I remember them being a bit temperamental. And support was hit and miss. Now though, 55 videos later, I too feel that they have come of age. Keep tuned for further videos...
@ianstubbington2334
@ianstubbington2334 3 роки тому
Great video for getting started with esp32. More please ;)
@RalphBacon
@RalphBacon 3 роки тому
Thanks, will do!
@deangreenhough3479
@deangreenhough3479 4 роки тому
At work and yet to see. But boy, I’ve been waiting for this one. Well done Ralph😁🏴󠁧󠁢󠁥󠁮󠁧󠁿
@RalphBacon
@RalphBacon 4 роки тому
I hope your expectations were met, Dean, and stay tuned for further videos.
@la6mp
@la6mp 4 роки тому
Really good stuff, Ralph! It is nice to go a bit under the hood of devices we often use without knowing what they are really capable of.
@RalphBacon
@RalphBacon 4 роки тому
You are most welcome John, I'm glad you like the video. Nice to hear from you.
@TheZrpilot
@TheZrpilot 4 роки тому
Very much enjoy this and ALL your videos Ralph... would like to see more!! Thanks!!!!
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Max, noted and appreciated!
@davidharms3562
@davidharms3562 11 місяців тому
Still enjoying these videos Ralph! Keep up the great work, good sir! 👍🏻
@RalphBacon
@RalphBacon 11 місяців тому
Glad you like them!
@John_Smith__
@John_Smith__ 4 роки тому
Oh yes, ESP32 is a great great platform ! We would all love to see inter-task communication ... passing arguments and data.
@RalphBacon
@RalphBacon 4 роки тому
Yes, that will be "interesting", John. Keep tuned. Thanks for posting.
@Trevor30926
@Trevor30926 4 роки тому
HI Ralph, very interesting video. I have just ordered a couple of boards. Please keep this type of video coming, The more the merrier.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Trevor30926, noted and appreciated!
@noweare1
@noweare1 4 роки тому
Another worthwhile video. Count me in for more esp32 vids. As far as the speed difference ... that's just mind boggling.
@RalphBacon
@RalphBacon 4 роки тому
Yes, Joey, it took me by surprise, actually. I wondered what I had done wrong! I even include some debugging statements in the code and it whizzed through so quickly it was amazing. Amazing chip.
@BiggsWorld
@BiggsWorld 4 роки тому
I just found your channel, subscribed! Great video, I've been using esp32 for quite a while now and learned some new stuff. I like the teaching style too. I love these kinds of things that add to my knowledge! Bravo.
@RalphBacon
@RalphBacon 4 роки тому
Thanks for that, BiggsWorld, nice to hear from you. Thanks for subscribing too!
@andymouse
@andymouse 4 роки тому
Hi, speaking of ESP32's an Australian UKpostsr who has a great channel called "The Unexpected Maker" has spent about a year designing a product called "TinyPico" Its as the name suggests a very small ESP32 development board, and I and many others have been watching the highs and lows of his design and thanks to crowd supply (and enormous effort on his part) is being shipped, I highly recommend that you have a look at his "TinyPico" as it really is feature packed, plenty of IO and he has a fully matched 3D antenna on there for outstanding WIFI performance. Take a look at his channel lots of interesting stuff....especially for ESP32's!
@RalphBacon
@RalphBacon 4 роки тому
And look I did, Andy, very interesting. I shall read (and watch) some of his videos when time permits. For others, here's the link: unexpectedmaker.com/tinypico
@anispinner
@anispinner 4 роки тому
So many details. Thank you, Ralph! Subbed, looking to more content on MC's and FPGA's.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, NLab, noted and appreciated!
@daviddoidge1252
@daviddoidge1252 4 роки тому
Excellent again, looking forward to more ESP32 videos
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, David, noted and appreciated!
@timcallinan
@timcallinan Рік тому
Excellent Tutorial Ralph. Enjoying it
@RalphBacon
@RalphBacon Рік тому
Glad you enjoyed it!
@iHayri1
@iHayri1 3 роки тому
Hi Ralph, just wanted to thank you for your incredible videos, they are extremely informative, very easy to understand and to learn from with no nonsense whatsoever like annoying background music which always seems too loud and makes understanding difficult. Of course I subscribed and hit the bell, to not miss a single video. Btw, the ESP32 is my new found love and I intent to learn every bit if information about it. Already designed and have manufactured a CNC milled aluminum case that will go with my version of a 3.5" IPS display with capacitive touch and the required PCB of course. Anyway, sorry about the long comment. Happy Holidays and a great New Year, stay safe.
@RalphBacon
@RalphBacon 3 роки тому
Thanks so much for your kind words, Hayri. The ESP32 is indeed a wonderful device (not Revision 0 though!) and I am now reading up more on the freeRTOS and multitasking. Very powerful stuff which I will share in the New Year. Have a good one!
@iHayri1
@iHayri1 3 роки тому
@@RalphBacon That is the least I can do, wish I could do more to support you than just subscribing but I do have my own struggles :-) Nevertheless if you are interested in my new upcoming PCB with the ESP32 WROVER on it, or anything esle I work on for that matter, I will be glad to send you one as a gift to show my appreciation for your excellent work. Looking forward to see freeRTOS and multitasking examples. Be well.
@Ne555N
@Ne555N 3 роки тому
This tutorial is excelent!! Thank you very much for the effort you put into the video
@RalphBacon
@RalphBacon 3 роки тому
You're very welcome!
@tomwatzek3500
@tomwatzek3500 4 роки тому
Nice Video, thank you. I would be happy if you do another video an go more into detail. - like how to get variables from on core to the other.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Tom Watzek, noted and appreciated! Variables from one _task_ to another (the core is irrelevant) is the subject of my next video, Tom. Oh, perhaps I should not have said that.. spoiler alert! Too late!
@robingiles399
@robingiles399 4 роки тому
What a great video, looking forward to more ESP32 videos, area of interest are around maximising power saving capabilities, this unit is great, Perhaps looking at the ESP-PICO-D4 as well..
@RalphBacon
@RalphBacon 4 роки тому
Thanks for that, ROBIN GILES, nice to hear from you.
@wires4auto
@wires4auto 4 роки тому
Fantastic! Ralph. I think this should be the second microcontroller board newbies get, the Delay fuction is so evil to beginners, and can hold them back. I would really like to see more of this board in the Arduino IDE, using Bluetooth fuction and passing information between the two cores. Thanks again.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, gordon, noted and appreciated!
@willofirony
@willofirony 4 роки тому
Yeah, I like this sort of stuff. Brilliant vid, Ralph.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Michael , noted and appreciated! Good to hear from you again!
@GRPZ66
@GRPZ66 4 роки тому
Excellent video. Keep them coming. Much appreciated.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Guido Zijlstra, noted and appreciated!
@stevehallam0850
@stevehallam0850 4 роки тому
Really good stuff, thanks Ralph 👍
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Steve Hallam, noted and appreciated!
@robertnovak1602
@robertnovak1602 4 роки тому
Hi Ralph, I really enjoy watching your videos, so thank you for sharing. The reason that putting nothing in loop() would result in your program doing nothing is because a "function" is just a location in memory which happens to contain instructions. Those instructions are generated by the compiler. If your function doesn't have any instructions, it would be effectively just a "jump" and "return", or possibly a "call" instruction (in fancier instruction sets). Basically, because the function doesn't have any content, when it generates the binary/executible, since it is optimizing for space, it most likely doesn't include that function, or won't provide an actual definition for it (different compilers and different optimization profiles will do different things, so I can't say precicely what it will do). Keep up the explorations, like I said, I really enjoy them.
@RalphBacon
@RalphBacon 4 роки тому
Yes, it's unclear whether the compiler would optimise an empty loop away (you would hope it would) and if so the task handler could not start the expected (default) loop task. That might crash the chip I suppose. I've just deleted the task in other sketches if I don't want the default loop(). Thanks for posting, Robert, good to hear from you.
@robertnovak1602
@robertnovak1602 4 роки тому
Depending on how obsessive you want to be, you can take a look at the ELF binary that gets generated, and see exactly what's getting created. It's not something I really enjoy doing, but it is usually enlightening. A very quick way to verify without looking at the binary itself would be to look at the size of the resulting binary with and without the delay added to loop(). If there's a massive size difference, you can be reasonably sure that the compiler is simply optimizing away most of the program. My thought would be that if loop() didn't contain any instructions, not only would the compiler remove the "call loop()" instruction, but it in theory should (being that it's C) optimize away most of even the basic wrapper program. Perhaps an example might illustrate: Suppose the "wrapper" program looks like: void main() { setup(); while(1) { loop(); } return; } if loop() is empty, that goes away, and the compiler is left with an additional empty while(1) loop. This also should get optimized away, and thus main() would become: void main() { setup() return; } resulting in the board not crashing per-se, it just essentially finishes the entirety of the task. anyway, I'm just some dude on the internet so feel absolutely free to take with a grain of salt.
@RalphBacon
@RalphBacon 4 роки тому
I'm thinking that the ESP32 (RTOS) would start the task handler for specific tasks (one of them being loop) but if the loop did not exist it may do weird and wonderful things. Eventually we will find out, I'm sure.
@Ed19601
@Ed19601 4 роки тому
Just got myself a few esp32's so I will be revisiting this
@RalphBacon
@RalphBacon 4 роки тому
Yes, indeed, Ed, it's quite interesting what you can do with them.
@datho-cq1ez
@datho-cq1ez 2 місяці тому
I am a student come from Viet Nam, this is a excellent video, thank you because share this topic.
@RalphBacon
@RalphBacon Місяць тому
Glad you enjoyed it! Thanks for posting!
@bhnienhuis
@bhnienhuis 4 роки тому
Very interesting, please continue
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Herman Nienhuis, noted and appreciated!
@ayganotomasyon1109
@ayganotomasyon1109 Рік тому
Thats what i m looking for. Thank you.
@RalphBacon
@RalphBacon Рік тому
Glad I could help!
@williammiller7543
@williammiller7543 4 роки тому
Another Great, Informative video. I'm starting to use the ESP32 and this background info is Very usefull.
@RalphBacon
@RalphBacon 4 роки тому
Thanks for your post, William, good to hear from you.
@ElieWar
@ElieWar 4 роки тому
Thank you, yes more, plz
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Elie, noted and appreciated!
@jeffbluejets2626
@jeffbluejets2626 4 роки тому
As usual, great stuff. More thankyou.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Jeff Bluejets, noted and appreciated!
@mav29
@mav29 3 роки тому
thanks mate, 2020 and still a great video
@RalphBacon
@RalphBacon 3 роки тому
Glad you enjoyed it! I want to do another on Timer Tasks, more efficient. It's on the list...
@mav29
@mav29 3 роки тому
@@RalphBacon we'll wait for it, And tonight I have decided to get me an esp32, thx haha BTW would it be possible to distribute load across 2 esp32 as processors while another is handling load distribution he he thx
@mav29
@mav29 3 роки тому
@@RalphBacon im back sir, i just recieved my ESP32 today and im going to test it using your examples yaaayyyyyyy! cheers!
@peut
@peut 4 роки тому
Very nicely done. Thank you. Please continue.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Jose, noted and appreciated!
@michaelbishton9439
@michaelbishton9439 4 роки тому
I've programmed a bit in other languages pre-IoT and am transitioning to the world you reflect here. I really like your clear and thoughtful approach to explaining things. I know (perhaps) just enough to see that you are using functions with parameters that pass information. May I suggest that when you use a function (like xTaskCreatePinnedToCore), you include a link to it's library that lists all of the functions, parameters, and what they do? That way, advanced beginners like me can more quickly build on what you teach without trying to find the libraries you are already using. I've used Adafruit tutorials that show functions with links to (what looks to me to be) partial libraries or incomplete explanations, which limit their functionality. Many thanks!
@RalphBacon
@RalphBacon 4 роки тому
Point taken, Michael, although in this case it's not so much a library as an entire operating system Free RTOS. It's been modified, somehow, by Espressif for this chip (not sure of the differences) but RTOS is well documented and there's a downloadable Reference Manual pdf too: www.freertos.org/Documentation/RTOS_book.html I hope this helps!
@michaelbishton9439
@michaelbishton9439 4 роки тому
@@RalphBacon Thank you very much, it does. Please keep doing that so that people can look up the full list of functions.
@abboberg987
@abboberg987 4 роки тому
Today i learned a lot; ESP32 has 2 cores and we can use it! Thanks Ralph
@RalphBacon
@RalphBacon 4 роки тому
We can use two cores with care, André, as you will hear in my next video. Multitasking is a great liberator and at the same time a minefield. Keep watching!
@originuk
@originuk Рік тому
Just quickly browsing through your tutorials - love what your're sharing! Multi-threaded stuff works fine when working with unique pins ... when using separate tasks to do stuff concurrently over the I2C or SPI bus, obviously needs resource locking... you may have mentioned this, already so apologies if you have. Great to see simple examples.
@RalphBacon
@RalphBacon Рік тому
Yes, semaphores and mutexes can lock resources but that's no use if the GPIO pin you want to share is already in use with a peripheral! Imagine some part of your program interrupting an SPI packet!
@michaelbyron9688
@michaelbyron9688 4 роки тому
Ralph, AWESOME video. The ESP32 is the processor to use today. how about a video on the sharing of variables between the two processors, going both ways.
@RalphBacon
@RalphBacon 4 роки тому
Hmm, I wonder what could be the topic of my next-but-one video, Michael, I wonder... Nope, can't figure it out. We shall just have to wait and see.
@mksmurff
@mksmurff 3 роки тому
Just found this. Brilliant. Earned a sub
@RalphBacon
@RalphBacon 2 роки тому
Thanks, DannyK, welcome aboard.
@patrickmaartense7772
@patrickmaartense7772 4 роки тому
yes please more of this !
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, patrick maartense, noted and appreciated!
@sortofsmarter
@sortofsmarter 4 роки тому
This is soooooo cool....I have like 3 of these boards...late night aliexpress shopping..lol and needed lots of help to really understand what in the heck I got into and how to use them.....Andreas Spiess is good but a little to advanced for my newbie abilities....Thanks
@RalphBacon
@RalphBacon 4 роки тому
Thanks for your post, Gene, good to hear from you.
@JohnTinic
@JohnTinic 4 роки тому
i love the esp. i avoided arduino wherever i could. just used it to flash my printer 😂 great video with onpoint informations thx👍
@RalphBacon
@RalphBacon 4 роки тому
You are most welcome John, I'm glad you like the video. Nice to hear from you.
@henrikjensen3278
@henrikjensen3278 4 роки тому
Interesting video, I have played a bit with the ESP32, but have not studied it and did not know it had a RTOS. With a RTOS it means you could run both your task on the same processor, you do not need to distribute it on two processors to run them in parallel. One big advantage for ESP is 32 bit architecture, it means anything but byte variables will be faster on it by more than the clock speed. The speed increase in your test was insane, there must be many factors to get that much. One detail I did find out about the ESP32 is that programs are stored in a serial memory and it will use a serial protocol to read the program. This reading is fast, but much much slower than the processor, it uses a internal cache to prevent much delay while running the program.
@RalphBacon
@RalphBacon 4 роки тому
Shh, don't spoil my next video on parallel task, Henrik! Yes, of course you can run multiple tasks on a single core, and as RTOS is running WiFi and BT tasks (among others) on Core 0 it's probably wise to treat core 0 with serious respect (memories of watchdog resets come to mind when I was coding my ESP8266 deice). You are correct about busses of any kind slowing down the processor - caching helps of course, but there's a limit and my first video #95 of the ESP32 driving a MAX7219 display was _very_ slow (caused by the stupidly slow I2C - or was it SPI? - bus setting). Anyway, great to hear from you, more in a future video!
@henrikjensen3278
@henrikjensen3278 4 роки тому
I am looking forward to more videos about ESP32, a good youtube video is a fast way to learn stuff. It looks like the ESP32 has some limitations on real time response, due to the RTOS, what I mean is that you have to handle a lot of stuff with RTOS calls, not directly. This means lots of clock cycles slower. You can check my projects about "computer controlled ..." stuff to see what I mean: lygte-info.dk/project/indexProjects%20UK.html A RTOS calls will probably mean that the ESP32 will not be faster than a old style Arduino to setup the function (Bad description, what do you call programming multiple times simultaneous), but when running it will have better precision. When I get better acquainted with the ESP32 (or any ARM CPU) I may redo the above boxes, but for now they work very well.
@rzinindiana8029
@rzinindiana8029 2 роки тому
As usual... clear and important info... TX
@RalphBacon
@RalphBacon 2 роки тому
Glad it was helpful!
@abpccpba
@abpccpba 4 роки тому
Thanks yes more on ESP32 👍
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Paul C Johnson, noted and appreciated!
@chetanyasaxena8082
@chetanyasaxena8082 4 роки тому
Great Video, very informative. Keep up the good work sir BTW new sub. Please make more ESP32 Videos.
@RalphBacon
@RalphBacon 4 роки тому
Thanks for your post, Chetanya Saxena, good to hear from you and thanks for the sub. You are most welcome.
@oncledan282
@oncledan282 2 роки тому
Hey! Ralph. I just looked at your video and I will try this tomorrow (it’s past 1AM for me, now). Thanks for this tutorial. 160 times faster ?? Really ?? It just might solve my flickering problem but I’ll try to get the TFT working first, then, the GPS. I’ll give you updates soon (via mail) Happy new year .. Talk to you soon !
@RalphBacon
@RalphBacon 2 роки тому
Talk soon! Don't be a stranger!
@vincenttang9059
@vincenttang9059 3 роки тому
Very Useful for me, thank you for your sharing :)
@RalphBacon
@RalphBacon 3 роки тому
Glad it was helpful!
@bobbudge1921
@bobbudge1921 3 роки тому
Hi Ralph, excellent video especially for those like me just starting to look at the esp32. Did you ever look at esp-now? I am wondering if it is possible to pass a function from one esp32 to another using esp-now.
@RalphBacon
@RalphBacon 3 роки тому
I briefly looked at it and saw that it was (yet another) way of communicating between ESP devices (not using BT) but decided I'd pass for now. Sorry, Bob.
@maxpenfold8699
@maxpenfold8699 3 роки тому
What a great Video, thanks!
@RalphBacon
@RalphBacon 3 роки тому
Glad you liked it!
@lmamakos
@lmamakos 4 роки тому
Is the Arduino runtime environment for the ESP32 thread-safe and reentrant? In the past, casual inspection of some Arduino libraries show that some/many are not thread-safe because they use statically allocated memory without any locking or protection. This is the tricky part of multi-threaded programming and usually results in intermittent and hard to diagnose bugs because the cause is so timing dependent. Like is the Serial.print method not using any static buffers while its formatting, e.g., Integer values into text? What happens if both threads are simultaneously running the same method? In other examples of adapting the Arduino environment into an RTOS with multiple threads, the practice usually is to only have one execution thread be allowed to use the Arduino environment because its unsafe, and the other threads do "other" processing in known-to-be-thread-safe ways.
@RalphBacon
@RalphBacon 4 роки тому
Excellent point you make, Louis. I shall investigate. Given that most libraries were never written to be thread safe I suspect the safest way to use them is to ensure that only one task ever uses them at a time - which, given the logic of a program could be quite straightforward. For example, if you are writing to a TFT display ensure that only one task (at a time) can access it. I'll investigate what Espressif say, too, on this subject. Thanks for posting, good to hear from you.
@EmbSysDev
@EmbSysDev 3 роки тому
Very , very nice into to ESP32 !
@RalphBacon
@RalphBacon 3 роки тому
Thanks!
@kennmossman8701
@kennmossman8701 4 роки тому
MORE please sir!
@RalphBacon
@RalphBacon 4 роки тому
Ooh, that's enthusiastic, Kenn! I was just thinking (always dangerous) the other day about multitasking on this chip. We will have to see whether all that Deep Thought comes up with new videos.
@kennmossman8701
@kennmossman8701 4 роки тому
@@RalphBacon Use one core per task? Or virtual multi-tasking?
@dekipet
@dekipet 4 роки тому
Neat one. Thank you.
@RalphBacon
@RalphBacon 4 роки тому
You are most welcome Dejan, I'm glad you like the video. Nice to hear from you.
@dekipet
@dekipet 4 роки тому
@@RalphBacon ESP32 has so much to unveil. Just to mention chips ID, touch sensor, temperature sensor, etc. It would be nice to someone take all of that, all of connectivity and make a nice video, or blog article. I am planning to put it on a magazine article i write for. Time is all i don't have. Damn...
@RalphBacon
@RalphBacon 4 роки тому
I'm starting a petition for the UK government to create a 30-hour day to give me more time to do the stuff I need to. Sounds like you will be the first signatory! Yes, I'll get round to the ESP32 features, I hope, in due course, if only I had more time. Oh, I have a feeling of deja vu...
@GabrielAlves-mf8vd
@GabrielAlves-mf8vd 4 роки тому
Amazing tutorial!
@RalphBacon
@RalphBacon 4 роки тому
You are most welcome Gabriel, I'm glad you like the video. Nice to hear from you.
@bryanethier1910
@bryanethier1910 4 роки тому
Excellent vids
@RalphBacon
@RalphBacon 4 роки тому
Thanks Bryan, glad you liked this one!
@rodneytapit5636
@rodneytapit5636 Рік тому
Thanks for this tutorial Ralph, it works for me. I would be very interested to know more about semaphores and mutex for the ESP32 - perhaps you have already made another video on the subject? Also, if I'm using wifi, async. server and client libraries what core would they be running on by default?
@RalphBacon
@RalphBacon Рік тому
Wi-Fi runs on Core 0, along with BT and any other Espressif code. Your code should all run on Core 1. If you place any code on Core 0 you run the risk of it causing a PANIC on Core 0 as it is _very_ sensitive to any delays. I can't remember whether my video #151 (ukposts.info/have/v-deo/saeTpWeoiWOXumQ.html ) dealt with semaphores / mutexes - I'll leave it for you to check!
@rodneytapit5636
@rodneytapit5636 Рік тому
@@RalphBacon Video #151 explains a lot of the finer detail, very good thank you. I wonder how 'sensitive' the single core ESP8266 is when it comes to WiFi operation and the user code delaying WiFi operations.
@binhphuoc2971
@binhphuoc2971 2 роки тому
Hello Ralph, thanks for your video. I learned quite few new things by watching it. I bet other videos of yours are no less excited. BTW: What is the IDE you're using at 16:29?
@RalphBacon
@RalphBacon 2 роки тому
Glad it was helpful! I was using the Eclipse Sloeber IDE but as support for it has ceased I now use PlatformIO on Visual Studio.
@binhphuoc2971
@binhphuoc2971 2 роки тому
@@RalphBacon Thanks. I'm using PlatformIO as well.
@billw2976
@billw2976 3 роки тому
Ralph, thank you very much for you videos and especially for the time you have dedicated to the world of Arduino. May I ask, of you, what program did you use for programing? You said the name during the first part of the video but I was not able to get the name clear enough to do a search for it. It looks like a very interesting system for programing Arduino type processors. Thanks again, Bill in Oklahoma, USA.
@RalphBacon
@RalphBacon 3 роки тому
I use the Eclipse (Sloeber) version but wait for the new Arduino IDE later this year, Bill. It's based on the same Eclipse setup so should be very good.
@jofie2302
@jofie2302 3 роки тому
You should also consider using the "Visual Studio Code" IDE in combination with PlatformIO. It provides Intellisense/command completion, a nice outline, a header file per project remembering things like board type and details, etc.
@pepethefrog7193
@pepethefrog7193 4 роки тому
Running the primenumber code bound to a core gives 135ms. Seems rtos uses both cores for the "unbound" state. Why is one esp32 core 7 times faster than a 8266? Love your way of explaining things plus the examples on git. How is that with passing variables between cores?
@RalphBacon
@RalphBacon 4 роки тому
I don't think it's anything to do which core it's bound to (or allowed to 'float') it's down to the task _priority_ and if you increase yours from 0 to 2 (with 24 the maximum allowed) it will indeed run again in about 64mS. See examples: xTaskCreatePinnedToCore( loop0, /* Function to implement the task */ "Task0", /* Name of the task */ 1000, /* Stack size in words */ NULL, /* Task input parameter */ 2, /* Priority of the task */ &Task0, /* Task handle. */ 1); /* Core where the task should run */ OR: xTaskCreate( loop0, /* Function to implement the task */ "Task0", /* Name of the task */ 1000, /* Stack size in words */ NULL, /* Task input parameter */ 24, /* Priority of the task */ &Task0 /* Task handle. */ );
@magic.marmot
@magic.marmot 4 роки тому
I've watched this again tonight, and have gained even more from it. I have to ask: does the Arduino IDE/library allow you to create multiple tasks on a single core?
@micultimy91
@micultimy91 4 роки тому
It's called multi-threading. it's actually pseudo-multitasking because the mcu is a serial processor is going to perform a little bit of each task you gave it to, in order to give you the appearance of multi-tasking
@RalphBacon
@RalphBacon 4 роки тому
My next video on the ESP32 shows this but you can try just by changing the core parameter on those tasks in this demo. Works as you would expect. If you don't specify a core to run on, then the task scheduler will allocate work to a core as it sees fit. there's much more detail here: www.freertos.org/implementation/a00005.html
@ahmedsaleh4546
@ahmedsaleh4546 2 роки тому
Hi, Thanks for the video I have a task that is resposible for posting data to firebase but I'm not sure how much memory should I assign to it. Thanks
@RalphBacon
@RalphBacon 2 роки тому
Start at a reasonable amount (eg 3,000b, or higher if it crashes!) and print the remaining stack memory every 60 seconds in the task. Then reduce it so that it has headroom of about 500 bytes. Like this: static unsigned long prevMillis = 0; if (millis() - prevMillis > (60000)) { unsigned long remainingStack = uxTaskGetStackHighWaterMark(NULL); log_v("Free stack:%lu", remainingStack); prevMillis = millis(); }
@andrewbarnard3229
@andrewbarnard3229 Рік тому
Just a couple questions please if you have the time to answer.. Can we still use the primary loop() and just append whatever function i want specifically running on core 2 to core 2? Or does adressing the cores in this way require us to now have everything running on a specific core? 2nd question. If i drop the for(;;) loop, can i call that as a function from my other loop but still maintain that the called function runs specifically on the given core. Like.. Can i have a program running on main loop. Then call a function attached to core2 and have that do some math while my main program still cycles?
@RalphBacon
@RalphBacon Рік тому
First things first: on a two-core ESP32 be careful what you run on Core 0. That is used by Wi-Fi and Bluetooth and a few other system-related functions. If they get delayed or interrupted in any significant way then the core will PANIC and crash the processor. Given your other queries I would suggest running multiple tasks on Core 1. I've done a few videos on tasks and this is the way I tend to use the ESP32. Only when there is no other option do I use Core 0 for anything other than what the system puts there. FreeRTOS does a great job scheduling the tasks (tip: keep them all at the same priority). If you do use both cores, you can call any function in your sketch. Functions are not bound to any particular core. But don't use global variables in those sketches as each time it is called it will use the most recent value(s)! Last question: when your main loop is running yes, you can have other tasks on either core running to do some maths. The question is how will you know when it has finished and has an answer (hint: it's usually 42).
@andrewbarnard3229
@andrewbarnard3229 Рік тому
@Ralph S Bacon i wanna start with thank you for the reply, and not just that but the clear and meaningful answers as well. I have no use for the wifi or bluetooth in my project, but i do need simple things to run in the background, like updating displays, etc. it sounds like from your answers and what i have watched from your videos that i may be able to work some things out, your help and insight has been appreciated, feel free to check my channel to see the robotic project i have been working on 😉
@tedmoga4797
@tedmoga4797 2 місяці тому
I plan to use both cores in the ESP for a project I am working on. I want to use core 0 to read wav file data from an SD card and play it using I2S, and provide the audio frame that is being played to core 1. To keep a program running some code from the SD card to move some servos in syvn with the audio. So I have been looking on information how to get this all working. When I read your comments “To be honest, I would not use two cores to do this. Use two tasks instead, of equal priority (ie keep them at 1) on core 1. That way you won't upset either the BT, Wi-Fi or other system function running on Core 0. “ and “It is true - to an extent. Putting some simple tasks on Core 0 won't make it unstable as long as you "yield()" control back to the other tasks fairly frequently. That said, putting an intensive task on Core 0 is not a good idea - keep those for Core 1 (which is where your "loop()" runs) “ After reading some of your comments, I thought the ESP32 will not work for my project so I looked around and I found information that said if you do not enable the WIFI or the Bluetooth the code will not be running? esp32.com/viewtopic.php?t=31169 Some comments said if you do not include it in your code it will not run, “This is nuts. Don't initialise it. There's nothing to stop. “ I think this might be right, but I will have to look into it more. But it makes sense If you do not include WIFI in your sketch why would the code run?
@RalphBacon
@RalphBacon Місяць тому
If you don't invoke Wi-Fi (on Core 0, as you say) then no Wi-Fi code will run. So your Core 0 can be used more like an App core (but there may be other stuff running on Core 0 that is sensitive to delays). If you get a PANIC on Core 0 you know you have crossed the line. Good practice would state that, usually, we should leave Core 0 to do all the Espressif things (including Wi-Fi, BT et al) and use Core 1 for our app. But, like all good rules, they are made to be broken now and again!
@JulianMakes
@JulianMakes 4 роки тому
lovely tutorial thanks :)
@RalphBacon
@RalphBacon 4 роки тому
You are most welcome Julian HG, I'm glad you like the video. Nice to hear from you.
@berkanab4260
@berkanab4260 Рік тому
Hello, quick question, do you meanwhile know why you have to include the delay from (1)?
@RalphBacon
@RalphBacon Рік тому
If you are talking about the one in the loop( ) it is to stop it being optimised away by the compiler. You can remove it, and the loop ( ) function disappears too which _might_ give you an error because the outer shell is calling it.
@GoodAllDay
@GoodAllDay 4 роки тому
Can i use hardware interrupts and dual core mode at the same time? When i tried it, i got a lot of errors in runtime. For example, structure in my project: 0 core for attach Interrupts, and some of algorithms. 1 core for Wi-fi communication and updates tft display using i2c. Is it possible?
@RalphBacon
@RalphBacon 4 роки тому
You must be careful in using Core 0. Try and keep all your tasks on Core 1 initially. Passing semaphores between tasks is fine, but *not* from an ISR, you need a different function. Core 0 is used by RTOS for the WiFi and BlueTooth; if you starve them of CPU cycles they will crash.
@robinvanleeuwen1911
@robinvanleeuwen1911 Рік тому
Yeah I like to see that sort of stuff (multicore programming on ESP32)
@RalphBacon
@RalphBacon Рік тому
Yes, multicore vs multitasking is quite different though, so keep tuned.
@therealblujuice
@therealblujuice 4 роки тому
Yes!!! Please!!! Esp32
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, Justin, noted and appreciated!
@charesealbow5357
@charesealbow5357 6 місяців тому
Ralph, what happens if you add a xSemaphoreGive statement after the xSemaphoreTake statement in loop2?
@RalphBacon
@RalphBacon 6 місяців тому
You've released the semaphore immediately it's been taken.
@paulkirchhof9546
@paulkirchhof9546 3 роки тому
Good stuff, but there are many questions. Ports, RAM, Flash, all is Shared between the two cores. Is RTOS able to handle the problems? If one core set the Port 27 to low and the other core set the same Port to high at the same cycle which core will have priority? Also for ram operation - is the ram locked for one core or can both core write to the same memory address at any time? Please show sketches for work around this.
@RalphBacon
@RalphBacon 2 роки тому
There's nothing magical about having two cores with shared hardware, Paul. If you, as the developer, do not enforce complete control of all that via semaphores and the suchlike, chaos will ensue. It's easy enough to do but tedious and error-prone. As an example, why would you allow both cores to access the same memory location to write info? Is there not a better way? If not, then semaphores (or similar) are the answer.
@paulkirchhof9546
@paulkirchhof9546 2 роки тому
@@RalphBacon , thanks for your answer. if you divide a problem in two pieces and put this in two algorithms a semaphore is a good idea. only when waiting time for the first result is to long RTOS have to cancel the hole work. his works if result2 wait for result1. If you do not know exact which result comes earlier what will you do? is RTOS able to be the master and control both processes? I don’t know how RTOS help to synchronize the cores. if you guest the needed time of one of the processes then you can decide which result waits for the other. Did you understand the problem if you can’t separate the RAM. I have no problems if Flash and RAM belongs to only one of the cores.
@oncledan282
@oncledan282 4 роки тому
Hey, Ralph!I I thought, since that time I got my ESP32 from China, I might as well give it a go and see how to program this li'l wonder. 2 cores seems a nice things to have and I'm glad the use of these cores are very common to yours in my way of thinking .. and a bunch of GPIOs too, although not all of them ore broken out on my Board. I got the ESP32 Development board, from DOIT (or rather, a very nice clone, may I add). I downloaded the board specifics and driver from GitHub and I THINK it's working. I say « I THINK » because the IDE does not seem to see the board as far as the com port is concern. I'll seek other videos to see if I should connect this board via FTDI or if I can program it via the microUSB port, just like the Arduino boards. To be followed .. On that, a few days from the New Year, I wish you all the best for 2020. Talk to you soon, my Friend !
@RalphBacon
@RalphBacon 4 роки тому
Happy New Year Daniel! The question is, does your PC see the COM port of the ESP32? You can use the USB socket just as on an Arduino to upload sketches etc and get back serial messages. Make sure you have selected the correct board from the long list.
@jenniferw8963
@jenniferw8963 Рік тому
Does it make sense to create a task each time you want to update the OLED display? I notice it atakes like 20ms to refresh an OLED with I2C ... pretty slow. Say I have some other process I want to run continuously without a 20ms interruption.. just wondering if the dual core processor would help in this situation.
@RalphBacon
@RalphBacon Рік тому
I would have a task that runs continuously to update the OLED display but which sits there idle until a resource is made available (a flag, if you will). Because it is waiting on a resource (a binary semaphore, maybe, or mutex) it uses no resources itself because it will not be scheduled until the resource becomes available. This leaves other tasks to do their business without hinderance.
@tenlittleindians
@tenlittleindians 4 роки тому
Is code written in sloeber-workspace for an ESP32 governed by the same open source license requirements? Am I able to keep my code private for commercial hardware I develop that uses ESP32 devices?
@RalphBacon
@RalphBacon 4 роки тому
However you write your code, it's not the IDE tool that decides whether or not the final product can be closed source. If you use open-source libraries that have to be made available in the same manner as you found them (ie open source) then your final code cannot be closed source. You must check the licence in each of the libraries. Absence of a licence does *not* mean that it is free - quite the reverse. If, however, the software you include in your project is licenced under the MIT licence then you can do anything you want, including making closed-source software from it. It's a legal minefield. For the ESP32 you also need to check whether the version of RTOS they use is OK for closed source software projects. It may be possible to create some of your software as closed source but release the parts that must be open source. See choosealicense.com/
@georgestewart5879
@georgestewart5879 4 роки тому
Yes some more please.
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, George, noted and appreciated!
@jonathanr4242
@jonathanr4242 2 роки тому
Thanks for another excellent video. I don't mean to be pedantic, but shouldn't we write assembler to do a proper speed comparison because the compiler might be more optimal for one processor or the other?
@RalphBacon
@RalphBacon 2 роки тому
Well, my understanding and belief, Jonathan, is that the compiler writes far better assembler than we can; taking into account the optimisation levels we can invoke too. Anyway, what's a few nanoseconds amongst μControllers? In this case. the difference in clock speed between the Arduino and the ESP32 makes this such a one-horse race anyway... 🤷‍♂️
@jonathanr4242
@jonathanr4242 2 роки тому
@@RalphBacon Hi Ralph, yes 62ms is quite an amazing speed. It's really a cool how this technology filters down to us hobbyists.
@Graham1904
@Graham1904 4 роки тому
Well presented esp (pun) ially for a newbie like myself
@RalphBacon
@RalphBacon 4 роки тому
Groan. Almost a pun, anyway, Graham! Glad you liked the video!
@JerryEricsson
@JerryEricsson 4 роки тому
Believe it or not, I actually have a wonderful use for your initial duel blink program, it will solve a problem I have been tinkering with for over a year now! You see I am a retired police officer, a few years back, my good wife of 50 years gave me one of those old model's of a 57 Chevy. Now back in 69, we drove a 57 Chevy out to Minnesota for our first year of married life, so it was that, I believe that she homed in on. That said, the model was painted the black and white of a police vehicle of that era, so I wanted to build and mount a small light bar that I could turn on to have the model be in pursuit whilst sitting atop my TV Stand. I have it working, but not right, I do have the wig-wag of the blue and red lights working right but the amber caution light in the rear window has to flash in conjunction with one of the overhead lights. This is not the way they really worked, in the old days when I began police work, the overhead lights ran by chain drive, the bulbs were aircraft landing lights, and the rear flasher ran off a simple flasher like a turn signal and the bulb was a simple stop light bulb from a car, I believe it was an 1157 if memory serves. So, you see, I can now have one core run the wig-wag overhead and the second do the caution amber, should work great once I replace the Nano with an ESP32! Sure in the future, I may try and program it so I can turn on the lights remotely from my laptop, that would really be cool, yes I think I will try and program it to do just that!
@RalphBacon
@RalphBacon 4 роки тому
You can certainly do it like this, Jerry, but I would caution you against using Core 0 (too much). Just put all your tasks on Core 1 and it will work wonderfully well without upsetting WiFi and BT that runs (behind the scenes) on Core 0. I'll explain all this in a couple of weeks in a new video but given what you are describing is probably 2 or three "blink" programs this will do for now!
@michaelbyron9688
@michaelbyron9688 4 роки тому
Consider using the Parallax 8 core "Prop" microcontroller. it is easy to use and ideal for concurrent programming. it can be programmed in C or in SPIN a very very easy to learn language.
@mtraven23
@mtraven23 12 днів тому
so does an arduino program straight up only use one core, or does the the program run on one core & background services (like wifi) run on core 2?
@RalphBacon
@RalphBacon 11 днів тому
Exactly so. Wi-Fi, BT and other "system" tasks run on Core 0. Your sketch will run on Core 1. You can make your own tasks run on either core, but Espressif generally suggest that user code should run on Core 1 unless you know exactly what you are doing; this is because any deviant behaviour in that task could make Wi-Fi and/or BT fail (I've had that happen). Also worth stating for others to read, is that your sketch is single-threaded on an ESP32. That is, each instruction is read one after the other and executed on the same core (usually Core 1, as stated above). Bits of your sketch do not run out-of-sequence on another core like you might have happen on a Windows PC to "speed things up" (which they do on a PC).
@robertmurton7373
@robertmurton7373 2 роки тому
Hello Ralph I down loaded your programme okay but it had a stack over flow error when I tried to run it, did you have this error when developing the programme? I have a lot more to learn about the ESP32.
@RalphBacon
@RalphBacon 2 роки тому
No stack overflow here, Robert. Are you allocating too much/little memory to each task? Try putting in your task(s): static unsigned oldMillis = 0; if (millis( ) - oldMillis > 1000) { Serial.print(ESP.getFreeHeap( )); oldmillis = millis( ); } That will show you if you're running out of memory (or have a leak). Adjust the amount of stack you allocate to each task accordingly.
@mikelopez9893
@mikelopez9893 4 роки тому
Nice video, but it might spread some misunderstanding about multi-core and RTOS. Note that RTOS can run multiple tasks on a SINGLE core. Pro tips: 1) Keep your tasks on core 1 and leave core 0 for Wifi etc 2) Use priority 1 or higher for tasks. Leave priority 0 for the “idle” task. 3) Use core affinity with caution! There is a good tutorial on free RTOS at www.freertos.org/tutorial. Keep up the good work. I always enjoy your videos.
@deangreenhough3479
@deangreenhough3479 4 роки тому
Mike Lopez thank you Mike, that’s great additional Information and appreciated. 👍🏴󠁧󠁢󠁥󠁮󠁧󠁿
@RalphBacon
@RalphBacon 4 роки тому
What you say, Mike, is of course 100% correct but I had to think of a way of presenting this clearly and using both cores was (I felt) a good way. I have other sketches that use the same core (or even switch cores) but that's for another day (if this video is received well). In general use, though, tasks should leave core 0 alone as much as possible to let WiFi and BT have their dedicated space to run. I'm a little disappointed that not all RTOS commands are available to the Arduino and the configuration files that control what is and isn't can be a veritable minefield. I'll keep it simple and in line with what my viewers will use most! It's an amazing device though, at an equally amazing price, and will probably convert me away from my current chip-of-choice, the ESP8266 but which doesn't have enough pins for me! I'll put your link in my GitHub if you don't mind, that's a good resource, thanks for the heads-up, appreciated.
@science4allworld587
@science4allworld587 4 роки тому
Study on power consumption variations when one cpu is off? Thanks.
@RalphBacon
@RalphBacon 4 роки тому
No, I haven't even gone there (but I bet others have). I'm not sure that I would choose an ESP32 for battery usage but I guess 'needs must'. I might do something in a future video, but nothing is planned right now.
@ChaplainDaveSparks
@ChaplainDaveSparks 4 роки тому
Ditto for setting the different clock frequencies and measuring power.
@niekbeijloos8355
@niekbeijloos8355 4 роки тому
Did you figure out why the delay(1) is needed within the loop ? I can not find a proper explanation for that. Thank you in advanced!
@RalphBacon
@RalphBacon 4 роки тому
Yes, Niek, I found out the reason. A _delay()_ has an inbuilt _yield()_ which, as you know, allows other processes to take their time slot from the processor. Without the _delay()_ the loop never relinquishes MCU time to other tasks. I tried the following options: //delay(1); //taskYIELD(); //vPortYield(); //yield(); vTaskDelete(NULL); The latter is the best option as it removes the _loop()_ task permanently, never to be called again. Some of the other _yield_ options didn't do what I expected.
@niekbeijloos8355
@niekbeijloos8355 4 роки тому
@@RalphBacon Thank you Ralph, really helpful. Keep it up! Your explanations are very clear.
@paulrichmond6903
@paulrichmond6903 4 роки тому
Great video.
@RalphBacon
@RalphBacon 4 роки тому
Thanks for your post, Paul Richmond, good to hear from you.
@kasunchanuka9610
@kasunchanuka9610 Рік тому
I would like to know the way using 2 cores of esp32 to get vibration values by using 2 adxl sensors?
@RalphBacon
@RalphBacon Рік тому
To be honest, I would not use two cores to do this. Use two tasks instead, of equal priority (ie keep them at 1) on core 1. That way you won't upset either the BT, Wi-Fi or other system function running on Core 0.
@foxabilo
@foxabilo 4 роки тому
Yea, I like this sort of stuff
@RalphBacon
@RalphBacon 4 роки тому
Thank you for your feedback, foxabilo, noted and appreciated!
@foxabilo
@foxabilo 4 роки тому
@@RalphBacon Just been chatting with Andreas Spiess on the platform.io JTAG debug feature western digital has just given everyone for free, about to test the ST-Link V2 with the ESP32 and the Atom editor to see if the maker space can get dirt cheap jtag debugging. Seems the ESP32 is making a resurgence in popularity for all things IOT and a whole bunch of new cool things and toys, really exciting time to be getting to know this cheap abundant powerful hardware. Hope you have a great time with it all and I hope the channel grows well, solid walkthrows of interesting stuff are always a great resource to link to when explaining something to someone just starting out.
@RalphBacon
@RalphBacon 4 роки тому
So, just to clarify, will JTAG debugging allow single stepping of code, or how does it work? I've used MS Visual Studio for years and was spoiled by this feature (impossible to debug enterprise level code otherwise). If the ESP32 allows it... well, I'll await your response first.
@foxabilo
@foxabilo 4 роки тому
@@RalphBacon I am in the breadboard and rats nest phase of finding out, platformio says it supports multi threaded debugging, I'll let you know how that works once i put all this magic smoke back in ;)
@foxabilo
@foxabilo 4 роки тому
So first update, this is specifically regarding the STLink32 V2 and clones, if you set the debug_tool = stlink then you get a compile time error of "DebugInvalidOptions: Unknown debug tool `stlink`. Please use one of `esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa` or `custom`:" I am going to have a scout round the net to see if it is possible to use the "custom" option to set up for use with the STLink if not I will have to order one of the ESP-Prog boards or look at the JLINK clone project as I doubt anyone has £600 floating about to debug a blink led project ;)
@tenlittleindians
@tenlittleindians 4 роки тому
Any program will run faster? Does that mean the "grbl" program for controlling cnc lasers,printers and routers? I am also using an Arduino to control a servo motor and counting pulses from the encoder a and b channels currently limits my speed. I may have to bump my code over to one of these to see if I can increase my pulse read rate on a servo motor.
@RalphBacon
@RalphBacon 4 роки тому
Any program will execute more quickly but will be bound by any network comms that has to take place, such as on I2C and SPI. But, generally, you won't be waiting for a program to run on the ESP32 like you might on an Arduino Uno or Mega.
@GilchristMcGill
@GilchristMcGill Рік тому
Thank you.
@RalphBacon
@RalphBacon Рік тому
Most welcome, Gil
@gvsh7742
@gvsh7742 3 роки тому
Please tell how to make a non blocking wifi program on esp32 I have a serial display to update at the same time MQTT data upload .if it looses MQTT broker it hangs ...
@RalphBacon
@RalphBacon 3 роки тому
Don't use Core 0, Raviprakash. That is used by Espressif for WiFi and other stuff (BT). If all your code is on Core 1 (which it will be by default) then WiFi etc will not block and will not hang.
@RakshithPrakash
@RakshithPrakash 3 роки тому
Hi I've built a MQTT controlled robot using single core maybe this could help. github.com/0xraks/esp32_MQTT_Bot
#148 TCA9548A I2C MULTIPLEXER (& Voltage Shifter)
38:00
Ralph S Bacon
Переглядів 25 тис.
#151 - ESP32 Passing Values 💾 Between Tasks - Deep Dive (2 Easy Ways)
38:38
Что будет с моей рукой?😨
01:00
Аришнев
Переглядів 3 млн
Я ЛЮБЛЮ УКРАЇНУ 3 сезон 3 випуск
1:35:26
Я ЛЮБЛЮ УКРАЇНУ
Переглядів 184 тис.
#263 Using WhatsApp with  your ESP32 (and other μControllers)
18:31
Ralph S Bacon
Переглядів 11 тис.
#203 SPIFFS vs LITTLEFS for ESP32✅ & ESP8266✅ (not Arduino UNO❌)
25:29
#228 ESP32 Over the Air (OTA) Updates with ONE LINE are EASY!
23:26
Ralph S Bacon
Переглядів 27 тис.
#363 Which ESP32 pins are safe to use?
11:53
Andreas Spiess
Переглядів 121 тис.
I built a 6-axes 3D printer that could be groundbreaking!
26:52
Proper Printing
Переглядів 127 тис.
ESPNOW mix with #ESP32 and #ESP8266
25:37
Programming Electronics Academy
Переглядів 30 тис.
#152 STM32 Blue Pill - Is this a modern NANO replacement (✅)
28:14
Ralph S Bacon
Переглядів 50 тис.
#227 ✨printf for Arduino✨(and ESP32, ESP8266) easy, formatted output
23:02
КАК РАБОТАЕТ БРАУЗЕР?
45:23
Alek OS
Переглядів 79 тис.
Обманет ли МЕНЯ консультант в 2024?
19:19
Харчевников
Переглядів 391 тис.