#253

  Переглядів 19,524

Ralph S Bacon

Ralph S Bacon

Рік тому

Finally a task scheduler that is super accurate - good enough for a clock!
Ten PCBs for just $5 pcbway.com/
Participate in the 5th PCBWay PCB Design Contest!
Demo sketch, links and more in my GitHub:
github.com/RalphBacon/253-Ard...
During the course of playing about with 7-segment animation, I stumbled across a very well-written Task Scheduler for the Arduino, STM32, ESP32 and others too, from Anatoli Arkhipenko.
I used it just to display a "clock" on the 4-digit, 7-segment display I was using for the animation - and was amazed to find that it was still accurately displaying the correct time the next day. No RTC. No access to the Internet. But still accurate. Unheard of!
Anyone who has ever tried to make an accurate loop in the Arduino environment will know that "drift" is normally unavoidable. That is, the time taken to execute the loop or function has an adverse effect on the timing accuracy of the loop, especially if the loop's code does not always execute the same code. Not any more!
SOFTWARE
So Anatoli Arkhipenko's Task Scheduler is a great find, and has lots of options, not to mention examples. It's worth taking the time to read the documentation to get a better grasp of the potential of this library; not least the option to ensure that a task is effectively guaranteed to fire the correct number of times in a given time period.
Demo sketch, links and more in my GitHub:
github.com/RalphBacon/253-Ard...
► arkhipenko/TaskScheduler: Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
github.com/arkhipenko/TaskSch...
► Using "printf" in an Arduino environment:
• #227 ✨printf for Ardui...
► FreeRTOS on an Arduino? No way! Yes way!
• #244 Multiple tasks on...
HARDWARE
The four-digit 74HC595-controlled device (two 2-digit devices cascaded [soldered] together) can be found here:
s.click.aliexpress.com/e/_DEt...
They don't make a great clock because the gap between the two sets of two digits is too big, but you could always put a couple of 1.8mm flashing LEDs in there, controlled by another task to ensure they flash accurately every second (just like in the demo sketch). But other ones are available that lend themselves better into making into a clock format.
LINKS
► Clickable list of all my videos (Special thanks to Michael Kurt Vogel for compiling this)
bit.ly/UKpostsVideoList-RalphB...
► 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 (and other μControllers) journey
Demo sketch, links and more in my GitHub:
github.com/RalphBacon/253-Ard...
My channel, GitHub and blog are here:
------------------------------------------------------------------
• / ralphbacon
• ralphbacon.blog
• github.com/RalphBacon
• buymeacoffee.com/ralphbacon
------------------------------------------------------------------
My ABOUT page with email address: / ralphbacon

