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 Жыл бұрын
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!
@OtusAsio2 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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.
@Ron_Rhodes2 жыл бұрын
I use Task Scheduler to dynamically generate tasks of different durations and looping frequencies to blink NeoPixels. Great job Anatoli.
@RalphBacon2 жыл бұрын
Agreed, Anatoli did some very good work here (and updated the library very recently too). Your use of it seems perfect!
@volodimirkun2 жыл бұрын
Sir, this video is timed perfectly! Having a project going right now ,which i will use this lib right away! My regards from Ukraine.
@RalphBacon2 жыл бұрын
Perfect! I am using this in a new project too!
@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 Жыл бұрын
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! 👍
@veedonfleece36942 жыл бұрын
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
@RalphBacon2 жыл бұрын
Thanks for sharing! Great that you're finding value in these videos 👍
@tim_bbq10082 жыл бұрын
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!
@RalphBacon2 жыл бұрын
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.
@Trust_me_I_am_an_Engineer2 жыл бұрын
Thanks so much for finding this scheduler and making the video, Ralph! Especially since it runs on different boards. Love your videos!
@RalphBacon2 жыл бұрын
My pleasure! Yes, I've now got it running on an ESP32, part of my next project research! Runs great.
@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 Жыл бұрын
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!
@Taran7211 ай бұрын
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).
@RalphBacon11 ай бұрын
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).
@Taran7211 ай бұрын
@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.
@WatchTomDotCom2 жыл бұрын
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!
@RalphBacon2 жыл бұрын
Sounds great! Yes, I think Anatoli has produced a great bit of functionality with this library.
@qzorn44402 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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 👍
@jeffbluejets26262 жыл бұрын
Brilliant......and here I was thinking RTC was the only accurate way to make a clock based unit.
@RalphBacon2 жыл бұрын
Me too. Except this really surprised me.
@jyvben15202 жыл бұрын
looking forward to more implementations of the task schedule system ... looks good.
@RalphBacon2 жыл бұрын
Yes, I agree.
@TheMrDrMs11 ай бұрын
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.
@RalphBacon11 ай бұрын
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!
@keitholiver39812 жыл бұрын
Very interesting topic, worth further investigation, many thanks
@RalphBacon2 жыл бұрын
Definitely worth some (in depth) reading, especially his examples. That's what I'm doing!
@Poult1002 жыл бұрын
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
@RalphBacon2 жыл бұрын
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).
@baconsledge Жыл бұрын
Thanks Ralph, anxious to try this!
@RalphBacon Жыл бұрын
Best of luck! I've used it since in a "real" project, works just fine. Considering whether it will work on my ESP32.
@tseckwr3783Ай бұрын
Ralph, thanks.
@RalphBaconАй бұрын
My pleasure!
@cyberphox19 ай бұрын
Really love your channel and how you teach
@RalphBacon9 ай бұрын
I appreciate that! 👍
@scottstevens75692 жыл бұрын
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.
@RalphBacon2 жыл бұрын
Ideal project to add this to, exactly for the reasons you mention.
@scottstevens75692 жыл бұрын
@@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.
@ForwardGuidance2 жыл бұрын
Meow Ralph, Great stuff here Ralph. You really know how to get in the weeds and figure things out.
@RalphBacon2 жыл бұрын
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.
@gregwmanning2 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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!
@gregwmanning2 жыл бұрын
@@RalphBacon Maybe the average crystal is pretty accurate? Good luck with the good luck!
@RalphBacon2 жыл бұрын
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?
@gregwmanning2 жыл бұрын
@@RalphBacon Without looking my guess would be ceramic resonator, because the are smaller and cheaper than a metal can crystal.
@simonabboud59872 жыл бұрын
Always enjoy your videos
@RalphBacon2 жыл бұрын
I appreciate that! 👍
@alnoorratansi93642 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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).
@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 Жыл бұрын
Quite so. That would be a perfect use of another task. Build, run, forget about it.
@IvoBallie2 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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?
@IanSlothieRolfe2 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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.
@DaveGWIS2 жыл бұрын
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.
@DaveGWIS2 жыл бұрын
... 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.
@RalphBacon2 жыл бұрын
@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.
@RalphBacon2 жыл бұрын
@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).
@DaveGWIS2 жыл бұрын
@@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 🤭
@DaveGWIS2 жыл бұрын
@@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. 😁👏
@benedicteJacobsen9 ай бұрын
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.
@RalphBacon9 ай бұрын
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.
@BersekViking2 жыл бұрын
Nice demo! :)
@RalphBacon2 жыл бұрын
Glad you think so!
@jkRatbird8 ай бұрын
About libprintf: what’s the benefit over doing Serial.println(“value: “ + String(value)) ?
@RalphBacon8 ай бұрын
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).
@PeteTheProps2 жыл бұрын
Another great piece of coding help thank you.
@RalphBacon2 жыл бұрын
Glad it was helpful!
@IvoBallie2 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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" 😂
@fscherz2 жыл бұрын
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(...)!
@RalphBacon2 жыл бұрын
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!
@danielroibert56312 жыл бұрын
Very interesting. Thank you.
@RalphBacon2 жыл бұрын
Glad you enjoyed it!
@schufti67062 жыл бұрын
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"
@RalphBacon2 жыл бұрын
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! 😲😂
@schufti67062 жыл бұрын
@@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
@mrlarsv2 жыл бұрын
@@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
@FunkySpunkyJunky2 жыл бұрын
@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.
@schufti67062 жыл бұрын
@@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.
@DesertVox2 жыл бұрын
You have to have a separate RTC chip to ensure real accuracy with 'no' drift.
@RalphBacon2 жыл бұрын
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.
@hopje012 жыл бұрын
Best to check if your Arduino board uses a crystal for the processor. There are boards that are using ceramic resonators.
@philipreed27582 жыл бұрын
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
@RalphBacon2 жыл бұрын
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.
@greg43672 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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.
@warperone Жыл бұрын
love your videos
@RalphBacon Жыл бұрын
Thanks, appreciated 👍
@mrtom642 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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).
@alexrossouw77022 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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.
@mahudson35472 жыл бұрын
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....
@RalphBacon2 жыл бұрын
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!
@LesCollier Жыл бұрын
Ralph which application / software are you using in your KZbin presentations ? i.e where you appear in person in front of the screen you are talking about
@RalphBacon Жыл бұрын
Like just about every other KZbinr, I use OBS (Open Broadcast System).
@Dad-ij2qy2 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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!
@ruben342 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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!).
@ruben342 жыл бұрын
@@RalphBacon Yeah, I have to make sure my code is non-blocking. It just takes a few micro-seconds to run the entire loop.
@j1952d2 жыл бұрын
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.
@MarkFishlock2 жыл бұрын
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
@j1952d2 жыл бұрын
@@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.
@RalphBacon2 жыл бұрын
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.
@MPElectronique2 жыл бұрын
I use this library as well..
@RalphBacon2 жыл бұрын
Excellent. Do you find it good?
@SpinStar19562 жыл бұрын
This was mildly entertaining! 🤣😂🤣
@RalphBacon2 жыл бұрын
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! 😁😁
@TheEmbeddedHobbyist2 жыл бұрын
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.
@fredflintstone12 жыл бұрын
meow!!!!!!!!!!!!!!!!!!!!!!!!!!!
@TheEmbeddedHobbyist2 жыл бұрын
@@fredflintstone1 Come on Fred you know you have a Woof in you. 🙂
@fredflintstone12 жыл бұрын
@@TheEmbeddedHobbyist "O" dear you know you are the woofer 🙂
@TheEmbeddedHobbyist2 жыл бұрын
@@fredflintstone1 Well as i've only got 399 subs to go to the 1K, heres a big Woof for you. WWWWoooooooooofffffffffffffff ;-)
@RalphBacon2 жыл бұрын
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.
@youssubernfissi5559 Жыл бұрын
Can we still use timer interrupts? If so which timer does the library use so we avoid it ?
@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 Жыл бұрын
@@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,
@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 Жыл бұрын
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?
@c4bombkawysadzi2 жыл бұрын
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
@RalphBacon2 жыл бұрын
I'm sure it works just fine too.
@jstro-hobbytech2 жыл бұрын
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
@RalphBacon2 жыл бұрын
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-hobbytech2 жыл бұрын
@@RalphBacon yes! I knew I was missing something. Thank you
@snowboarderdj862 жыл бұрын
Does this library manage tasks across both cores of an esp32?
@RalphBacon2 жыл бұрын
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.
@snowboarderdj862 жыл бұрын
@@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
@RalphBacon2 жыл бұрын
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 Жыл бұрын
@@snowboarderdj86 Try having a look at how this guy did it...
@livetohash61526 ай бұрын
Are millis not that accurate then?
@RalphBacon6 ай бұрын
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.
@johnjacobjinglehimerschmid35552 жыл бұрын
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.
@RalphBacon2 жыл бұрын
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.
@johnjacobjinglehimerschmid35552 жыл бұрын
@@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.
@yogeshitaliya4732 жыл бұрын
😍😍🙏🙏🙏😍😍
@RalphBacon2 жыл бұрын
Quick off the mark, as usual, Yogesh 👍
@haroldthibault99219 ай бұрын
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.
@RalphBacon9 ай бұрын
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?