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

Try Something Different: Explore MicroPython (... tales from an adventurer)

00:00

Formal Metadata

Title
Try Something Different: Explore MicroPython (... tales from an adventurer)
Alternative Title
Try Something Different: Explore MicroPython (a rough guide for newcomers)
Title of Series
Number of Parts
112
Author
Contributors
License
CC Attribution - NonCommercial - ShareAlike 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 and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
MicroPython is a reimplementation of Python for microcontrollers, originally developed as a result of a Kickstarter campaign. Today, it is an approachable way into programming for many young people, via boards like the Raspberry Pi Pico, the BBC micro:bit and the CodeBug - you can even run it on LEGO bricks! It is increasingly being used in commercial fields as well. MicroPython is helping Python to get into even more places, and making programmers more efficient as it does so. Andy Piper wanted to learn more, so he spent some time travelling and adventuring on the internet, to discover the community and projects around MicroPython. The goal of this session is to briefly explain the What, Why and How of MicroPython. There *will* be circuit boards, and discussion of microcontrollers! We will take a look at examples, from established development boards to brand new ones. We will also acknowledge how MicroPython has been built upon, to enable different ways of working (with CircuitPython), and LEGO robots (via PyBricks). Finally, and most importantly, you'll get a good sense of the places you can find and learn from the MicroPython community, and how you can get involved and contribute!
29
EllipseExpert systemMetrePoint (geometry)Software developerFormal languageScaling (geometry)Derivation (linguistics)Integrated development environmentTwitterProcess (computing)Mathematical optimizationCopyright infringementDistribution (mathematics)Regular graphLaptopLine (geometry)Web browserMultiplication signQuicksortLoginGroup actionArithmetic meanTelecommunicationMereologyForm (programming)Library (computing)ImplementationReal numberExpert systemNumberInsertion lossBitCausalityImage processingMicrocontrollerRange (statistics)Disk read-and-write headDifferent (Kate Ryan album)Variety (linguistics)CodeCASE <Informatik>Wireless LANPrice indexPoint cloud40 (number)Projective planePattern languageECosSpacetimeComputer clusterAdditionHand fanConstraint (mathematics)Limit (category theory)Proof theory
Run time (program lifecycle phase)Text editorIntrusion detection systemCodeDifferent (Kate Ryan album)Core dumpFormal languageCommon Language InfrastructureRevision controlForm (programming)BitProgrammer (hardware)Demo (music)FirmwareComputer fileLibrary (computing)Keyboard shortcutCode2 (number)AbstractionMass storageRegular graphMacro (computer science)Variety (linguistics)Integrated development environmentSemiconductor memoryData storage deviceWhiteboardGraphics tabletCodeGame theoryEmulatorComputer hardwareSpacetimeTwitterDistribution (mathematics)QuicksortProjective planePattern languagePoint cloudSoftware bugChainPersonal identification numberBootingOpen sourceMereologyCASE <Informatik>Computer clusterBuildingComputer programmingEndliche ModelltheorieSystem call1 (number)Multiplication signDataflowRepetitionArmBit rateAreaArithmetic meanWeb browserComputer configurationPoint (geometry)Plug-in (computing)MassGame controller
CodeChi-squared distributionGamma functionInterior (topology)Whiteboard2 (number)Electronic visual displayConnected spacePoint (geometry)LaptopSpacetimeGraph coloringPasswordProjective planeRevision controlMoment (mathematics)Power (physics)Electronic mailing listOcean currentLarge eddy simulationWeb pageCodeTwitterCloningWireless LANHydraulic jumpProper mapScripting languageChainBitFunctional (mathematics)InternetworkingMereologyPiMathematicsClosed set1 (number)QuicksortMultiplication signSet (mathematics)Computer animation
MIDICodierung <Programmierung>Gamma functionWeb pageMultiplication signUniform resource locator40 (number)WhiteboardVirtual machineConnected space
ACIDComputer wormMetropolitan area networkRight angleMultiplication signBuildingGraphics tabletBitText editorSpeech synthesisMachine visionCopyright infringementProjective planeSoftware development kitGraph coloringInterface (computing)Variety (linguistics)Computer animation
Internet forumTwitterWhiteboardBlogElectronic mailing listDifferent (Kate Ryan album)Device driverSpacetimeType theoryComputer clusterSynchronizationSheaf (mathematics)VideoconferencingSeries (mathematics)Touch typingSelectivity (electronic)WebsiteDescriptive statisticsMereologyMultiplication signColor confinementTwitterWindowLattice (order)TouchscreenAreaGraph coloringComputer animation
Computer hardwareLimit (category theory)Semiconductor memoryTerm (mathematics)Lecture/Conference
Latent heatSemiconductor memoryLimit (category theory)Expert systemRight angleLecture/Conference
Flash memoryQuicksortComputer fileWhiteboardAutomationBitCASE <Informatik>InformationDifferent (Kate Ryan album)Lecture/ConferenceMeeting/Interview
Template (C++)Information securityLecture/Conference
QuicksortNumberCore dumpGoodness of fitBitWhiteboardIntegrated development environmentCategory of beingType theoryWireless LANBlock (periodic table)Line (geometry)Extension (kinesiology)CASE <Informatik>Basis <Mathematik>Content (media)Perspective (visual)CodeSoftwarePoint (geometry)Uniformer RaumMultiplication signTorusFunctional (mathematics)PiLecture/Conference
AreaFormal languageCore dumpMultiplication signMereologyInternet forumProcess (computing)Proper mapSpacetimeArmForm (programming)Product (business)Lecture/Conference
XML
Transcript: English(auto-generated)
Now for this talk, I want you to think about where it's most likely you're running your Python code today. I'm imagining that the majority of the folks in the room are not already using MicroPython or small devices. Maybe some of you are, which is awesome. OK, there's some nods in the room.
But if you don't, I imagine that you're probably running Python on the cloud, on your machines, in Jupyter notebooks. We heard that it scales to image processing for the space telescope, which is amazing. We know that it's moving to running on the browser. So we're going to talk about something that goes down to the other end of the scale,
down to smaller devices. So talking about running Python on small circuit boards, on LEGO bricks, that's going to become relevant later on. On watches, it can really get everywhere. And that's pretty cool, I think.
So my name is Andy. I work at Twitter as a developer advocate. I'm not here on behalf of or in any way related to that day job. I'm here because I'm excited about Python, and I'm excited about MicroPython. I went to my first PyCon a number of years ago over in Ohio, and I'm really excited to be here
at EuroPython. So thank you for having me as a speaker. I am not an expert in electronics. I'm not an expert in MicroPython. This is really going to be a talk about my journey learning about MicroPython, in particular in the last six, eight months.
I have got some experience in the past, and I'm talking 10, 15 years ago. I worked at IBM. I was one of the people that worked on MQTT there. And I've gone forward a slide. And I've been playing with things like Arduino for a long time. But I've never fully got my head around a lot of the electronics concepts.
I'm a Lego fan. That's going to become relevant. So bear with me, and hopefully you'll learn along with me as I've discovered things here. So let's talk about MicroPython. What it is, as in where it came from really,
and the differences between it and other varieties of Python, and why I think it's important, why I'm here talking about it as opposed to talking about other varieties, again, or distributions of Python, and also how to start using it because that's kind of fun.
So hopefully we'll play around with it on a few different boards and see the kinds of things you can start to learn. So for those of you that aren't familiar, how many of you have no knowledge at all of MicroPython or no idea what it is? A few of you, OK, cool. So MicroPython has actually just celebrated its ninth year, so just in May.
It was the ninth anniversary of its first release. It started off as a Kickstarter project from a guy called Damien George, who's an awesome guy. He's actually over in Australia now. And he had this idea that Python's a great expressive language. Why not try to run it on small devices?
Now, you can't run C Python on some of these devices. We're talking about things with very limited amounts of RAM in particular. So some of the optimizations in MicroPython are really focused on things that C Python is not optimized for. So it's not C Python.
It's a full re-implementation of a language that looks very similar, is virtually the same as Python. It doesn't include all of the batteries included that you get with the regular Python distributions. The libraries in MicroPython have to be re-implemented specifically for the hardware
and for the environment they're running in. So specifically, it's a re-implementation of Python at around about 3.4, 3.5 release. And since then, over the years incrementally, they've added additional sort of pet features that have come along since then, as they make sense and as they can be accommodated within the constraints
of the language. And since then, it's been ported across a whole range of microcontrollers. The most recent one that's been added in the latest release of 1.19 of MicroPython is a Rhenesas SA board.
But about two weeks ago, the Raspberry Pi Foundation brought out the Raspberry Pi Pico W, which is a Pico with wireless. And it runs there as well, which hopefully I'll be able to show you in just a few minutes. So you may have heard of some other things.
And I know there have been also talks about other varieties of Python for small devices, in particular CircuitPython from Adafruit, which is really, really cool. I'll talk about why I started down the path of MicroPython though. It's been going over, as I say, going since 2014 now, May 2014.
Just before that, I think actually was it 2013? It's just had nine years, so it must be 2013. And this is just a star chart showing, and stars are not necessarily the best indicator of popularity or growth of a project on GitHub. But it's interesting to see that MicroPython, the red line
there, has grown in a kind of a fairly linear fashion over time. Some other derivatives of MicroPython, things that have been built off of MicroPython, such as CircuitPython and PyBricks, have come along at different times. And they've also been tracking really well. It's exciting to see these languages getting
into these environments. So why is it important? Well, Damian, I was listening to a podcast the other day from a few years ago to get a bit more inside Damian's head, really, as best I could. And he described his initial idea when he went to Kickstarter to launch for some funding
as sort of a proof of possibility, I think was the phrase he used, which I thought was really interesting. Python is a great language for expressing your ideas as code. And I certainly have had that experience myself. I've been doing code in various forms for 30-plus years, and I think Python's a great language.
It's relatively easy to pick up, and it's very easy to be productive in very quickly. It's particularly good for prototyping, iterating, and trying things out, optimizing things later. And importantly, MicroPython is now the foundation, as I said, for some of those other projects.
So Adafruit's put a lot of investment into building a version of Python that's got MicroPython at its core called CircuitPython. They've got a team that builds that commercially, as well as it being an open source project. They pay people to actually work on it as their day jobs.
CircuitPython itself has had stuff built in it, so there's a keyboard firmware called KMK for programmable macro pads and things that's built on CircuitPython. So you've kind of got these sets of layers. Pybricks, which is able to run on a lot of Legos controllers, has been built on MicroPython as well.
So I think it's really important to understand and build on that foundation. And I was talking to Carlos downstairs earlier, who had some microbits down in the maker space there. And he was describing it as really a bit like a Linux distribution model, where you've got a core, and you've got different ports and different varieties and different ways that people are bundling MicroPython
and extending it. So you heard there'd be demos if you read the abstracts I put out. So we're going to probably want to have a board. We don't have to have a board. There is an emulator called Wokwi,
which you can go and try MicroPython and an emulator of a board like a Pico in the browser, which is very cool, actually. So you don't have to go out and spend lots of money on hardware. AliExpress can end up being a lot more expensive than it starts off looking when you start looking at fun little boards.
Once you've got a board, you're going to need to put MicroPython on it. I've got MicroPython on all the things on the desk already, so I'm not going to go into how to install it. But it's usually just a question of plugging the board in, resetting it into bootloader mode, and then dragging a firmware on in most cases, and a code editor. Now, how did I get involved with all of this?
Well, in January, Deborah, who's a maker on Twitter, tweeted this board that you can see here, the one with the LEDs. And she said somebody's sort of blinged out a tiny board, which I've now put under here,
with lots of RGB LEDs. And she thought, this is amazing, and it cost, I don't know, $4 or $5. So a bunch of us all saw that tweet and thought, yeah, OK, that's not very expensive. We all need one of those. And it's got Wi-Fi and Bluetooth and other stuff on there as well. It's an ESP32C3 chip, USB-C on the top.
So she ordered one and started making jewelry with it. It's kind of fun. And she's got this necklace. She can change the stuff on there. And then she also made one which made a little 3D-printed cloud and did different rain patterns and things on it. So I got one of these. And it wouldn't, at that time, support CircuitPython.
ESP32C3 doesn't enable you to mount it as a USB drive, which is what CircuitPython typically does, although they're moving more towards being able to program them directly over Bluetooth. So I ended up starting a project for myself. And then, because a lot of other people had bought
these boards around the same time, we all started sort of figuring out what the maker over in China had done, what the pins were on the board, what we needed to do to drive it. The other thing at the time, in February, was that the ESP32, the Espressif C3 chips were not as well supported in MicroPython
or, in fact, in Espressif's own tool chain. So we ended up fixing some bugs. So I put together this little project. It started off as MicroPython examples. And then it ended up, I've played with TinyGo. And there's some other languages you can use on there as well. So that's why I started digging in on MicroPython.
And it had been a while since I looked at it myself. I'd previously looked at CircuitPython, which has got a really nice workflow. You literally just are editing a file on a USB mass storage device. MicroPython, you kind of need to do a bit more work yourself, which is fine for me, because I'm familiar with things.
MicroPython, as of some of the more recent versions, has got a CLI called MP remote, which we'll try and have a quick look at in a second. I also mentioned MicroPython is not as batteries included as full Python.
So you're typically going to need to be installing libraries as you need them. And you're going to want to be very thoughtful about what libraries you actually need, what harbor you're driving, again, how much RAM you're using on the board. Because with some of them, you're going to very rapidly run out. Other ones, you can get some of the RP2040 boards with a lot more storage and other capabilities and memory.
And the other thing I started looking at was all of the IDEs options. So Nicholas is here and has got the Mu editor, which is awesome, and he works really, really nicely for CircuitPython in particular, works really nicely for lots of varieties of Python, regular Python.
We saw him building that cool game with Pygame Zero the other day. But there's a nice one called Thonny, which I've been using. There's a plug-in for PyCharm. There's a plug-in for VS Code from one of the other board vendors called PyMaker. I haven't got it to work. VS Code's my go-to editor, so I'm
disappointed about that. There's a variety of them to check out. So we're going to take a quick whip through some boards. And that's why I've got this camera here. And we'll see what we can achieve. Let's see.
Where did I do with my Pyboard Lite? So when Damien did the Kickstarter, he built a board. And this is actually a clone of the Pyboard Lite. I do have the actual proper Pyboard Lite. I picked up the wrong one when I was rushing and packing my stuff the other day.
Now, these boards don't have wireless connectivity on them. You can connect something to them. I hope people can see that. Can everybody see this OK? Excellent. I can actually increase the size of this for now, because I'm not going to be immediately jumping into code. But I will do in a second. So there's Pyboard Lite.
So initially, the Pyboards were bundled with the Kickstarter rewards. We've also got this 5x5 board, which I've got a cable plugged into at the moment. Now, I should have this. This is where everything goes horribly wrong
and I lose all my connection. So bear with me. That's not going to reach. Switch USB hubs so I can put it in front of the camera. I also need to get one of those funky close-up cameras, which this is not.
So in principle, when I plug this in, it's going to connect to the EuroPython Wi-Fi. There's a little blue light on the back. So this is an Espressif ESP32 board. Has anybody heard of a project called Cheerlites? Nobody? So Cheerlites is basically a synchronized color API
driven over the internet. You tweet a color, hashtag Cheerlites. Currently, the color is green. So this is subscribed to an MQTT topic. So when it started, it connected to the Wi-Fi, subscribed to the Cheerlites topic. If anybody wants to tweet the Cheerlites at the moment,
that will change color. But given the time, I'm going to jump straight over to the PicoW because I want to show you this one. So until about two weeks ago, the Raspberry Pi Pico was in plentiful supply but didn't have any Wi-Fi connectivity. You could get some boards with ethernet or you could add Wi-Fi or ethernet yourself. They've just added one which has got Wi-Fi.
So let's jump into some code because I think this is hopefully going to work. Let's move to that. I'll stop for a second. So we've connected. I've plugged this in, and we've connected to it. So this is, it's got a, MicroPython's got a REPL,
as has Python. So I can do import us and print uname. So the uname functionality in the latest release has improved a bit. So we'll show you a bit more about the tool chain it was compiled with, which is handy.
So I've got a couple of scripts here. There's one here called space, which is borrowed from my friend Les Pounder, big Les P on Twitter. So this is going to connect to the conference Wi-Fi, and it's hopefully going to get us back the current list of astronauts in space.
That is saying it hasn't connected to the Wi-Fi yet, which is why it says false. Hopefully it will come true in a second. OK, so that's the Pico. That's not running on my laptop. That's running on the Pico here. What's the point of that? Well, this could be connected to a small display in your home on very little power if you wanted to.
Astronauts in space are probably not going to change very often, but you might want to do some other things with that. And the Pico is an incredibly affordable board. It's like 6 quid, 7 quid for, I think, the Wi-Fi version. Sorry, you can tell I'm British and referring to things in quid rather than euros or dollars or any other thing.
The other thing I've got here, which I quite like, Alistair Allen from the Foundation, Pi Foundation, put this one together. So I'm going to just kick this one off. Let me stop the one that's running. And when I start this, there should be a new Wi-Fi hotspot in the room called Explore EuPython. If anybody wants to try connecting to it,
the password is dublin2022. And there should be a web page at 192.168.4.1. I do have this to show you all, and especially for those who are remote and can't connect to that. It will look something, I hope, like this.
So that's just running straight off the board again. If anybody's connecting, then I should be able to see it. But nobody has connected yet. So, oh, well. I promise you it works because otherwise I wouldn't have been
able to do that screenshot earlier. There we go. Somebody's connected. Thank you. It's a Linux Android Dalvik machine thing. So the web address is 192.168.4.1. And then if you load that, you should get back the web page. And I've even got the SVG logo from the conference in it,
I hope. Anyway, moving right along, this is quite simple stuff. I'm not going to plug in any more boards on the grounds of time. But again, the BBC Microbit runs a MicroPython, and it can be programmed visually as well. Yes, Lego.
I can't find my Lego man board. Well, I have a Lego man of my own, which you can't see on the camera right now. You know, I do lots of conference speaking, but this one's going very, very quickly. So my Lego man. So I'm into Lego.
And I think Laurent from the PyBricks team was going to try and connect to watch my talk. But Lego sell a variety of these kits where you can program them typically on an iPad or something like that or with a visual interface. So this is one of them. This is from their Lego Droids set
where you can build an RTD2 and drive it. It comes with things like color sensors. So I'm not going to show you now for the reasons of purposes of time. But I can assure you that it works. It's really nice. This one is programmed over Bluetooth. And they have an editor that looks a bit like this.
So were I to run this and connect to it now, this would start printing out the color of things that I put in front of that sensor. You could do some really cool stuff with that if you're building things with Lego. It's a really nice project. I apologize to the folks from PyBricks. We're not giving them a bit more time today. But if you're interested in that,
do check that out as well. But yeah, this is actually, somewhere in my bag down there, a little Lego mini fig shaped board, definitely not approved by Lego, that has a SAMD51 chip that has got a micro USB connector on the back
and you can use MicroPython or CircuitPython with that as well, which is really fun. And this watch is running Python. This is a cheap, it's only 30 quid. It's got a touch screen, various sensors on there. So what I've been doing is, as well as learning about this stuff,
coming to talk to you about this stuff, I've been trying to get involved with the community and I think that's really helped me. I've been writing on what I've been learning. So the little five by five board, there's a series of blog posts on dev.to, dev, and I'm also moderating the MicroPython tag over there.
There's a GitHub topic now for MicroPython that I submitted. If you didn't know, topics on GitHub, you can actually go and add, which are on the explore section on GitHub, you can actually send a pull request to add descriptions and stuff. I've also been attending the meetups. They have monthly meetups in MicroPython now. All of the leads, almost all of the leads,
I think, are in Australia. So I've been joining at seven or eight in the morning and they've been having their meetups in their evening, but it's been really good. Especially, actually, because of the fact that we've had the pandemic and we've had the lockdown, they've been doing them online, which has meant that I've been able to join, which has been really fun.
You can try MicroPython on Wokwi. If you search for MicroPython, Wokwi, which is a fairly specific spelling there, then you'll be able to find, there's a site where you can go and basically select boards and try things there. And the final two things I really want to recommend are the awesome MicroPython lists.
So if you're familiar with awesome lists, there's one for MicroPython. You're going to learn a lot if you get into this around different types of sensors, different types of connectors to attach sensors to your boards and you often need drivers for those. So the awesome MicroPython list is a really good place to go and learn about them.
And there's a great guy called Bvesh over in Canada who's been doing an amazing series of tutorials on his blog with videos as well, showing doing things like building color-changing lamps, using MicroPython with MQTT, NTP, other things. This watch is actually connecting to NTP to do the synchronization.
So thank you very much for attending. I really appreciate it. And I apologize that it seemed like I was scrabbling around for boards. I shall consider my use of my space and time more carefully in the future or just ask for a longer slot. Thanks so much. I can't stay for the sprints, unfortunately.
But do tweet me or come find me before the end of today. I'd love to chat. Thanks.
Just a quick one since I'm not familiar with all the hardware. Oh, yes. What are we talking about in terms of memory restrictions? So I think the absolute lower limits are,
they're in less than megabytes of memory. I mean, you're talking about very small amounts of memory that they're optimizing for and trying to do a lot of stuff as well in that memory, in RAM rather than necessarily, you've got no swap, right? So you're having to do that.
I don't know. It does scale up as well. I don't know. I have to say, I'm not an expert on the absolute specifics. What does a typical board have, like the ESP32? So a lot of them are sort of one or two mega flash storage for your files.
Again, I'm not 100% sure on the actual RAM restrictions on all of them. I'd have to go look up the different specs for the different boards. Sorry about that. The other thing is I've been talking about like having lots of fun with all this stuff, which is what I get to do. But the folks that actually are writing MicroPython, as I mentioned, several of them are in Australia,
are using this for industrial automation and industrial use cases as well. So it's definitely something that's a bit more serious than blinking LEDs. Folks are using it for some really cool orchestrations. But I will tweet some information about this later on
because I now feel like I need to know that. First of all, it was really exciting. Thank you. I guess that when you started working with this, you already had some experience with the overall thing.
If someone with less experience, someone that's beginner wants to actually start working with MicroPython, which would be your advice? I think Wokwi is really nice because they've got some templates on there. Microbit's really good as well because it's designed as an educational tool
and it enables you to go from sort of block type based environment into Python. I think that the advantage that CircuitPython has got, they've got Adafruit behind it with a team of people that are building, constantly building tutorials, really good content on there. CircuitPython is slightly different.
It's not 100% compatible with MicroPython, but they've got some really great walkthrough tutorials. I think that's something that's not there currently on the MicroPython side, and that's what I'd love to help with. Vivesh is doing some great work around it, but it's all on a volunteer basis there, which is also the case to some extent for Adafruit,
but I did struggle a little bit and I've actually been chatting with a Jimmo who's one of the folks who's on the core team for MicroPython about how we can improve the documentation experience in particular. Again, because all of the boards are slightly different and there's a number of ports.
For example, the network, which you briefly saw some lines of code from there, the WLAN functions, some of the core, some of the properties are slightly different between the different ports. So you end up digging through the docs to figure out what's what.
But I think Microbit's really good for starting out. The Pi Foundation's got a couple of bits for, they've actually got a book about MicroPython on the Pico, which is quite nice. I think those kind of resources are a good starting point. And if, okay, I want to do another one.
From the other perspective is that you have, I guess, a lot of experience. So do you see an area there for Python, for MicroPython that this technology has some steps to do more? Do I, I'm trying to understand, I just want to try and make sure I'm understanding the question.
Are you asking if there's a gap? No, no, no, no, I'm not sure that I heard properly. Are you saying, is there a gap or something or is there an opportunity or? Yeah, yeah, exactly. I mean, I personally think that the MicroPython, I say we, I'm hoping to be part of that community and everybody to be part of that community. I think that there are definitely some gaps
because the core team is small and they're focused on the technical aspects of the language. So I think tutorials, documentation, all of those kinds of things are an opportunity. And then also bringing things together in a community space. There's currently a forum on,
I think it's a PHPB based forum. There's a discussion about whether that's right for the job now or they might move it to GitHub discussions or something else. There's a Slack community. There's also a Discord community. So it's like knowing where to go find out, ask questions. And again, everybody's doing it on their spare time as often happens.
So it's really just making sure that everybody's talking to one another and that's always an opportunity. Thank you. Okay. Enjoy the rest of the week. Thank you.