КОМЕНТАРІ: 149
@EugeneSorokacorp
@EugeneSorokacorp 10 місяців тому
I'm an embedded firmware engineer who works with arm processors for a living, but also tinkers with arduinos, I gotta say, your content is incredible. You take it to the next level of complexity. I love your series on state machines and rtos for arduino. These are real world industry concepts, and you introduce them to beginners in such an easy to understand manner. Bravo, sir!
@RalphBacon
@RalphBacon 10 місяців тому
Thank you for your kind words. I hope the beginners you refer to (and for whom this channel was originally created) understand the concepts and put them to good use in their sketches!
@Trust_me_I_am_an_Engineer
@Trust_me_I_am_an_Engineer Рік тому
Thanks so much for finding this scheduler and making the video, Ralph! Especially since it runs on different boards. Love your videos!
@RalphBacon
@RalphBacon Рік тому
My pleasure! Yes, I've now got it running on an ESP32, part of my next project research! Runs great.
@OtusAsio
@OtusAsio Рік тому
Thank you Ralph...you made my day. And you also proved to me that you read most of the comments (if not all). You just did what I would have, not every time for the clock but at the minute or hour of the clock, just to make it do something special. I cannot give you the many likes I would like to give. One will be ok... Thank You!!! BTW French Canadian here.
@RalphBacon
@RalphBacon Рік тому
My pleasure! You'll see this being used in not one, but TWO of my future projects, just because I can! Talk about over-engineered! BTW English/German here.
@volodimirkun
@volodimirkun Рік тому
Sir, this video is timed perfectly! Having a project going right now ,which i will use this lib right away! My regards from Ukraine.
@RalphBacon
@RalphBacon Рік тому
Perfect! I am using this in a new project too!
@arkhipenko
@arkhipenko Рік тому
Hello, Ralph. Thank you for your review of the TaskScheduler. And most importantly, thank you for understanding the concepts behind it and highlighting the aspects of it that are meant to help write compact and reliable code! I sometimes get very critical feedback that this is not "multitasking" or that it does not work for someone in their specific case. Videos like yours help evangelize the library and help developers pick the right tools for their tasks. It also provides me with a third-party perspective on what I designed and what I actually use in 99% of my own projects. You mentioned FreeRTOS in your video. I use that framework a lot as well actually. If you are interested, please have a look at my POC project where I combined the FreeRTOS with TaskScheduler, taking advantage of both. Cooperative multitasking allows you to eliminate a lot of challenges of pre-emptive one, but certain tasks require pre-emption! So my approach lately is to split independent tasks between RTOS tasks but keep complex business logic within TaskScheduler. As an example, I always put sensor reading or pure communication tasks in a separate RTOS task with a higher priority and let them do their periodic jobs. TaskScheduler runs as a separate RTOS task. Since there is little to no dependency between the two, there are fewer race conditions, deadlocks, and other "fun" stuff to worry about or debug. As a matter of fact, I have successfully run multiple TaskSchedulers in separate RTOS tasks, and it all worked beautifully. Here is the link. Please look past the fact that it is a fun project - the concepts tested there are real. www.hackster.io/anatoli-arkhipenko/minecraft-interactive-do-not-enter-sword-sign-esp32-cam-cd1b07 Thank you again. You really made my day! Anatoli Arkhipenko - author or TaskScheduler.
@RalphBacon
@RalphBacon 11 місяців тому
Thanks for your comments and sorry that I have only just seen your comment (blame YT). Yes, I do like your approach to multitasking, keep it going! 👍
@veedonfleece3694
@veedonfleece3694 Рік тому
Hei Ralph, Thank you for another good tutorial. As a hw specialist guy self-learning sw for the ESP32 in particular, these tutorials are at just the right level and enjoyable. In particular, I liked the sleep-on-idle in task scheduler bit. Keep up the good work
@RalphBacon
@RalphBacon Рік тому
Thanks for sharing! Great that you're finding value in these videos 👍
@tim_bbq1008
@tim_bbq1008 Рік тому
I'll forget everything I learned about task scheduling in previous videos and use this one. Super nice! I saw in the arkhipenko examples he uses a RTC module to really lock in the time and probably not rely on the code set start time. Thanks for sharing!
@RalphBacon
@RalphBacon Рік тому
He does that? So do I when I start my ESP32, i grab the time to set the clock and it's fine after that. In a real project I will re-sync the time once a day or so.
@prestongivens3594
@prestongivens3594 Рік тому
Hey, Ralph! Just catching up on your latest videos, an found this one. Wow! My background (I'm 69) was originally in real-time computer interfacing and programming. A light-weight and flexible library such as this one would have been a wondrous addition to the stuff I was writing in Fortran IV on a PDP-11. The cost-benefit ratio of using a "single-user" PDP-11 vs. a "single-user" Arduino (or several of them!) is truly mind-boggling to contemplate! We have indeed come a looooong way! FYI, I go back to the computer Iron Ages! In a lab in college, I worked on a PDP-8L, loading and saving programs via paper tape on a Teletype! Cheers! Pete
@RalphBacon
@RalphBacon Рік тому
OMG 😲 PDP-11! Fortran! Paper tape! I suppose you'll tell me you used 8" floppy disks next?!? (Please don't, I have). Yes, the modern microcontroller is a wonder compared to all those "iron age" devices!
@baconsledge
@baconsledge Рік тому
Thanks Ralph, anxious to try this!
@RalphBacon
@RalphBacon Рік тому
Best of luck! I've used it since in a "real" project, works just fine. Considering whether it will work on my ESP32.
@simonabboud5987
@simonabboud5987 Рік тому
Always enjoy your videos
@RalphBacon
@RalphBacon Рік тому
I appreciate that! 👍
@warperone
@warperone 7 місяців тому
love your videos
@RalphBacon
@RalphBacon 7 місяців тому
Thanks, appreciated 👍
@Ron_Rhodes
@Ron_Rhodes Рік тому
I use Task Scheduler to dynamically generate tasks of different durations and looping frequencies to blink NeoPixels. Great job Anatoli.
@RalphBacon
@RalphBacon Рік тому
Agreed, Anatoli did some very good work here (and updated the library very recently too). Your use of it seems perfect!
@cyberphox1
@cyberphox1 3 місяці тому
Really love your channel and how you teach
@RalphBacon
@RalphBacon 3 місяці тому
I appreciate that! 👍
@jyvben1520
@jyvben1520 Рік тому
looking forward to more implementations of the task schedule system ... looks good.
@RalphBacon
@RalphBacon Рік тому
Yes, I agree.
@keitholiver3981
@keitholiver3981 Рік тому
Very interesting topic, worth further investigation, many thanks
@RalphBacon
@RalphBacon Рік тому
Definitely worth some (in depth) reading, especially his examples. That's what I'm doing!
@WatchTomDotCom
@WatchTomDotCom Рік тому
Hi Ralph, I've been thinking how to accomplish a project. RTOS was an option, but I don't have time for the learning curve. By serendipity today I saw this video. You opened my eyes with using a "task scheduler." Thank you. BTW your channel is fantasic!
@RalphBacon
@RalphBacon Рік тому
Sounds great! Yes, I think Anatoli has produced a great bit of functionality with this library.
@TheMrDrMs
@TheMrDrMs 5 місяців тому
Just found your channel, it's super helpful! I dabble in python for work, but really need to learn C# for work. I also have a lot of projects I want to make based on arduino/pico, so I figured I'd learn concepts with my arduino projects first then move on to C Sharp. And you've explained a number of things that was holding up me up with a number of your videos.
@RalphBacon
@RalphBacon 5 місяців тому
Welcome aboard! I am a C# developer by trade so I can tell you the move to C++ (and back) isn't such a mountain to climb, although there are some huge differences (C# being managed code, probably in a .Net environment) but an ESP32 running RTOS gets you quite close-ish!
@BersekViking
@BersekViking Рік тому
Nice demo! :)
@RalphBacon
@RalphBacon Рік тому
Glad you think so!
@Taran72
@Taran72 5 місяців тому
Thank you for showing a real life example for this library and for providing the code! I find it more useful that the RTOS library. I tried to use the RTOS library but I found it too complicated to figure out...I felt it was going to take longer for me to understand how to use the RTOS than actually writing the code by myself. This library looks more friendly to use for a non-programmer like myself (I'm an electrical engineer hobbyist). Love all your videos, I've learned a lot from you... definitely saved a lot of time (if I had to do it myself).
@RalphBacon
@RalphBacon 5 місяців тому
You can use this task scheduler and RTOS at the same time! Very useful. for instance, you can schedule a task to run every 10 seconds which with RTOS is more complex (albeit very do-able).
@Taran72
@Taran72 5 місяців тому
@RalphBacon , got it, and it's good to know. However, for my current projects, most of the tasks I need to perform are in the order of seconds and minutes, so I don't need the extra speed of the RTOS. Maybe I will spend more time on it later on. Thanks again for your instructional video.
@qzorn4440
@qzorn4440 Рік тому
I love PCBway it makes me look like I know something around my friends. 🙃 I cannot get enough of the esp32 Arduino projects and enjoy the down to earth Ralph Bacon learning videos. 😎 I finally got the Arduino esp32_dev_module; Modbus input 30001 rtu rs485 6_digit panel meter to display on the free cellphone remoteXY app monitoring & displaying the 25,000 Lbs. loadcell using the $24.00 LILYGO T-CAN485 ESP32 Development Board CAN Modbus_rtu_RS485 IoT Engineer Control Module. Thank you for the task scheduler ideas.
@RalphBacon
@RalphBacon Рік тому
The task scheduler also works very well on the ESP32 (running it here now). Thanks for your kind words about my channel and my sponsor too 👍
@PeteTheProps
@PeteTheProps Рік тому
Another great piece of coding help thank you.
@RalphBacon
@RalphBacon Рік тому
Glad it was helpful!
@danielroibert5631
@danielroibert5631 Рік тому
Very interesting. Thank you.
@RalphBacon
@RalphBacon Рік тому
Glad you enjoyed it!
@Poult100
@Poult100 Рік тому
This could be just what I need! I built a battery monitor, basically a coulomb counter, which, to maintain accuracy, resets to 100% when the solar charge controller goes to 'float'. I built a clock with mins, hrs, days to show how long the thing had been running since the last reset. As I lot of various display stuff was happening in the loop, the clock would drift badly at times. I fudged it by dividing millis by a fudge factor. But this Task Scheduler should fix it! Thanks Ralph. Simon
@RalphBacon
@RalphBacon Рік тому
Yes, this should fix it. If your project has got Wi-Fi access you can sync the time once a day to an NTP server (I've not needed to do this but it's good to have the facility).
@jeffbluejets2626
@jeffbluejets2626 Рік тому
Brilliant......and here I was thinking RTC was the only accurate way to make a clock based unit.
@RalphBacon
@RalphBacon Рік тому
Me too. Except this really surprised me.
@ForwardGuidance
@ForwardGuidance Рік тому
Meow Ralph, Great stuff here Ralph. You really know how to get in the weeds and figure things out.
@RalphBacon
@RalphBacon Рік тому
I try! Sometimes the excitement is all too much and I have a lie down in a dark room. Then have a beer. Or two.
@IvoBallie
@IvoBallie Рік тому
Hi Ralph. There is an interesting "shift register" MC14489 capable of driving 5 seven segment displays and can be cascaded. It can also decode certain hex characters, or it can be used as a bar graph driver. For your next project maybe? Regards.
@RalphBacon
@RalphBacon Рік тому
It looks interesting (especially having the 5 "chip select" type lines) but trying to find this chip locally is impossible. Available from AliExpress but as I got my fingers burned there recently I'm not sure we can class the MC14489 as a mainstream chip any more - or have I got that wrong?
@SpinStar1956
@SpinStar1956 Рік тому
This was mildly entertaining! 🤣😂🤣
@RalphBacon
@RalphBacon Рік тому
Ha, ha! When I said that, it was a typical British understatement so I'll assume you found it totally engrossing and couldn't stop watching! 😁😁
@scottstevens7569
@scottstevens7569 Рік тому
Nice video tutorial! Very timely. Your code is soooo pretty now, all those colours: pink, yellow, blue, white,green and just a rainbow of cipher. Think I'll see how an ATTINY treats this library. Unfortunately, the project in front of me isn't a clock, just a fancy switch timer (fan + humidity), but there's a whack of millis I can switch out.
@RalphBacon
@RalphBacon Рік тому
Ideal project to add this to, exactly for the reasons you mention.
@scottstevens7569
@scottstevens7569 Рік тому
@@RalphBacon Well, I guess it 'works' on an Attiny85, but it does not leave much space to do other things. I guess , as expected. Still, likey enough to flip a few breakers or read a metric.. This is the "Blink" example loaded up readout: Sketch uses 4636 bytes (56%) of program storage space. Maximum is 8192 bytes. Global variables use 411 bytes (80%) of dynamic memory, leaving 101 bytes for local variables. Maximum is 512 bytes. Low memory available, stability problems may occur.
@Toro-Tor
@Toro-Tor Рік тому
So in the example here, the second task could have been connected to another single led-segment displaying the " : " every second and you fit it between that gap of the first and second segment-block - "bridging" that open gap ... for example
@RalphBacon
@RalphBacon Рік тому
Quite so. That would be a perfect use of another task. Build, run, forget about it.
@gregwmanning
@gregwmanning Рік тому
Can see your enthusiasm with discovering this task scheduler. I guess the absolute accuracy of a clock (or any schedule) is dependant on the frequency accuracy of the onboard crystal oscillator.
@RalphBacon
@RalphBacon Рік тому
True. I've mentioned this below in other comments, as have others. Maybe I got lucky (no, not that kind) in my Arduino crystal on this board. A super accurate crystal? But I've run the same code on an ESP32 (ran overnight) and it is still 100% accurate this morning. I say 100%, but I'm not logging actual time vs displayed time, so a few seconds drift cannot be noticed right now, but I will compare properly in my final project where I'm using this timer, just so we know. I might do that this morning, actually!
@gregwmanning
@gregwmanning Рік тому
@@RalphBacon Maybe the average crystal is pretty accurate? Good luck with the good luck!
@RalphBacon
@RalphBacon Рік тому
Apparently, the "average crystal" is good for 0.005% so only drifts 4 seconds in a month. Hmm, I wonder why my ESP8266 drifted several minutes a day then? Perhaps running on a ceramic resonator?
@gregwmanning
@gregwmanning Рік тому
@@RalphBacon Without looking my guess would be ceramic resonator, because the are smaller and cheaper than a metal can crystal.
@user-yo7qg9kk4e
@user-yo7qg9kk4e 3 місяці тому
Thank you for the video. You mentioned the scheduler being accurate enough for a clock. Any idea how much it is off (seconds) over say 2-3 months comapred to your wristwatch? Any crystal driven circuit will be temperature dependant, and have some imperfections. And so I wonder if one will be annoyed by having to resync a clock implementation every so often.
@RalphBacon
@RalphBacon 3 місяці тому
As you say, even if the crystal were perfect at 21ºC it would still vary throughout the day/seasons. But I found it pretty good during normal use over a few days. Of course, to be 100% accurate you need to use a microcontroller that has access to the Internet, like an ESP32 where this is all pretty much standard and auto-updates the internal clock every so often.
@alnoorratansi9364
@alnoorratansi9364 Рік тому
Great project, You could get time using NTP (esp8266) and writing the time to rtc, and then reading from rtc to send it to display, then syncing time from ntp every hour or whatever time interval you like.
@RalphBacon
@RalphBacon Рік тому
Well, I could do that... and in my _real_ project I will be doing just that, of course! Albeit I will be using an ESP32. But it does ensure any drift is minimised (my ESP8266 'clock' was appallingly inaccurate: after even 1 day it was several minutes slow).
@IanSlothieRolfe
@IanSlothieRolfe Рік тому
That's interesting, I recently made a device to play a tune every 20 minutes (to remind me to drink water, I need to keep hydrated for my medicines to work...) and had the usual loop calling routines that check the time with millis() to time the 20 minute interval and to time the notes of the tune, flash LEDs etc. I was thinking about creating a library to do make this more general and re-usable, but as usual it appears someone has already thought of that! I might have a go at re-doing the code using this library to see if it is any better than my code.
@RalphBacon
@RalphBacon Рік тому
You can refactor your code in about 10 mins to use this library, Ian. Just look at my demo sketch for an example. This would be perfect for you.
@philipreed2758
@philipreed2758 Рік тому
Another fantastic video ralph. Quick question if i may. been on my mind for a while now. i have used the HC595 shift register for a project and used a slightly different library, and the library got updated and caused all sorts of problems until i noticed. what im really wanting to know is, these libraries have code in them for all the different micros we might want to use them for. does that extra code actually take up much needed space in the overall program? should we be trying to take the code and omitting out code thats never going to be used and will this save space in memory? i am currently working on a big project and it will have many libraries to be included, and im worried about there being not much room left for the actual program for things i want it to do. (my project is not time criticl as such) but just wondering if you have ever come across something like this. Thanks Phil
@RalphBacon
@RalphBacon Рік тому
Many libraries cater for all sorts of processors it is true, but luckily they are _usually_ coded in such a way with compiler directive #ifdef statements that only makes the 'true' bit visible to the compiler - the rest is _totally_ ignored. Example (not real): #ifdef ARDUINO lots of stuff here #else other stuff here #endif This means that if you are using an Arduino board the bit after the #ifdef statement is compiled, and vice versa. Also, the compiler is smart enough to exclude bits of libraries that are never used. So if a library has 100 functions but you only use 1 of them, the compiler (sometimes the linker) will (usually) discard the compiled functions not used. The Arduino compiler has some hard-coded compiler options (in a boards.txt file) that optimise for space, but you can edit the parameters if you know what dangers that might hold for you. Best to leave it to the compiler and linker unless you really know what you are doing.
@greg4367
@greg4367 Рік тому
Greetings from San Francisco. Ralph, do you have any interest in doing a video on migrating from the Arduino IDE to Platform IO. I've been trying to migrate my Teensy development to that environment and can;t seem to crack the code of getting everything set up to work right. Please keep up the great work.
@RalphBacon
@RalphBacon Рік тому
Tricky, Greg. Whilst I _could_ do a walkthrough, the chances are that viewers will hit umpteen speed bumps along the way and get very disillusioned. That said, when I had to reinstall it on my new PC it all went very well. I'll bear it in mind. Greetings from sunny Lincolnshire to San Fran.
@DesertVox
@DesertVox Рік тому
You have to have a separate RTC chip to ensure real accuracy with 'no' drift.
@RalphBacon
@RalphBacon Рік тому
But the whole point of this video was to show how accurate it was. No drift. That said, my newest project using this (ESP32) will sync the time once a day and I will log the drift so we get some evidence.
@hopje01
@hopje01 Рік тому
Best to check if your Arduino board uses a crystal for the processor. There are boards that are using ceramic resonators.
@DaveGWIS
@DaveGWIS Рік тому
Excellent video with lots of golden nuggets of info for newbie me. I am currently grappling with a Uno R3 based project to build a data logger which will need to run for 4+ months remote from the internet, gathering data every 5 minutes of the day and night (eg 09:55, 10:00, 10:05, .... 23:15, 23,20 .....). Syncing to time of day rather than just every 5 minutes. I am doing this with an RTC but can I ditch this and just use the Uno + Task Scheduler to achieve the same thing? My code is a rather tight for a Uno so a bit of extra space would be welcome, if that's what it gives 🤞. Thanks.
@DaveGWIS
@DaveGWIS Рік тому
... I know the RTC (1307) will drift a bit anyway and a few tens of seconds drift over 4 months wouldn't be a major issue TBH.
@RalphBacon
@RalphBacon Рік тому
@David G I don't know how the DS1307 has the audacity to call itself a RTC. They should be removed from sale and only the DS3231 be allowed.
@RalphBacon
@RalphBacon Рік тому
@David G part 2! Sync to time of day is easy once the timer is running. I'm doing that on my workbench right now. A future project will use this library so keep tuned. Yes, ditch the RTC and try this library (use my demo sketch as a guide).
@DaveGWIS
@DaveGWIS Рік тому
@@RalphBacon 😂😂 Thanks Ralph. I appreciate your wisdom and humour but didn't appreciate how bad the 1307 was. I had read that the Uno timekeeping on its own was awful and that an RTC was required to give any semblance of accuracy. Clearly this doesn't apply to the DS1307. All things are relative I guess 🤭
@DaveGWIS
@DaveGWIS Рік тому
@@RalphBacon Again thanks Ralph. 1307 rattling in the bin as I type and looking into incorporating the Scheduler. Also subbed so I wont miss the project - or other gems. 😁👏
@alexrossouw7702
@alexrossouw7702 Рік тому
Hi so it seems that one can implement an led flasher sketch? (by "flasher" I mean where the light comes on for X seconds and off for a Y seconds, eg: on for 5 sec, off 10 sec). Currently I'm polling epoch seconds and would maybe like to upgrade to clock tasks for some coding practise.
@RalphBacon
@RalphBacon Рік тому
Yes, one task (the ON task, for example) can queue up another task (the OFF task to run in ten seconds time. Which in turn can... you get the picture. Alternatively run the 5-second task to switch the LED on/off at different intervals. That single task just runs forever every 5 seconds.
@mrtom64
@mrtom64 Рік тому
Is there any advantage to using this instead of the [see Arduino Reference] 'Ticker' library (by Stefan Staub)? It appears at first glance that they do the same thing.
@RalphBacon
@RalphBacon Рік тому
All so-called interrupt timers will do the "same thing". This library purports to offer the "options" I mentioned including that of ensuring an accurate firing of tasks (which it seems to do).
@jkRatbird
@jkRatbird 2 місяці тому
About libprintf: what’s the benefit over doing Serial.println(“value: “ + String(value)) ?
@RalphBacon
@RalphBacon 2 місяці тому
Basically, it's formatting and neatness of the string that you are outputting, when reading the code. That and the fact that using String like this is non-standard C++ and may contribute to your heap memory going kaputt (technical term).
@MPElectronique
@MPElectronique Рік тому
I use this library as well..
@RalphBacon
@RalphBacon Рік тому
Excellent. Do you find it good?
@Dad-ij2qy
@Dad-ij2qy Рік тому
Superb video, Mr. Bacon. 1. archipenko's code is extremely exciting. I seen no reason why it won't save me TONS of time debugging spaghetti code, as you pointed out, and 2. yes, for battery-operated electronic devices, it could be Heaven-sent for the programmer (me!). However, 3. I must say that discovering your previous youtube video wherein you made a printf function for the Arduino is the BEST NEWS I have heard all week. I will start with that code first. Can I do all this coding from my exiting Arduino 1.8.19 IDE ? I hope I don't need a cross-compiler because I only use free software.
@RalphBacon
@RalphBacon Рік тому
You can do it all from the Arduino IDE, but I do recommend installing the newly released Arduino 2.0.1 as it is a great step up and helps beginners (and experts too) with code completion and function parameter peeks etc. Glad you liked the video. printf for Arduino should be mandatory!
@fscherz
@fscherz Рік тому
I'm also using PlatformIO with ESP32 and used printf without ''! The reason is that the Serial class has it built in, it's Serial.printf(...)!
@RalphBacon
@RalphBacon Рік тому
The ESP32 has it all built in, so I don't believe I ever promoted this library for that platform. BTW, on the ESP32, It's better to use log_x (where x is one of: v[erbose], d[ebug], i[nfo], w[arning], and finally e[rror]) so the messages have a level of granularity. It's all part of the Espressif macro added-value!
@ruben34
@ruben34 Рік тому
Wouldn't the millis() function be as accurate as this tasks? I recently made a project which had lots of blinking lights, buzzers, and they had to flash at an exact pre-programmed time, I just used millis() and if statements and it is pretty accurate, although I only tested 5min.
@RalphBacon
@RalphBacon Рік тому
Millis() will accurately read the current value but how do you ensure that you accurately execute the function at the right time without constantly checking, and potentially missing, the right time? This method uses no extra resources so your loop() can just do its thing without having to check millis() (I know, I do this all the time, but no more!).
@ruben34
@ruben34 Рік тому
@@RalphBacon Yeah, I have to make sure my code is non-blocking. It just takes a few micro-seconds to run the entire loop.
@LesCollier
@LesCollier Рік тому
Ralph which application / software are you using in your UKposts presentations ? i.e where you appear in person in front of the screen you are talking about
@RalphBacon
@RalphBacon Рік тому
Like just about every other UKpostsr, I use OBS (Open Broadcast System).
@IvoBallie
@IvoBallie Рік тому
It's definitely not a mainstream chip anymore, but it's readily available, in smd, from main stream component suppliers like Digikey, Futurelec, Element 14 etc. , but they are horrifically priced from these suppliers. I used these chips in the late 90's for small scale production and they were reasonably priced at about $2 each.
@RalphBacon
@RalphBacon Рік тому
Even at $2 that's quite a lot. I specifically chose the shift register because it was (and is) dirt cheap. $2 is fine for a hobby project but not for a commercial project; the hardware engineers would expect the software engineers to "compensate" 😂
@youssubernfissi5559
@youssubernfissi5559 Рік тому
Can we still use timer interrupts? If so which timer does the library use so we avoid it ?
@RalphBacon
@RalphBacon Рік тому
AFAIK this does not use any of the timers, per se. It does require that the loop() now invokes the scheduler (several thousand times a second, potentially) and it uses just 15-18μS per pass to do its stuff. So I would expect timers to be available for a developer's use, as long as it does not interfere with the scheduled tasks. It also runs fine in an RTOS environment that is timer driven.
@youssubernfissi5559
@youssubernfissi5559 Рік тому
@@RalphBacon that makes sense, thanks a lot for the clarification and for responding even though the video is a bit old. I really appreciate that, also thanks for all the videos they are both amusing and useful,
@j1952d
@j1952d Рік тому
Presumably this is using the Arduino internal "clock". Is it possible to sync to an external clock eg an RTC connected over I2C? This would be much more accurate.
@MarkFishlock
@MarkFishlock Рік тому
I have projects that sync 'internal' device time to a range of external time devices including a RTC, a NTP server, A php script that outputs time and a GPS module. I tend to 'resync' to these external devices every couple of hours, to ensure relative time accuracy. So the answer is YES
@j1952d
@j1952d Рік тому
@@MarkFishlock I don't use a sheduler, but I have a clock that runs on the Arduino "internal" time, and syncs to an RTC via I2C at 50 mins past every hour. Usually has to adjust by 2 or 3 seconds/hour. I assumed it should be pretty easy, but just checking.
@RalphBacon
@RalphBacon Рік тому
Yes, this will be subject to the accuracy of the crystal on the dev board. I'm going to be using an ESP32 so as an optional extra I will be able to sync the time once a day.
@jstro-hobbytech
@jstro-hobbytech Рік тому
Ralph I have a challenge for you. I want to take a bunch of similar programs and load them into psram on an new esp wroom32d and be able to set up a way to select them. It's a 2 pin program with one pin not being used most of the time. Can that be done or would I have to set up a server and flash the esp Ota. I'd like to use software serial over bt. It's for a project. I can keep a database of compiled working programs and just do an Ota task change or update. I could do this with a pi but I don't want to waste a 3b and an esp32 plus the side loaded controls I have on android. Anyway, let me know if this makes sense or I could tell you my project. It's an led matrix with built in fft and simple games. 2 pins haha 1 for the 16x16 matrix and another for a microphone. You're a sage and I ask you kindly for input
@RalphBacon
@RalphBacon Рік тому
Hmm. You can't actually have multiple programs (sketches) loaded but it they are quite similar maybe you could have multiple _functions_ that do 99.9% of the work with the main loop acting as a reset / select? Then you could select which program (function) to run on each reset? If this is a non-starter, you would have to automate the upload process (yes, OTA would be fine) from your PC / command line.
@jstro-hobbytech
@jstro-hobbytech Рік тому
@@RalphBacon yes! I knew I was missing something. Thank you
@snowboarderdj86
@snowboarderdj86 Рік тому
Does this library manage tasks across both cores of an esp32?
@RalphBacon
@RalphBacon Рік тому
I couldn't find any reference to the core on which a task should run. I assumed that Core 1 would be always be used as Core 0 should not really be touched by developers as it runs all the Espressif-specific stuff (BT, Wi-Fi etc). Any delays in this core causes a PANIC state. You could ask Anatoli, I suppose.
@snowboarderdj86
@snowboarderdj86 Рік тому
@@RalphBacon bummer, I was looking for an easier way to execute important tasks on one core with all my neopixel patterns running on the other. For example, in a certain state I want the neopixel to ‘breathe’ and on event I want to read a bunch of sensors and update LoRa or update a screen etc etc. If the tasks are running on same core you’ll notice the neopixel breathing effect gets paused slightly while the core is handling the other tasks
@RalphBacon
@RalphBacon Рік тому
You could try a task on Core 0 (remember BT and Wi-Fi are intolerant of pauses on that core) which runs continuously for the breathing effect but yields if there is nothing to do. It can still read/give semaphores and mutexes created by tasks on the other core.
@colindejager1250
@colindejager1250 Рік тому
@@snowboarderdj86 Try having a look at how this guy did it...
@mahudson3547
@mahudson3547 Рік тому
Task scheduler - great and as usual, excellently presented. Thanks. BUT using an arduino crystal/resonator as any sort of time keeper - NO! Any long period timing needs better. For a lot less than a coffee, the DS3231 offers stability, compensation, age trimming, battery backup and lots more. And the Chinese modules come with proper EEPROM as well. Why compromise? Yeah, it was only a demo....
@RalphBacon
@RalphBacon Рік тому
Until I found this library I would have agreed with you whole-heartedly. Especially on the Arduino (ESP32 is a special case, of course). But I had this running for a week on the Arduino and it was still keeping excellent time (a few seconds lost). The crystal on the Arduino (not a cheap and inaccurate resonator) is very stable and usually pretty accurate too. Agreed, the DS3231 is the only RTC I would consider, and it's cheap too but it's yet another component to fit and another battery to keep up-to-date. I guess it all depends on what you want to do with your project!
@schufti6706
@schufti6706 Рік тому
sorry to nitpick, but ... 500ms on and 500ms off is a periode of 1s equal to 1Hz NOT 2Hz and btw. this clock is only as accurate as the oscillator on the arduino ... task scheduler does nothing to improve accuracy. I do like your videos none the less and as allways leave a "thumbs up"
@RalphBacon
@RalphBacon Рік тому
I'm glad you like my videos and support me, that's most appreciated. Now, the task to drive the LED on/off is being triggered twice a second so that _must_ be 2Hz, surely? The LED _flashes_ once a second, that's true. I think we are both meaning the same thing in different ways! 😲😂
@schufti6706
@schufti6706 Рік тому
@@RalphBacon if the state is inverted every 500ms, that means during one second 500ms on, 500ms off. compared to AC it is during a period of 1s 500ms positive, 500ms negative, then the cycle repeats --> 1Hz == 1 cycle takes 1s. If it would change state once a second it would be a periode of 2s == 0.5Hz
@mrlarsv
@mrlarsv Рік тому
@@schufti6706 So it’s like this; In the UK 230V voltage is 50 times positive and 50 times negative so net frequency must be 100 Hz ;-) Apart from that Ralph you're videos are great - keep them comming
@FunkySpunkyJunky
@FunkySpunkyJunky Рік тому
@schufti ... no, I'm with Ralph on this one. The task (regardless of what the task does) is being triggered twice per second. That's 2hz. You're focusing on the led. It does an on-off cycle once per second, which is indeed 1hz, but that isn't the point. Ralph is talking about the task and the frequency of that task. The led is just there to provide a visual indication that the task has been triggered. The task could be updating a counter or flushing a buffer, it makes no difference, its still triggered twice per second, and that's 2hz.
@schufti6706
@schufti6706 Рік тому
@@FunkySpunkyJunky ... at 3:57 he talks about the "other task" and that the LED is half a second on and half a second off and calls it 2Hz (compare it to 1Hz rectangle it is similar. AC mains switches polarity 100 times a second and still it is called 50Hz. It is about the period == one cycle, so until the signal is back to its starting state. If you don't believe it, connect the LED to a DSO and check the displayed frequency ...) but I am with you/him if he talked about the task schedule frequency, that could be interpreted as 2Hz - every 500ms it runs for a short time and then sleeps for a longer one, 2Hz with very unsymmetric duty cycle.
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist Рік тому
I expect that you will need a better clock for the arduino as I expect that they don't fit a quality crystal to the boards.
@fredflintstone1
@fredflintstone1 Рік тому
meow!!!!!!!!!!!!!!!!!!!!!!!!!!!
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist Рік тому
@@fredflintstone1 Come on Fred you know you have a Woof in you. 🙂
@fredflintstone1
@fredflintstone1 Рік тому
@@TheEmbeddedHobbyist "O" dear you know you are the woofer 🙂
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist Рік тому
@@fredflintstone1 Well as i've only got 399 subs to go to the 1K, heres a big Woof for you. WWWWoooooooooofffffffffffffff ;-)
@RalphBacon
@RalphBacon Рік тому
Well, I can only report on the device I'm using, a clone Arduino UNO. No drift in a whole week. YMMV and my next project does use an ESP32 so I can sync the time once a day, or whatever.
@c4bombkawysadzi
@c4bombkawysadzi Рік тому
I think that Simpletimer (by Natan Lisowski) is a lot easier to use without this defines and stuff as the name suggests it simplier and works good too
@RalphBacon
@RalphBacon Рік тому
I'm sure it works just fine too.
@livetohash6152
@livetohash6152 22 дні тому
Are millis not that accurate then?
@RalphBacon
@RalphBacon 21 день тому
Well... that depends on what your definition of "accurate" is! If you were to design a simple 24-hour clock and use millis() as the source of the time, you would find it severely out of step with World time by the end of the day. This applies to most microcontrollers that rely on an external crystal for their clock. But for shorter time periods it's accurate enough. Just bear in mind that millis() is not updated whilst an Interrupt Service Routine (ISR) is running, or whenever there's a "nointerrupts()" command (not necessarily in _your_ code but perhaps the Arduino framework itself, or a library you've included). TL;DR for short time periods it's fine. For longer ones, or where the ultimate in accuracy is required, you can't rely on it.
@yogeshitaliya473
@yogeshitaliya473 Рік тому
😍😍🙏🙏🙏😍😍
@RalphBacon
@RalphBacon Рік тому
Quick off the mark, as usual, Yogesh 👍
@c1ph3rpunk
@c1ph3rpunk Рік тому
I love the types: “it’s not accurate to a millisecond and it drifts 200ms a day, it’s not accurate enough!” What are you trying to do, high frequency trading or something? “No, send an email once a day” I’m out.
@RalphBacon
@RalphBacon Рік тому
It depends on what you are trying to do. If you want an accurate pulse to be generated then a drift would not be acceptable (and hardware would be the answer). But otherwise, such as sending an email, it makes no difference which is EXACTLY what I said in the video! Oh, you missed that?
@johnjacobjinglehimerschmid3555
@johnjacobjinglehimerschmid3555 Рік тому
With the prevalence of cell phones. Too bad there isn't a "FREE" way to be able to get the time that I think must be broadcast via cell towers.
@RalphBacon
@RalphBacon Рік тому
Your local cell/mobile phone can certainly grab the time, but it's not free as you have to have a connection to the mobile service. The almost free way is to use your Wi-Fi and contact the NTP (Network Time Protocol) server pools (specified for each geographical area, eg UK, Europe, Oz, USA) which is the way I do it (you'll see this in a future video). Your processor needs to be Wi-Fi capable, of course. Not quite free as you have to have a Wi-Fi connection (and Internet connection from that Wi-Fi) but you probably already have that.
@johnjacobjinglehimerschmid3555
@johnjacobjinglehimerschmid3555 Рік тому
@@RalphBacon Great response ... thanks ... agreed I suppose the wifi method would be inherently more diy friendly and cheaper. Just came across this video clip and I like your style. New subscriber and can't wait to digest some more of your previous videos. Keep up the great work.
@haroldthibault9921
@haroldthibault9921 3 місяці тому
I've been watching your video #208 on ESP32 with "native" FreeRTOS, #BB5 and #BB6 on state machine and how not using Arduinos's delay() function, then another one where youv' re using a taskHelper.h library and then this one about TaskScheduler.h. I was very confused with all these different methods. I understood there are different libraries for the same purpose ( taskHelper.h and TaskScheduler.h). Still one strange thing to me is why TaskScheduler.h is available on ESP32, or why one would use TaskScheduler.h as it seems possible to declare some task without external library as FreeRTOS is running on that chip ? All these possibilities make the route to choose for a project very hard to do for a beginner ! Searching for a timing libraries gives many many choices. Why choose one more than an other ? Beginners have already hard time taking one in hand ! Thanks for your instructives videos.
@RalphBacon
@RalphBacon 3 місяці тому
If it's built-in, use that functionality, at least until you are familiar with it. As you have found, tasks can run very well on an ESP32 without any addition "helper" libraries! Other developers create libraries to make life easier for beginners but sometimes it just abstracts away the very thing they should be learning. It's called _syntactic sugar_ , and sometimes it's a joy to be able to just type in a single statement and have it do umpteen things for you - but what are those things?
#251 8-bit Shift Register for your Arduino's LEDs or 7-Segment Display
19:45
#227 ✨printf for Arduino✨(and ESP32, ESP8266) easy, formatted output
23:02
#244 Multiple tasks on an Arduino?😲FreeRTOS can do it - so can you😜
18:37
All about Cardputer from @M5Stack
15:40
techiesms
Переглядів 25 тис.
#BB4 MOSFETs - From an Arduino Perspective
15:10
Ralph S Bacon
Переглядів 21 тис.
#151 - ESP32 Passing Values 💾 Between Tasks - Deep Dive (2 Easy Ways)
38:38
#328 ESP32 Secrets: Interrupts, and Deep-Sleep under the Hood
18:57
Andreas Spiess
Переглядів 172 тис.
PlatformIO: All you need to know in 10 Minutes!
10:56
J's e-shack
Переглядів 280 тис.
Intro to Hardware Reversing: Finding a UART and getting a shell
12:07
Tony Gambacorta
Переглядів 872 тис.
ESP32 Guide 2024 | Choosing and Using an ESP32 Board
41:06
DroneBot Workshop
Переглядів 207 тис.
#33 Internet of Things with ESP8266 #5: Watchdogs, Timers & Stability
9:17
iPhone 17 Slim - НЕ ОНОВЛЮЙ iPhone в 2024 | Новини Тижня
31:12
Канал Лучкова
Переглядів 36 тис.
🤯Самая КРУТАЯ Функция #shorts
0:58
YOLODROID
Переглядів 3,3 млн
❌УШЛА ЭПОХА!🍏
0:37
Demin's Lounge
Переглядів 317 тис.