We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Hobby Electronics with MicroPython

00:00

Formal Metadata

Title
Hobby Electronics with MicroPython
Title of Series
Number of Parts
9
Author
License
CC Attribution 4.0 International:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
"A gentle introduction into the world of hobby electronics. Robots, art, gadgets, monitoring, tools, toys, home appliances, wearables -- with microcontrollers you can make anything. And now, that MicroPython is here, you can easily learn to program them."
Precedence diagram methodProjective planeRange (statistics)NeuroinformatikPrice indexMultiplication signQuicksortPRINCE2PrototypePole (complex analysis)LengthPlanningSurfaceInteractive televisionAreaDifferent (Kate Ryan album)Reverse engineeringVideo game consoleComputer programmingWhiteboardError messageMicrocontrollerState of matterMereologyPoint (geometry)TelecommunicationInsertion lossDigitizingCompilerPower (physics)Personal identification numberBlock (periodic table)DampingText editorBlogMusical ensembleInterpreter (computing)Library (computing)MiniDiscSpacetimeCodeField (computer science)BefehlsprozessorWeb 2.0TouchscreenBitHeegaard splittingVoltmeterCommunications protocolRevision controlPlastikkarteServer (computing)Electronic visual displayComputer hardwareMessage passingWeb browserMaizeInstance (computer science)Demo (music)Interior (topology)EmulatorAlgorithmRadical (chemistry)Process (computing)Network socketMachine visionMoment (mathematics)Pattern languageFunctional (mathematics)Standard deviationRoboticsObject (grammar)Pattern recognitionPOKESmoothingCASE <Informatik>Asynchronous Transfer ModeNumberoutputFormal languageImplementationRhombusModule (mathematics)Speech synthesisGravitationPhysical systemSemiconductor memoryVirtual machineRepository (publishing)Interface (computing)Flash memoryInternet der DingeEaster egg <Programm>SpeicherbereinigungComplete metric spaceWave packetFunction (mathematics)PeripheralGame controllerAnalogyTheoryRight angleLoop (music)Task (computing)Endliche ModelltheorieInternetworkingNoise (electronics)PiFlow separationCycle (graph theory)Normal (geometry)Sound effectSocket-SchnittstelleHidden Markov modelCryptographyArmAuthorizationPerfect groupOpen setDigital electronicsInheritance (object-oriented programming)MeasurementGraph coloringDecision theoryLecture/Conference
Transcript: English(auto-generated)
Hello, my name is Radomir, I'm going to tell you about my home be and how I Recently started using Python in it in it. So Let's start with a riddle Do you know what that is?
Yes Well, if you have read the little prints, you probably know what it is But I'm going to tell you more about it in a while. So This is an Arduino Looks something like that and it was really revolutionary some you know ten years ago
because for the first time People who are not electrical engineers would use a Small computer could really program it and put it into their project
it revolutionize that Areas like interactive art or I don't know home electronics like the digital kind not there because because you know There are all sorts of of electronics like there are radio people Come there are the audio people who do amplifiers and they are the you know
Gitter effects people who do all sorts of funny thing with their guitars and and stuff like that I'm mainly speaking about programming thing. So this thing here this
This part Here is a microcontroller, which basically means that it's a complete computer You can remove it from the from this board provided power and it will run as a normal computer However, as you can see on the picture this computer is a little bit limited
It has a 16 megahertz CPU Which is twice as fast at my feet as my first computer. So still Awesome, it has 32 kilobytes of disk space basically, it has flash memory and it has two kilobytes of RAM and
Can you run Python on that? well Python 3 I last checked it. It takes 16 megabytes Megabytes on disk and it when you just start the interpreter it Takes up 10 megabytes of RAM. I
Know the most of this RAM is shared with other libraries and when you actually use it, it's it's not used and so on however, you still need 10 megabytes of RAM and There is no way you can run it on something like this So There came this guy from Australia. His name is Damien George and
He wonders. Hmm. Maybe Python could be optimized or you know stripped down a little bit to actually make it run on a microcontroller and Well He didn't make it run on an Arduino
Although there is a project that does which is quite old version of you know Python 1.6 or something like that called pymite He made his own board and he used a little bit more powerful
Micro controller, it's an ARM Cortex-m4. You can see it's over 150 megahertz and It has almost 200 Kilobytes of RAM so a bit bigger than what 100 times bigger than Arduino but still much smarter than the computers we use every day and
Once he got it to run he decided okay Maybe I should polish it up a little bit and you know make it available for people to hear on a Kickstarter Campaign, that was some years ago three years ago something like that
And I have a lot of toys here going to talk I'm going to show you It like this so that you can see it Mostly I guess the light is not perfect
Anyways, it's it's a microcontroller board or those pins you can use for connecting various things to it and It runs Python I will demonstrate in them in a moment and I will
Explain I will try to Demonstrate You hands-on how micro Python works because I think this is the best way to get into it I could talk about technical details I could talk about you know garbage collector and and how the dict is implemented differently and
And things like that, but I'm not too good at it. I just started Showing this community I don't know years ago. Maybe a year ago and really got into it So I don't know all the details. There are a lot of talks by Damien himself and
Some of them actually go really deep into the that those details. I'm going just to try to interest you in that So the thing is and I've connected it through a Micro USB socket in here. I'm going to run a terminal emulator
Yeah wrong device and that Should I can reset it? This is a Python prompt But this Python runs on this small board here and the only thing that happens
With the letters that the characters are sent to the computer back and forth. So all the computations all the Python programs are actually executed on this thing so I can do the And I think I need the parents because this is Python 3
He decided to do we use the new syntax Yeah, I can do standard Python things I can do computations I can do floating-point and so on
The Interesting thing is the GPIO all those you know metal things on this are general purpose input output pins, basically and What they are is basically a switch
That can have one of the of three states it can be connected to Minus of the battery so it can be low Logical zero it can be connected to the pros of the battery so it can be high logical one and It can be switched into input mode in which
Case it's not connected either to plus or minus. It's just floating at least Officially, it's floating in practice. It has just very high resistance like mega mega ohms of resistance and When it's in that state the program can actually
Measure what voltage is provided to turn to that pin? So you can check if the device on the other side you connect two of those pins together You can check if the pin on the other side is high or low with that and that basically gives you all the power in the world to make any electronic gadget you you ever
dreamed about Because this this is how all the electronics that we use is is done and going to all that So I'm not going to use this board because it's a little less
Convenient for me. I'm going to use this board this is and a board based on the esp8 266 microcontroller Which appeared some two years ago from some Chinese?
Distributor called expressive and Damien decide. Oh, it would it wouldn't it be cool if if I could run Python on that one It's about three times slower than the pipe board and it has Twice as little memory as a spy board, so he had to
squeeze it in there however It has one huge advantage. It costs about three dollars So Compared to Arduino that costs about 50. I
Don't know And it's still a very powerful powerful system And also it has Wi-Fi built in so you can connect it to Network and and do you know all the Internet of Things? Things if you if you really are into that
Well, I'm going to connect this and Now I'm going to connect to the other yes, so we have the Python prompt and Of Course to do anything you first have to import your libraries and micro Python doesn't have all the of Python standard library because that's a big chunk of those 16 megabytes of
This space that it uses however There is a big chunk of the Python some library in prime implemented for micro Python In a separate repository and you can just copy the libraries the modules that you will actually want to use
So this way you save some space I imported machine machine is a module that contains all the interface functions for for the actual hardware on this thing and I Know for a fact that on this particular board
There is an LED so Basically a light connected on GPIO to and it's connected between that pin and the plus of the battery so if I set the GPIO to to low To to minus there will be current flowing here and the light should come on
Let's try that so I Will create a pin object? Using oh there is tab completion, which is super convenient And I set it to output and
Right and it's shining So if I do pin I I will switch it to the plus of the battery
right and it's not shining and If I set it to low again, it's shining too. Okay, so
We can do more So, let me copy some old because there is a time library, of course
That doesn't work well, so there is a copy paste mode in here if you press ctrl e It will let you do this and then if you okay after all
It's not that much
living twice
Doesn't matter so it's blinking blinking light is like a hello world electronics
It's it proves that you can actually talk to two peripherals. Oh, that's like the most basic thing you can make and Right, but what if we wanted to this LED to to be nice and like have shades of
Not just on and off but you know dim slowly and then slowly come up and so on but we can do that We can only set this pin to high or low We cannot we don't have like analog control on there. Although there are ADC peripherals. That's also allow that
So what we can do we can switch this LED on and off very fast and Also, we can vary the time in which it is on So if it's on 50% of the time, it will be at 50% brightness, right?
And if it's only 10% of the time on and the rest of the time off it will be at 10% bright That's the theory anyways Let's try that Yeah so we have PWM which is basically pulls pulls with modulation
there is a special peripheral on this board because Blinking and LED is such a common task that there is a separate hardware Peripheral on this board just for doing blinking It's actually useful for other things too, but I
I like to think about Like that, so I will try to paste mode again This is going to be tricky let's let me just do a
loop from 0 to 124 in steps of by eight PWM beauty cycle I and time sleep
0.1 and now I can The camera should be fading slowly Yeah
Well, maybe that's just the camera No, it's fading. It's fading Okay, you get the idea you can just set the duty and and so on and you can also Control things like hobby servos with that
Because a hobby servo is think originally used in like flying models like radio controls models for moving the Control surfaces of the plane and
It's really cheap. You can you can buy those let's say they use them in toys now and The thing is once you can control it you control it the same way as the LED you just vary the length of the pools I'm not going to demo that. It's going to be
I'm I can't show it clearly, but I'm going to demo. I think I built using that with micro Python
Let me put it back together
So You get the idea I should actually put some screws in
I Didn't charge it before
That's one example of things you can make you can also make all sorts of I don't know Indicators displays you have all a huge range of sensors you can connect because of they are doing nothing You can you can use all the things they made for are doing those
because you control it the same way and With Python and with an interactive console. This is really a huge difference because With Arduino you had to write your C program basically compile it Correct all the compiler errors compile it again
correct insert the last missing Semicolon somewhere compile it again Upload it to the board run it go to the point where you are using a certain thing So navigate through the menus or or I don't know get it into the state Where where that you are debugging right now, and then it crashes and you cannot see the error
Because it's on the board So the the interactive console helps really lots Because you can just connect things to it and just try things interactively and see the errors and
Try other things and so on and then later you can can just copy that into your program Yeah, it also has Wi-Fi I'm not going to show you Wi-Fi because We won't be able to connect to this Wi-Fi here because it needs web sign-on
But believe me and there is a very convenient library called you requests So most of the simplified libraries for for micro Python have the you prefix because they are simplified So they don't have everything that the original library has
And They added the prefix because you may at some point implement the full library and then you won't have the name conflict You can use both Yeah, it has a lot of Protocols that is supposed so it actually has web sockets so you can do interactive thing with with with your web browser
HTTPS which is kind of an achievement because doing crypto on a 80 megahertz you it's not easy MQTT is very useful for all sorts of
message Exchange for Internet of Things and the rest of those are hardware protocols for talking to things like Displays like those or sensors or I don't know Servos more intelligent servers and so on
So those two boards are the official supported Once by by the authors of micro Python, but of course micro Python has been forged and there are many other Ports that it runs on for instance
Adafruit Which is a seller of a lot of these are doing those stuff those sensors and so on They made their own board that runs micro Python and they of course They named it circuit Python because they changed things in there to be easier to teach Because they won't mostly want to teach children
There is this open MV ink which has It has a little bit stronger CPU on it and it has a camera and the guy actually went and implemented in C from scratch a Lot of vision processing algorithms on it and you can call those algorithms
From the Python. I will I can demo that after the talk Because we are running out of time or if we have and so it does things like face detection. It does things like object detection color blobs and and all the things you do with vision really cool stuff for
things like robots and There is this micro bit ink so last year BBC Gave this thing. This is the micro bit I can show Looks like this and it has a microcontroller on it
It gave that to 1 million children in UK basically all seventh graders at schools For teaching Electronics for teaching programming on something different than a huge computer
something you can put in your pocket and a Number of people that I mean George the the the author of micro Python, but also Nicholas torov and a number of other people
Came up with the implementation of micro Python for this Board, it's a bit different than standard micro Python because it's made easier for children to teach but Really it's the only language you can use with this board that has interactive console
so it's a really nice thing for children and I can show you one of the Yes, they have Easter eggs in there they also have import anti-gravity but Import love is something I can show easily. It's just a stick
Yeah It's super cool They implemented a speech synthesizer for this so you can connect a speaker to it and make it talk they implemented music module that plays music and lets you play music and
All sorts of really nice things for children They even have a blog editor where you can you know, like scratch you can make a program from blocks But at the same time it has a split screen and at the same time on the other side of the screen It's writes Python for that program so you can easily switch between the two and you can learn Python that way
awesome Okay, so This is all I had prepared for now I will I will try to demo the camera board and in the meantime, you can ask me questions and I will
Try to avoid them Thanks a lot do we have any questions don't be shy I guess more time for demonstrations, okay
All Right one question
Just a small question about the GPIO say on on on what voltage do they run so It depends on the board most of the boards that Like most of the modern boards as these days are produced are 3.3 volts are doing noise very old
That's why it's 5 volt but The pie board is Very nice because it runs on 3.3 volts, but the pins are 5 volt tolerant so you can connect 5 volt after it The ESP8266 doesn't have that so if you connect 5 volts to it you will fry it
Yeah, it varies but mostly 3.3 volt, okay Okay, I'm going to so the demo I You see here I I don't know if I can zoom that I'm going to show you the face detection demo because that's
worked last time I write Yeah, as you can see this is not very Much cold here because they they are mostly calling ready pattern functions
it does The face detection in black and white with the lighting here. It's a bit tricky Thank you, you can see oh sometimes it's I guess I have a non-standard face
Yeah, but it mostly works with some smoothing and you can easily make I don't know a Dart gun thing that Tries to poke people's eyes out or I don't know they also have face recognition thing where you can
actually Recognize faces they have eye eye tracking thing where you can Find eyes in in in the face and you know use a laser pointer thing
Whatever all right, we're slowly running out of time. Let's thanks rather meet up once again for the nice talk