MicroPython #4 - PWM, ADC, Timers & Interrupts

  Рет қаралды 37,012

Unexpected Maker

Unexpected Maker

Күн бұрын

Пікірлер: 79
@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.😎
@davidmc105
@davidmc105 3 жыл бұрын
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!
@capiberra4118
@capiberra4118 4 жыл бұрын
A brilliant and valuable set of tutorials. Thanks!
@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!
@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!
@damianzelazny5785
@damianzelazny5785 5 ай бұрын
Awesome stuff, many thanks!
@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 >>>
@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++.
@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!
@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!
@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 ;)
@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 ;)
@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 !
@AJB2K3
@AJB2K3 5 жыл бұрын
Nice, I'm learning lots!
@UnexpectedMaker
@UnexpectedMaker 5 жыл бұрын
Glad to hear Adam! Me too!
@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.
@ofsanjay
@ofsanjay 5 жыл бұрын
Those who learn new thing please like his video thanks for this video
@UnexpectedMaker
@UnexpectedMaker 5 жыл бұрын
Thanks!
@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?
@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
@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!!!!!
@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?
@stormbytes
@stormbytes 2 жыл бұрын
Thanks!
@stormbytes
@stormbytes 2 жыл бұрын
You spend a good deal of time recording and editing these outstanding tutorials. Have a cup of java on me!
@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)
@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?
@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!
@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.
@n9583
@n9583 3 жыл бұрын
Can you make a tutorial on how to code micro python on vscode and upload it?
@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!
@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?
@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.
@PicoGirl
@PicoGirl 3 жыл бұрын
Why is the timer linked to a period of 1ms or longer? This is ridiculously slow.
@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.
@sebasleyva4521
@sebasleyva4521 5 жыл бұрын
hi, i would like learn how do to connection with a api using HTTPS
@UnexpectedMaker
@UnexpectedMaker 5 жыл бұрын
Soon :-)
@clownzfeet
@clownzfeet 5 жыл бұрын
How to I find this part?
@UnexpectedMaker
@UnexpectedMaker 5 жыл бұрын
Which part @m sherwood? I'm not sure what you mean.
@clownzfeet
@clownzfeet 5 жыл бұрын
@@UnexpectedMaker The tinypico play shield. I dont find it on the site. Please link me? And Thank you for the great tutorials
@UnexpectedMaker
@UnexpectedMaker 5 жыл бұрын
www.tinypico.com/shop
@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
@clownzfeet
@clownzfeet 5 жыл бұрын
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 5 жыл бұрын
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 5 жыл бұрын
@@UnexpectedMaker OK, this makes since. Still new to this. That worked Thank you
MicroPython #5 - JSON & Network Modules + Practical Example
19:15
Unexpected Maker
Рет қаралды 29 М.
MicroPython #1 - Lets Get Started
12:35
Unexpected Maker
Рет қаралды 143 М.
Or is Harriet Quinn good? #cosplay#joker #Harriet Quinn
00:20
佐助与鸣人
Рет қаралды 55 МЛН
Шок. Никокадо Авокадо похудел на 110 кг
00:44
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12
Using PICO Interrupts
25:15
Making Stuff with Chris DeHut
Рет қаралды 18 М.
MicroPython #2 - Hit the ground running
13:50
Unexpected Maker
Рет қаралды 40 М.
Using MicroPython in the wild
31:55
PyCon AU
Рет қаралды 35 М.
MicroPython #3 - Fundamentals
19:30
Unexpected Maker
Рет қаралды 27 М.
Learn MicroPython #4 - Interrupts (event-driven code)
14:46
Invent Box Tutorials
Рет қаралды 25 М.
004 - ESP32 MicroPython: External Interrupt
17:05
TechToTinker
Рет қаралды 15 М.
ESP32 MicroPython OLED Tutorial with ADC & FTP
18:05
rdagger68
Рет қаралды 25 М.
Why build an entire computer on breadboards?
28:43
Ben Eater
Рет қаралды 3,1 МЛН