Тёмный

How to use Timers on the RPi PICO 

Making Stuff with Chris DeHut
Подписаться 10 тыс.
Просмотров 16 тыс.
50% 1

Timers are very simple devices on the Raspberry Pi PICO but they can help you do so much more with your programs and they do it VERY efficiently. Covered in this video are: What they are, uses, types and more. Program examples for both types timers are provided and explained in great detail.
VISIT OUR COMPANION WEBSITE -- makingstuffwithchrisdehut.com
DOWNLOAD FILES HERE -- makingstuffwithchrisdehut.com...
SOURCED ITEMS USED IN SOME OF THE VIDEOS
10 pcs Seven Segment LED display amzn.to/37lv21R
2 pcs Bar Graph LEDs amzn.to/3LIevno
3 pack of breadboards amzn.to/3oAkK3H
200 pc assortment of LEDs amzn.to/3JfLQVc
450 pc assortment of LEDs amzn.to/3sr1vKL
38 value / 1200 pcs resistor assortment amzn.to/3Llxq8k

Наука

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

 

6 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 58   
@norbertbans
@norbertbans Год назад
Well explained and for the like and subscription well deserved!!! Thanks for this simple but very good demo!!!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Thank you very much Norbertbans! I really appreciate the feedback and kind words - happy programming!
@abdontroche
@abdontroche 10 месяцев назад
Thank you for the explanation! It helps me a lot!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 10 месяцев назад
Glad it helped! Cheers! Chris
@skf957
@skf957 Год назад
Very nicely presented, thank you. Just checked out your channel after watching a couple of your Pico vids. I'm a big Pico fan from when it was launched here in the UK in early '21. I was going to subscribe on the basis of the Pico content alone, but was then amazed to see that you share another passion of mine - woodworking! I'd got to the stage of combining the electronics stuff with some of my woodworking projects when a change in my circumstances meant that all of my machines are now in storage. Hopefully not for too much longer. Meantime I'll binge on your vids. Good luck with the channel.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Thanks for the feedback! I certainly hope things improve for you so you can bring your shop back to life!!!!
@peterwest1158
@peterwest1158 11 месяцев назад
Thank you for the info on timers and IRQ handling. Looking forward to your eventual updates.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 11 месяцев назад
Glad you liked the videos. I have plenty more videos coming up. Cheers! Chris
@aligurbuzoglu5181
@aligurbuzoglu5181 2 года назад
Thank you very much for your workshoop so it was very helpful
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 2 года назад
Thank you for watching and for the feedback! Be sure to let others know about this channel.
@andreasgerth3654
@andreasgerth3654 Год назад
I think this basic explanation for beginners is very well done. Only now from the point of view of those who want to write more complex routines or are approaching the RAM limit, you shouldn't be so wasteful with it. You don't have to first import the "machine" library as a whole, and then import individual components like the "timer" again separately. This can be greatly reduced by summarizing all of them with "from machine import Pin, Timer", the same applies to "utime". I would also like to note that the Python directive states that no subfunction accesses global objects of the MAIN. So it looks like this, and would also simplify subsequent improvements / extensions. def blink(pin): [tab]pin.toggle() the timer itself comes with: Blue_Timer = Timer(period = 2_000, mode = Timer.PERIODIC, callback = lambda t: blink(blue)) Instead of then, as shown later, because the function content is always the same, you can save yourself these 3 additional subprograms / functions by only assigning a different PIN for Timer-Init. A blink function is then sufficient for this to toggle several different LEDs on different GPIOs.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Hi andreasgerth, Thanks for sharing that great information. I admit, my code if often not "pythonic" or even efficient as it is often developed with the sole purpose of explaining a specific topic. In an upcoming project series, it is looking like I will be pushing the limits on memory capacity for the PICO and will need to be VERY aware of memory waste on that project! If you don't mind, when I get into that project, can I reach out to you for advice and suggestions? Cheers! Chris
@mikeg3660
@mikeg3660 Год назад
Good stuff … subscribed
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Hi Mike, Welcome, I am glad you like what you see and have subscribed! Just a heads up, I was going over my "to do" list of videos I will be shooting and I have about 50 more planned around the PICO. I am confident that in a year from now, I will think of 50 more things to film about it too. Cheers! Chris
@rodrigodemarchi1184
@rodrigodemarchi1184 Год назад
Nice video, thanks for it.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Thanks for watching! Much appreciated.
@rafaelrobles2335
@rafaelrobles2335 Год назад
nice video!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Rafael, thank you very much for the feedback- much appreciated! Cheers!
@TheUnofficialMaker
@TheUnofficialMaker 3 месяца назад
good stuff
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 3 месяца назад
Thank you for the kind words! Cheers! Chris
@jimcraig5727
@jimcraig5727 2 года назад
Another well done video/tutorial Chris. The word "Source" in the functions parameter brackets baffled me for a bit until I figured out its just a word, holding a place for the period value in the Timer function. Correct me if I'm wrong. I need to get a better understanding of functions probably.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 2 года назад
Hi Jim, That is the Source of where the interrupt came from, in this case a timer. I will need to do a video on explaining that because it is a bit tricky to understand depending on the type of interrupt.
@henkoegema6390
@henkoegema6390 6 месяцев назад
👍
@VoeViking
@VoeViking 2 года назад
Coming from Arduino ide to micro python, thanks for your help. Will check your other videos.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 2 года назад
Hi VoeViking! Thanks for stopping by and glad you found some value in the form of help.
@Steven-jf4cs
@Steven-jf4cs 7 месяцев назад
Great tutorial! Similar to the 'pumper timer' example, could I also call the Timer mode ONE_SHOT from inside a function to then execute a general cleanup/shutdown process, e.g., xyz.deinit(), pin.value(0), etc. I'm positive it could but wanted your input if this is an acceptable practice. Thanks again!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 7 месяцев назад
Hi Steven-jf4cs, I am glad you enjoyed the video! Regarding your question, I don't have an opinion if it is acceptable or not. To start with, give it a go and if it works, that is pretty convincing to me that you can use it. Unfortunately, what is and is not acceptable can be debated by many from different points of view. The Python purists really get demanding that everyone must do things one very specific way even though dozens of other ways will yield the same result. For professional programmers, it is very important to follow consistent guidelines regarding practices and syntax etc so that all the team members can work on the same code. In the "wild west" of DIY, I follow much less strict rules, if it works great, if not, keep experimenting until it does. Cheers! Chris
@robjr657
@robjr657 Год назад
Really enjoyed this video... I hope you continue doing more videos about the pico. I do have 1 question for you... If you import the machine library, why then do you have to import the timer from the machine library again? I quite new to this and don't understand why this is required... Thanks!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Hi OpenEye, I must have had a bad day when I did that example! from machine import Timer is appropriate and the other import is not needed - probably just habit. I would certainly love to keep doing more videos but I must admit, I am unable to gather a large enough audience. While I certainly don't do this for a living, it would be great if it would cover the costs of the materials used and right now these videos can't even pay for a Pico - LOL.
@ramsesramirez1910
@ramsesramirez1910 10 месяцев назад
Very good explanation! Thinking about corner cases where two or more timers are triggered at the same time. Is that even possible? Could there be a chance of a race condition or maybe one of the interrupts don't get called? Thanks!
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 10 месяцев назад
Hi @ramsesramirez1910 Having been around microcontrollers for about 2 decades, the one thing I am certain of, strange things are possible. As for a race condition, I am not sure on that. I recall reading in the docs that this is somehow prevented but can't recall the details at this time. Unfortunately I don't have the time right now to dig into it deeper. Chris
@helmutzollner5496
@helmutzollner5496 Год назад
Interesting! Would you implement a PWM with a timer? I guess you could always use a recurring to switch on the signal and a one-shot to switch it off. But would a millisecond timer be fine enough for that for let's say audio?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
I don't think you would get the results you desire using a timer to generate the PWM signal. I would stick with the traditional means for generating PWM signals. Chris
@nomosapplication
@nomosapplication 8 месяцев назад
thx for a great tutorial, now functioning right here on my r.pi. i am trying to import a timer that opens a number of pins, each for their own (x) sec, closes for each their (y) sec, for the entire given period - instead of blinking in even intervals - and then onwards to the next of in all 12 periods, before it loops to the first period - but apparently micro python does not yet incorporate this function. do i have to transfer to c+, or what is your take on this one?
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 8 месяцев назад
GLad you liked the video. I am sure that could be coded in python, but I am not aware of any such existing function to do that. Chris
@garystout4300
@garystout4300 Год назад
Great video Chris! I have a question and maybe you can point me in the right direction. I have setup a pico with a LCD and RTC, which basically runs as a clock and date display. I would like to have an event or relay trigger at a preset start time and continue until a preset stop time. My gola is to have 2 relays turn on/off at preset times. The clock is running great but I am not sure how to proceed with allowing it to control some events. So to summarize, say I want relay #1 to turn on at 8am and then shutoff at 5pm.....any thoughts or libraries available to use to do something like this? Thanks, Gary
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Hi Gary, I suspect what you want to do is pretty straight forward. Currently I am swamped with real-life work but hope to get back to video production later this fall and I think I should do a video on that as it would tie together a few things. Sorry I can't code it up quick for you, I just don't have much "fun time" these days with being so busy at my regular job. Cheers!
@garystout4300
@garystout4300 Год назад
@@MakingStuffwithChrisDeHut thanks Chris! I think I figured it out. I found some code for an alarm clock that would sound a buzzer. Instead of the buzzer, I was able to create 2 separate timers to fire off at set times and 2 more timers to turn off at set times. The on/off times are set in the code but for an in-house project, it will do the trick. It really wasn't as hard as I thought it might be, but I am still learning micro python as well. Thanks again, Gary
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
@@garystout4300 AWESOME! Glad to hear you got it working - that is the fun of playing with Microcontrollers.
@bradychen7980
@bradychen7980 2 месяца назад
I was trying to set the timer frequency to 20MHz, however the code seemed to stop working at 125KHz, I was wondering if that’s the limit of the machine.Timer class
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 2 месяца назад
That is a very high frequency to get using MicroPython. Cheers! Chris
@loadlinetubes
@loadlinetubes 11 месяцев назад
Hi, Is there a way to improve timers accuracy, e.g. 0.1 ms?... Thank you.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 11 месяцев назад
Hi loadlinetubes , I was recently told that MicroPython can now use the hardware timers on the PICO instead of software timers. However, I just reviewed the MicroPython documentation that still states the hardware timers are not implemented. I suspect that the accuracy issues are related to a software implementation and until the hardware timers are implemented accuracy will suffer. Chris
@loadlinetubes
@loadlinetubes 11 месяцев назад
@@MakingStuffwithChrisDeHut ho Chris, thank you very much for your kind and quick reply. Daniele Colombi
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 11 месяцев назад
Out of curiosity, what are you trying to do with the timers?
@loadlinetubes
@loadlinetubes 11 месяцев назад
@@MakingStuffwithChrisDeHut this will be the very 1st time I'll use RB Pi Pico. I woukd like to read, calculate and show on 4 digits display the BPM (Beats per minute) from a 555 based metronome, this for my son Tommaso, 11 Years old, studying acoustic Guitar 😊 I've already planner everything and I need to know some details to measure the time between two "ticks", used to calculate the BPM.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 11 месяцев назад
@@loadlinetubes On the PICO, I use this bit of code to measure time of an event (or between events). CT_St = time.ticks_us() #TIME MEASURE the code you are trying to measure is here CT_Et = time.ticks_us() print(time.ticks_diff(CT_Et, CT_St)) This is microsecond accurate and may help. Cheers!
@gedtoon6451
@gedtoon6451 Год назад
Good video but now a little out of date. Micropython has supported the Pi Pico hardware timers since version 1.8.5 and the current version is 1.20.0 You can still use the software timer you refer to in this video, but you define it as Timer(-1).
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Hi gedtoon6451, That is GREAT NEWS! I would certainly like to get a re-visit video done regarding this. By chance do you have a link to the docs on this? Thanks for the update and sharing it. Cheers! Chris
@gedtoon6451
@gedtoon6451 11 месяцев назад
My bad! I must have been looking at documentation for a different microcontroller. When I checked the latest docs for the pi pico, it still says only software timers are available. Sorry for that.
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 11 месяцев назад
No Worries my friend. Thanks for sharing and updating the information. Cheers! Chris@@gedtoon6451
@apanoiu
@apanoiu 5 месяцев назад
I suggest using micropython and asyncio. Rendering most timers useless
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut 5 месяцев назад
Thanks for that information. Could you share a bit more detail about it, perhaps and idea of what asyncio does or how it works? Cheers! Chris
@gwynsea8162
@gwynsea8162 Год назад
Be interesting to know what's going on under the hood with timers. And what happens if you have multiple timers that go at different times - what if one is in progress when another is ready? The documentation is... err... incomplete (polite) crap (factual)
@MakingStuffwithChrisDeHut
@MakingStuffwithChrisDeHut Год назад
Hmm, that is interesting and would be helpful for all to know. I believe we can somewhat answer that question with some sample programs and observing the behavior. Hopefully I can fit this into the next filming schedule. Thanks for the feedback!
Далее
E003 Using Rotary Encoder Switches on the Raspberry Pi
15:58
Let's Get Started with the PICO W
19:40
Просмотров 8 тыс.
Using PICO Interrupts
25:15
Просмотров 18 тыс.
Saving Data Inside the PICO
13:11
Просмотров 8 тыс.
Pi Pico W with the Arduino IDE | Using WiFi
49:26
Просмотров 149 тыс.
Raspberry Pi Pico: Inputs & Servo Control
17:20
Просмотров 131 тыс.
Самая редкая видеокарта NVIDIA
1:00
Лучший браузер!
0:27
Просмотров 1,1 млн
Проверил, как вам?
0:58
Просмотров 378 тыс.