Тёмный

MicroPython #4 - PWM, ADC, Timers & Interrupts 

Unexpected Maker
Подписаться 25 тыс.
Просмотров 37 тыс.
50% 1

#MicroPython #esp32 #tutorial
It's no secret I like MicroPython... and MicroPython on the ESP32 is amazing, so I decided to start a video series about MicroPython.
In this episode I start to look at working with the ESP32 hardware like interrupts, timers, PWM and ADCs
Callbacks in MicroPython for interrupts and timers are ISRs, and have some limitations and consequences in their use. Check this link for a detailed guide:
docs.micropython.org/en/lates...
[ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ]
If you'd like to support me on my journey, please consider buying one of my products on tindie
www.tindie.com/stores/seonr/
or becoming a Patron at
/ unexpectedmaker
★ Subscribing, Liking and Sharing my videos really makes a difference. If you are not subscribed, please consider it and then click the alarm button to be notified when I release new videos. Thanks!
★ FOLLOW ME
/ unexpectedmaker
/ unexpectedmaker
/ unexpectedmaker

Наука

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

 

5 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 79   
@capiberra4118
@capiberra4118 4 года назад
A brilliant and valuable set of tutorials. Thanks!
@TheOleHermit
@TheOleHermit 5 лет назад
Great video! Over the past few months, I've jumped from RPi3B+ to ROCK Pi 4B (Linux troubleshooting above my knowledge level), Nano, Nano-RF, ESP8266, Teensy 3.6, and Particle Photon. The learning curves and variations have been overwhelming to integrate into a WiFi network of IoT devices. After watching several videos from Adafruit (micro Python) & the 'guy with the Swiss accent', I've finally come home to roost with an M5STACK and an ESP32 WROVER dev board. What a trip! Suddenly, techie world has become much more simple and far less frustrating. Based upon seeing this video, looks like you will close many of my knowledge gaps, so I'm subscribing and starting at the beginning.👀 Thanks for sharing the basics so eloquently.😎
@damianzelazny5785
@damianzelazny5785 3 месяца назад
Awesome stuff, many thanks!
@MarioSDetroit313
@MarioSDetroit313 2 года назад
I appreciate this tutorial series... I've actually been using esp32's with arduino and esphome for a while now but I started on python when I learned how to program. I'm actually kind of happy this is a thing now I feel much more at home coding in python then c++ or arduino c++.
@davidmc105
@davidmc105 2 года назад
Mate, this series is superb. I have programmed in Python before, though not a lot and it was a while ago. I wished I 'd found it sooner, I would have used it a lot more. I haven't had the need the last few years so this is an awesome refresher for me as well as being a great introduction to micro python which is what has brought me back to python. I like that these are bite size tutorials. Whilst they may be a bit much for a newbie, it's easy to play again and pause when need be and I expect newbies will come back again and again to check how things work when they need. I'm enjoying the journey.
@UnexpectedMaker
@UnexpectedMaker 2 года назад
Cheers David!
@BenjaminEggerstedt
@BenjaminEggerstedt 4 года назад
I just recently discovered your channel and I really like your content. I now want to review something around the hardware-timer-based function and will share my finding here hopefully later today.
@BenjaminEggerstedt
@BenjaminEggerstedt 4 года назад
Ok, I was able to confirm my suspicion - which is positive in this case ... ;) The hardware-timer that you introduced in this video is even working while the REPL is blocked with something else e.g. a time.sleep(5). I kind of expected that, but I wasn't sure - now I am. Cool stuff! My LED is blinking a friendly "Thank you and stay healthy during those difficult times!" :)
@nwjlions
@nwjlions 4 года назад
This video really helped me get started with micropython. Thank you 🙏
@UnexpectedMaker
@UnexpectedMaker 4 года назад
Awesome, thanks for letting me know!
@SantiagoPerez-nm1fm
@SantiagoPerez-nm1fm 5 лет назад
Hey UM, I never comment here, but I had to this time: Great video, highly didactic but not condescendent, and it has a fast rhythm. That's the way to go with any online tutorial, show them the way. Thanks a bunch, mate, you've got a few beers on me whenever you visit Madrid.
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Thanks heaps Santiago!
@paulrautenbach
@paulrautenbach 5 лет назад
Good clear tutorial again. Thanks. MicroPython does look easy to use.
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Thanks Paul. Yeah I am constantly surprised by how easy and intuitive it is to code in. Loving it!
@Magic-Smoke
@Magic-Smoke 5 лет назад
Very nice Seon. I really don't now much Python but you're making it look easy!
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Cheers John! I still don't know much about Python/MicroPython but I'm learning as I am teaching!
@AJB2K3
@AJB2K3 5 лет назад
Nice, I'm learning lots!
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Glad to hear Adam! Me too!
@andymouse
@andymouse 5 лет назад
I'm loving this Seon...cheers!
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Cheers mate! How's your coding going? Got any progress to share?
@andymouse
@andymouse 5 лет назад
@@UnexpectedMaker nope, not a sausage to share sadly, Ive played with neopixel, (always fun) but progress is steady and as soon as I finish "Doom" on my ESP8266 you'll be the first to no !
@garyrowlands8537
@garyrowlands8537 4 года назад
Man I love these videos of yours.. I just wanted to mention that I go through everything you do step by step and interestingly when I do the (stra is strb) part of the video... I get True as I do with (stra == strb) the only thing I did differently :D was stra = ( "hello" ) strb = ( 'hello' ) But I got True with the is version and the == even the id() gives the same location Im using ESP32, rshell , repletc etc just like you Please keep up the great work you are doing you have saved me and so many others thousands of hours in total I am sure :)
@ericwertz4398
@ericwertz4398 4 года назад
The difference in the "is" behavior could be implementation/version dependent. I believe that, by definition, "is" returns true if the two id()s are the same. "is" is supposed to only be for checking to see if the two objects being compared are (pointing to) the same object. As you noted, by virtue of id() returning the same value, they are referencing the same object. The reason why Seon's "is" demo results are different than yours could be changes in the implementation between whatever version and his. If you remember/know, Python strings are immutable, so in cases where the runtime makes the effort to see if there's already a string with the same value ("hello" in stra, in this case), it's safe for strb to also point to it, because it can't be changed through any references to stra. An implementation may choose to create another copy of "hello" in memory for strb and point to it, rather than double-teaming the perfectly valid/safe copy of "hello" made first for stra. This is a memory optimization --at the expense of looking for a usable, equivalent string with the same contents at object-creation time. Bottom line, this implementation-dependent "is" comparison is unreliable, for just this reason. "is" should only be used to compare two object references where one reference was derived from the other. For example, a technically correct demonstration of is would be: stra="hello", strc="foo", if (blah): strb=strc, ..., strb=stra, stra is strb -> True. The results of "is" for Seon's demonstrated case are either undefined in the language definition, or the semantics changed from one version to the other (unlikely). So, technically doing what Seon did in his demo is demonstrating a case of undefined behavior per the language spec (if my suspicion/explanation is in fact correct).
@popviz3316
@popviz3316 3 года назад
Same, somehow micropython is noticing that my two strings contain the same text so is optimising them to a single object. >>> stra = "hi" >>> strb = "hi" >>> (stra == strb) True >>> (stra is strb) True >>> inta = 1 >>> intb = 1 >>> (inta == intb) True >>> (inta is intb) True >>> id(stra) 4410 >>> id(strb) 4410 >>> id(inta) 3 >>> id(intb) 3 >>>
@TheDefpom
@TheDefpom 5 лет назад
You are making me tempted to try that language, I don’t do a lot of coding though, usually just micro controllers from the Arduino IDE
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Hahahaha! Don't feel any pressure to try it out ;)
@HariWiguna
@HariWiguna 5 лет назад
Great job Seon! I'm now using rshell too. Although PyCharm has a nice way to upload, it locks the com port so I can't repl without closing windows. I still use PyCharm to edit, but I use rshell to upload the file and ocassionally invoke repl from rshell. Best of both worlds in one place. Now, someone needs to turn rshell into an IDE!
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Ha! rshell really rocks... esp using rsync. I have that on my list of things to showcase, and VCS + rsehll removes the need for any other IDEs ;)
@stormbytes
@stormbytes Год назад
Thanks!
@stormbytes
@stormbytes Год назад
You spend a good deal of time recording and editing these outstanding tutorials. Have a cup of java on me!
@barbasbandas6665
@barbasbandas6665 3 года назад
Hey just found your channel and it has a lot of quality! Do you have any video about the Arduino Portenta H7 comming up? Thanks and greetings from Portugal
@dannyboland1363
@dannyboland1363 5 лет назад
Great series. Really clear and easy to follow. Any plans to do video on working with SD Cards in MicroPython?
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Thanks Danny. I have a lot of more general stuff to cover still before I look at specific things like that.
@thalesmaia6607
@thalesmaia6607 4 года назад
You make things look easy. I'm intending to use ESP32 for machine control. It seems that complementary Pwm pins are not implemented. Any suggestion?
@hene6539
@hene6539 5 лет назад
My pyboard just arrived. I'm glad that you have done these very good videos! I set up VSC first time a week ago to my arduino. I'm fairly new to this stuff. What kind of extensions you use in VSC?
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Woohoo, you got a PyBoard D? Damien has made an amazing board! I'm just using the Python extension in VSC and rshell to talk to my TinyPICO.
@hene6539
@hene6539 5 лет назад
@@UnexpectedMaker Unfortunately this pyboard V1.1 is not genuine. But now that I looked his website, the D version seems pretty good! My long time goal is to make a model rocket flight computer. I'm fairly new to programming so this micropython looks like easier way to do that compared to c++. It would be awesome to make thrust vector control to gimbal the motor from accel/gyro data.
@PicoGirl
@PicoGirl 3 года назад
And how do you change the resolution? Is it somehow wasting 65535 points of resolution by locking it on to the 1ms increment of the period?
@ofsanjay
@ofsanjay 5 лет назад
Those who learn new thing please like his video thanks for this video
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Thanks!
@shanmuganathanca245
@shanmuganathanca245 5 лет назад
Thanks, nice video! Appreciate your efforts! Can we use the standard ESP32 board with all features covered by micro Python?
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Thanks! Yup, any ESP32 board will work, though without the extra PSRAM like on the TinyPICO, you'll only have about 120KB, but that's enough for a lot of stuff.
@Omarbg95
@Omarbg95 5 лет назад
Dude i totally need to buy a ESP32, one question what are the limits on the frequency of the PWM (can it go up to 30k or above?) and is 512 the max value of the PWM?
@666JackTheKnife666
@666JackTheKnife666 5 лет назад
How would you bind a bluetooth keyboard to the esp32 with micropython ?
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
No idea mate, sorry. Google is a better place to answer questions for niche stuff like that. Cheers.
@MicheleHjorleifsson
@MicheleHjorleifsson 5 лет назад
the machine library, since machine dependent, would have the correct resolution of the adc provided by the board correct ? I.e. some of the teensy boards have 16bit adc vs the 10bit arduino vs the 12 bit esp32
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Yes, the machine module in each hardware port uses the correct default ADC resolution for its hardware, but it's a lot more complicated than that. The ESP32 has a sliding resolution that you can change, and though it might default to 12bit, (0-4095) it's only a 0v-1v range, so if you change the range to 0-3.3V, you lose resolution. It's the same with PWM, if when you change the frequency, your available duty cycle range is altered too. Both of these topics were beyond the scope of this video as they really require people to read and understand the capabilities of the hardware.
@MicheleHjorleifsson
@MicheleHjorleifsson 5 лет назад
@@UnexpectedMaker thamks for the adc info and the map function. The adc info is disappointing though I could use a voltage splitter to knock down the incoming signal. Sensors I use are normally 0-4.8v
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Yes, a voltage divider is all that is needed to convert 0-4.8v to 0-1v.
@ericwertz4398
@ericwertz4398 4 года назад
@@MicheleHjorleifsson uh... depends on your resistor value choices. Using an op-amp could be a better solution, unless you understand what all of the impedances involved are. But for some/many cases a voltage divider might be just fine.
@SantiagoPerez-nm1fm
@SantiagoPerez-nm1fm 5 лет назад
When would you use a time.sleep() based function to make a timer and when a hardware Machine.Timer()? What are the advs and disadvs? Thanks
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Well, like in c++ delay(), time.sleep() or time.sleep_ms() are blocking calls, so they halt all execution during the sleep. If you code is ok with being halted like that, a simple sleep() is fine, but of you need things to happen in a periodic fashion without halting execution of the rest of your code, timers are perfect.
@SantiagoPerez-nm1fm
@SantiagoPerez-nm1fm 5 лет назад
Makes perfect sense. Thank you!
@aleXelaMec
@aleXelaMec 5 лет назад
Very very very big thanks!!?? Does it work with eeprom? And how to autostart py?
@paulo.galvao
@paulo.galvao 3 года назад
you have to create a boot.py, and press the botton boot... Use Thonny is much more easy.
@AndruRomin
@AndruRomin 3 года назад
I'm using a esp8266 from Amazon. When I type in the "Timer.init" PyCharm is telling me its not a method, I have timer imported and its within the scope. I think i'll reimport the library on to the board itself with upip. Even when I look at the library it doesn't have a init method but does have a deinit. Anybody else have this issue?
@AndruRomin
@AndruRomin 3 года назад
Well, I figured it out...I thought what the hell let me try running this through REPL and see if it's crashing. It's not, just PyCharm. Ignored the error and up and running.
@clownzfeet
@clownzfeet 4 года назад
Thank you . I enjoying learning from you tutorials. I have a new shiny TInyPICO. But when I try to run things im getting alot of message that the library is not available.( not the right terms ) . prntscr.com/pfsagm any idea on adding all the necessary libraries. or should i install a new copy of micropython?
@UnexpectedMaker
@UnexpectedMaker 4 года назад
Yay for your new TinyPICO! MicroPython deliberately doesn't ship with every library built into the firmware... or it would be bloated with stuff most people don't need. You need to add the libraries you need to the filesystem on the TinyPICO to use them. Check out github.com/tinypico/tinypico-micropython for examples and libraries
@clownzfeet
@clownzfeet 4 года назад
@@UnexpectedMaker OK, this makes since. Still new to this. That worked Thank you
@MicheleHjorleifsson
@MicheleHjorleifsson 5 лет назад
maybe a good idea to show the mp equivalent of the map command for the ADC i think.
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
There is no Map command in MicroPython, but a map is simply this... def valmap(x, in_min, in_max, out_min, out_max): return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
@n9583
@n9583 3 года назад
Can you make a tutorial on how to code micro python on vscode and upload it?
@sebasleyva4521
@sebasleyva4521 5 лет назад
hi, i would like learn how do to connection with a api using HTTPS
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Soon :-)
@riordanpelayo9996
@riordanpelayo9996 5 лет назад
How can I change between Pull up, Pull Down or No Pull?
@UnexpectedMaker
@UnexpectedMaker 5 лет назад
Pin.IN, Pin.PULL_UP, Pin.PULL_DOWN docs.micropython.org/en/latest/library/machine.Pin.html#machine-pin
@riordanpelayo9996
@riordanpelayo9996 5 лет назад
Thank you!!!!!
@abeekueshun4626
@abeekueshun4626 4 года назад
Very useful videos. Thanks. I am trying to get micropython-schedule to work on my esp32 and its errors after errors. Any help?
@maxmoq8423
@maxmoq8423 4 года назад
would you consider USB C on tiny pico?
@UnexpectedMaker
@UnexpectedMaker 4 года назад
All of my new board designs are using USB-C, though Micro-B is still more popular - for now ;)
@maxmoq8423
@maxmoq8423 4 года назад
​@@UnexpectedMaker I hand soldered your tinypico board this week as a personal challenge (and because I have too much time on my hands from this virus) and it all works! :D it's an awesome design, good job!
@clownzfeet
@clownzfeet 4 года назад
How to I find this part?
@UnexpectedMaker
@UnexpectedMaker 4 года назад
Which part @m sherwood? I'm not sure what you mean.
@clownzfeet
@clownzfeet 4 года назад
@@UnexpectedMaker The tinypico play shield. I dont find it on the site. Please link me? And Thank you for the great tutorials
@UnexpectedMaker
@UnexpectedMaker 4 года назад
www.tinypico.com/shop
@PicoGirl
@PicoGirl 3 года назад
Why is the timer linked to a period of 1ms or longer? This is ridiculously slow.
@bradclements1815
@bradclements1815 3 года назад
Hello, nice series so far on Python. Btw, the 'is' operator cannot always be used to compare integer values. The 'is' operator compares the identity of objects, not the value. Certain common integers are pre-created when Python starts, and so any use of those values will always have the same identity. However when using an integer outside the range of pre-created integers, the 'is' operator won't work. for example >>> a = 12345679 >>> b = 12345679 >>> a is b False >>> a == b True This article on interning explains it more medium.com/@daniel.tooke/singletons-and-interning-in-python-328413db334
Далее
MicroPython #2 - Hit the ground running
13:50
Просмотров 40 тыс.
БАТЯ И СОСЕД😂#shorts
00:59
Просмотров 2,2 млн
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
451 Which Processor can kill the ESP32?
11:24
Просмотров 342 тыс.
Using PICO Interrupts
25:15
Просмотров 18 тыс.
Programming a NodeMCU with MicroPython: PWM and ADC
7:48
Why The Windows Phone Failed
24:08
Просмотров 233 тыс.
MicroPython #3 - Fundamentals
19:30
Просмотров 27 тыс.
Using MicroPython in the wild
31:55
Просмотров 35 тыс.
MicroPython #1 - Lets Get Started
12:35
Просмотров 142 тыс.
Analog output from PWM and a low-pass filter
14:13
Просмотров 10 тыс.
📱магазин техники в 2014 vs 2024
0:41
КАКОЙ SAMSUNG КУПИТЬ В 2024 ГОДУ
14:59