Latest / Talk Python To Me / #108: MicroPython and Open Source Hardware at Adafruit
Transcript
- 0:00Want to learn how to build an Ironman-like arc reactor accessory or maybe a solar charging backpack?
- 0:05What if you could program these devices with Python? Now that would be cool.
- 0:09In this episode, we're going to be talking about a project and a company combining to make this possible.
- 0:15This week, you'll meet Tony DeCola, who works at Adafruit, a company making hardware programming accessible to everyone.
- 0:22And we'll also be talking about MicroPython, which lets you program these cool devices in Python.
- 0:28This is Talk Python To Me, episode 108, recorded April 18th, 2017.
- 0:56Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
- 1:04This is your host, Michael Kennedy. Follow me on Twitter, where I'm @mkennedy.
- 1:09Keep up with the show and listen to past episodes at talkpython.fm.
- 1:12And follow the show on Twitter via at Talk Python.
- 1:16This episode is brought to you by Advanced Digital and the Strange Loop Conference.
- 1:20Be sure to check out what they're offering during their segments. It helps support the show.
- 1:24Tony, welcome to Talk Python.
- 1:26Hey, it's great to be here. Thanks a lot.
- 1:28Yeah, I'm really excited to talk about hardware and MicroPython and all the stuff that we got on deck today.
- 1:33So that's going to be really fun. But before we do, let's start with your story.
- 1:37How do you get into programming in Python?
- 1:39Yeah, so I think like a lot of people that you've had on the show, I got into programming just as a kid.
- 1:43So when I was 13 or 14, I remember at the time we had a 486 and I was using QBasic to learn how to do programming.
- 1:50Or it was just a fascinating thing to me to understand like, wow, I can actually make something that controls the computer.
- 1:57And of course, I wanted to make video games. And that seemed like the coolest thing for me.
- 2:01But it was just a really interesting passion that I followed as a kid.
- 2:05Just took me all the way through college, studied computer science.
- 2:08And Python is interesting. So I remember in college, this was around maybe the early 2000s or so,
- 2:14I'd started to hear about Python and it had been around for quite a while.
- 2:17But I played around with it. I think I'd learned like the basic syntax and then put it away and didn't use it for a long time.
- 2:24And I went on and worked a lot in industry with like some of the managed languages like C#.
- 2:29And I did a lot with like C++ originally. But I kind of came back to Python maybe about 10 years ago.
- 2:35I was working for an online service, SkyDrive, like what used to be called SkyDrive, a big file store service.
- 2:42And we had to do a lot of data processing. So things like looking at log files and analyzing data.
- 2:48And that stuff is not so fun to do in some of the languages like C++.
- 2:53So Python was like a perfect fit for that. So I started to use a lot of that for things like manipulating data.
- 2:58And just really kind of fell in love with the language.
- 3:00You know, it's turned into something that becomes kind of the first thing I reach for now when I have some problem of,
- 3:06you know, whether it's even just like doing something on the desktop, like manipulating files, manipulating data.
- 3:12It's what I really like and enjoy using. So it's become kind of, I'd say, the primary language that I use.
- 3:18And then as I've worked with Adafruit, it's been something that's been interesting to explore of how you take Python and use it to control hardware,
- 3:25because that's been something that's been a little bit difficult.
- 3:28You know, hardware has typically been a lot of low level languages and direct access to the hardware.
- 3:34Right. That's the domain of C, right?
- 3:36Exactly. Yeah. So having like the C and C++ knowledge, that's what your bread and butter was.
- 3:41But nowadays, things have kind of changed a little bit.
- 3:44So there are a lot of new processors and, you know, it's Moore's law.
- 3:47Everything is getting faster, even at the low end.
- 3:49So these little processors can actually start to run things like Python code.
- 3:53And so that's super exciting to me to start to see that kind of crossover there.
- 3:56I think that's really cool.
- 3:58Like a couple of questions.
- 4:00One, coming from like static languages that are based on C with curly braces,
- 4:05like how did you feel about coming into Python with the white space and the dynamic types and whatnot?
- 4:11Oh, sure. Yeah, yeah, yeah.
- 4:13I think everyone maybe goes through like a phase of like it feels weird and you maybe push back against it
- 4:19and think like, oh, wow, this is horrible.
- 4:20Like I don't understand what's happening.
- 4:22And the biggest thing for me was losing the destructor.
- 4:25Like, you know, in C++, I love having that knowledge of when some object goes in and out of scope,
- 4:30you can do certain things.
- 4:31Then in Python and some of these managed languages, you just don't have that control anymore.
- 4:34So, yeah, your first reaction is kind of to push back.
- 4:38But then after a few years and using it for a while, you get into that zen of Python of just kind of understanding.
- 4:43And like nowadays, I love how Python, it almost feels like clay.
- 4:47Like you can just model it into whatever paradigm of programming you like,
- 4:51like whether you want to do object oriented or functional or some combination of those.
- 4:55So it's, yeah, it was a little bit of an adjustment period, but you kind of have to think more, I guess, Pythonically,
- 5:01which was another thing that took a while to kind of figure out and understand what that means.
- 5:05But yeah, really not try to do things that you would do in the C and C++ world.
- 5:11Look more at, okay, how do you do that in the Python world and just adjust to that.
- 5:15So, yeah, there's a definite period of changing.
- 5:18Yeah, that's interesting.
- 5:18I still remember that it seemed really odd to me, like using white space for managing structure and stuff.
- 5:24And then I got really comfortable.
- 5:27It really took a few hours to actually get comfortable.
- 5:29But then a week or so later, I went back and I'm like, whoa, what are all these symbols?
- 5:33And why is all this stuff here?
- 5:34This is so not fun anymore.
- 5:35And like a week ago, I really loved it.
- 5:37It was so weird.
- 5:38Oh, yeah, exactly.
- 5:38And the problem is, unfortunately, with a lot of the curly braces, everyone has a different style.
- 5:42So you might read some code that looks completely different from a different style of code.
- 5:46And so it is nice that it makes things a little bit more uniform with the spacing.
- 5:50Yeah, yeah, for sure.
- 5:51For sure.
- 5:52And then an article that just came out recently, it was, I don't remember the title exactly,
- 5:57but it was something like Python slow and I don't care.
- 6:00And the idea was, we should be optimizing for the programmer in a lot of cases, much more
- 6:06than we should be optimizing for high performance or close to the metal.
- 6:11Do you think that's kind of happening in like small hardware type stuff?
- 6:15Like Python is making it more accessible and that's way better than making it, you know,
- 6:1810% faster or something?
- 6:20Yeah, I totally agree.
- 6:21And it's definitely a big priority, I think, of, yeah, making things easier to create and
- 6:26understand, especially with a lot of devices and things that are coming out today.
- 6:30You know, the big buzzword is the Internet of Things, IoT, where every device has to be connected
- 6:35to the Internet for better or worse, unfortunately, in some cases.
- 6:38But, you know, in those cases, you're usually talking to like web services and dealing with
- 6:43like parsing a lot of data.
- 6:45And so writing that kind of code in C and C++, it's doable, but, you know, it's almost like
- 6:52a field of landmines where it's very easy to have like buffer issues or it's sometimes
- 6:56just really cumbersome to like parse JSON data, for example.
- 7:00But that's where a language like Python is great because you've got a lot of libraries that
- 7:04you can use or just the syntax can be a little bit simpler.
- 7:07So I think that's where we'll start to see Python really shine is that when you have these
- 7:12more complex applications where, yeah, you don't really care about sending, like controlling
- 7:17some signal at some super high speed and when you do care about that, you know, there are
- 7:22ways that you can say, oh, well, we'll just write that code in C or C++, put the performance
- 7:26critical code in a language that makes sense for that.
- 7:29But then all of your business logic, all of the things that you care about, all of how
- 7:32your application wants to work, do that in a higher level language so that it's a little
- 7:36easier to understand, easier to change.
- 7:38You know, you can build your minimum viable product or whatever.
- 7:40You can iterate on it a little bit faster with it.
- 7:43So, yeah, I think it's definitely an important thing to consider with Python is that you have
- 7:47that simplicity that helps you do things faster when you don't necessarily need like that
- 7:52super critical hardware speed.
- 7:53Right.
- 7:54The speed of innovation might be more important than how fast your nest can report the temperature
- 8:00or whatever.
- 8:00Exactly.
- 8:01Yeah.
- 8:02So what do you do day to day?
- 8:03You work at Adafruit, right?
- 8:04Yeah, exactly.
- 8:05Right.
- 8:05So I work for Adafruit and basically I, so my title is engineer, but I do a lot of things from
- 8:11the software side.
- 8:12So I have a background in software, but I did a little bit of hardware also in college.
- 8:16I have a computer science degree, but did kind of a mixed computer engineering.
- 8:20And basically I do a lot of the software and I originally started doing things with Raspberry
- 8:25Pi.
- 8:25So Adafruit builds a lot of hardware, a lot of educational hardware and sensors and boards
- 8:30and, you know, things like lights that you can control or motors that you can move around.
- 8:35But a lot of that stuff wasn't, well, it was originally written or created to work with platforms
- 8:40like Arduino, which are these little microcontrollers that you program directly.
- 8:44But then things like the Raspberry Pi came around and we'll talk more about that later,
- 8:47I'm sure.
- 8:47But the Raspberry Pi is a platform that's more of a Linux based system that you can run actual
- 8:52CPython on, on that system.
- 8:54And so maybe three or four years ago or so, I came around, I was doing a lot of stuff for
- 8:59Adafruit and they brought me on to help port a lot of the drivers that they had in the
- 9:04Arduino world to the Raspberry Pi.
- 9:06So to convert that code from C and C++ to Python code.
- 9:10So I did a lot of that and then just got a lot more involved in kind of the products that
- 9:15Adafruit creates and, you know, helping to support them.
- 9:17So yeah, the day-to-day for me is doing a lot of things like usually there's certain projects
- 9:23that we're working on.
- 9:24You know, there's maybe a lot of things in like the Raspberry Pi world, like drivers to
- 9:29write or to support.
- 9:31There are a lot of projects that we do also because a big thing that Adafruit does is teach
- 9:36people how to use stuff.
- 9:37So we show people, you know, it's not just good enough to sell you a board that lights up
- 9:41and does things.
- 9:42You have to understand how to use that and how to control it yourself.
- 9:45And so we create a lot of different content, like guides and tutorials that walk you through
- 9:50how to use a product, but they'll even walk through concepts of like, okay, here's how
- 9:55temperature sensors work.
- 9:56And here's how, you know, maybe you calibrate them.
- 9:59And here's how the equations work to convert the raw data into temperature reading and things
- 10:04like that.
- 10:04So it's just a lot of interesting, you know, knowledge to share that helps people learn
- 10:09and they can kind of build on that knowledge to build different things and do their own
- 10:12projects.
- 10:13So yeah, I'll do guides and things.
- 10:14And then in recent years, we've gotten into video because that's kind of become the new
- 10:19medium as far as like how people learn things.
- 10:22You know, the internet started out just as a text thing.
- 10:26And nowadays, you know, like Netflix, I think it's like 90% of all the bandwidth on the internet.
- 10:29So video is such a critical thing that, you know, we're there on YouTube and actually Twitch
- 10:35and some of these live streaming platforms too.
- 10:37So I do some of those things too.
- 10:38I do some videos.
- 10:39I try to do like a video every week, just kind of showing off maybe things that I'm hacking
- 10:43on.
- 10:43Or if I did like a guide or tutorial, kind of walking through how to do that.
- 10:47So yeah, it's a lot of kind of showing people how things work.
- 10:49Yeah.
- 10:50That sounds like a really fun job.
- 10:51So I heard just the other day that YouTube is the second largest search engine on the
- 10:57internet.
- 10:57Oh, wow.
- 10:58Bigger than Bing, bigger than Yahoo, bigger than, you know, a bunch of others, right?
- 11:03There's Google and then there's YouTube.
- 11:04And so, yeah, for the kind of stuff that you're doing, you definitely want to be putting your
- 11:08guides there and whatnot, right?
- 11:10Yep, exactly.
- 11:11Yeah.
- 11:11It sounds like a really fun job that you kind of get to see what people need to know
- 11:15and then just like come up with these little projects for them, right?
- 11:18Yeah, no, it definitely is.
- 11:19I would definitely consider it maybe like a dream job in some ways because yeah, it is
- 11:24really cool to have a lot of kind of freedom to build things that, you know, are interesting
- 11:29to me.
- 11:30And then, yeah, to show people how I build things.
- 11:32You know, I kind of think of myself in some ways as like, if you remember Bob Ross, who did
- 11:36the joy of painting, you know, do these instructional videos on PBS and he had the amazing
- 11:40hair, the Afro.
- 11:41I don't have the Afro, unfortunately, but I kind of think of myself and this is, you know,
- 11:45I don't want to be too presumptuous, but, you know, I think of myself in some ways as a Bob
- 11:51Ross, but more for code.
- 11:53So like showing people, you know, how do you do this project?
- 11:58Or for example, I'll do like videos maybe that show how I convert a driver to run on the
- 12:04Raspberry Pi and how to write it in Python.
- 12:05And I like to show kind of that process of creating that driver and show like even the
- 12:10mistakes and things that happen as I code this up.
- 12:13And, you know, I get some of the math wrong.
- 12:15And so you can watch me fidget around and figure out like debug this thing.
- 12:18Because, you know, I think back to when I was learning and it was so hard to just understand,
- 12:24you know, to make that leap from beginner to more experienced programmer.
- 12:27Because back in my day, you know, early days, the internet, it was like, you'd be lucky to find maybe a text file or something that explains how something works.
- 12:35You know, you'd be going to the bookstore and reading these three, 400 page books and hoping to understand things.
- 12:40You know, whereas now I'm hoping that maybe, you know, the 13 year old me kid out there could watch me and hopefully learn a little bit and kind of see like, okay, yeah, this is how I can get into programming or how things can work for this.
- 12:52So, yeah.
- 12:53Yeah.
- 12:53It sounds super fun.
- 12:55Super fun.
- 12:55So let's talk a little bit about microcontrollers.
- 12:58So you said that there's Arduino, which is a microcontroller.
- 13:01And then there's Raspberry Pi, which is more like a computer on a board or something like that.
- 13:06Right.
- 13:06What's the difference?
- 13:07Like when would I know to call which?
- 13:09Because I didn't.
- 13:09Yeah.
- 13:10I didn't study hardware in college.
- 13:11I studied, you know, math and programming, right?
- 13:14So good question.
- 13:15And the honest answer is it's kind of a gray area because, you know, when you get down to it, they're both really similar.
- 13:22So like the computer that, you know, that people are using right now, like if you're listening to this on your phone or on your desktop computer, on your laptop, you know, that has a little CPU that just runs instructions.
- 13:32And so a microcontroller is the exact same thing.
- 13:35It's just a tiny little CPU that runs program instructions and it can do math.
- 13:39It can do all kinds of processing.
- 13:41But the big difference is usually that the microcontrollers are much more constrained.
- 13:46So they have much less memory.
- 13:49So your computer or even your phone, like I think the new phones these days have like four gigabytes of memory, which is kind of insane to me.
- 13:55You know, you have a lot of resources like that, whereas a microcontroller, an Arduino has, for example, two kilobytes of RAM.
- 14:02So that's a huge difference as far as just the amount of things that you can store, the program state you can have.
- 14:09And then the processing speed is usually a lot different, too.
- 14:12So an Arduino is usually like 16 or 8 megahertz or so, whereas, you know, your phone or your laptop, your computer is well into the multiple gigahertz, three, four gigahertz sometimes.
- 14:21So there's a big difference there.
- 14:24And there are some other differences as far as your computer is usually built to run an operating system, which is kind of a layer that does a lot of work for you.
- 14:32So it can talk to your peripherals and it can control access to a lot of things.
- 14:38Whereas on a microcontroller, you're usually doing things what they call bare metal, where you write your code and it might be in a higher level language like C or C++, but it gets compiled down into the raw assembly language that just controls that processor directly and has complete control over all the memory.
- 14:54There's nothing stopping it to say, hey, stop your program for a little bit to let another program run.
- 14:59You know, whereas on your desktop computer, you've got all kinds of programs running for that.
- 15:03So it's kind of a spectrum.
- 15:04Yeah.
- 15:05And that, you know, the Raspberry Pi is maybe on one end where it's the more computer style where you have a full Linux operating system and it's running multiple programs and you have a little bit less direct access to the hardware.
- 15:18You still do have pretty close control to the hardware.
- 15:21But I mean, ultimately, there's maybe some control that you give up in that case.
- 15:24Whereas with Arduino, yeah, you've got a much less powerful microcontroller.
- 15:29Sometimes in a lot of cases, they're a little bit less expensive, though, because of that.
- 15:33And so you've got less power, less memory, but more control over the hardware.
- 15:37So your code runs directly on the CPU.
- 15:39And you can know, for example, if you write a loop, how long it's going to run and, you know, that nothing's going to stop it or keep it from going.
- 15:46Right.
- 15:46Basically, your program, it's the whole thing, right?
- 15:50It has access to the hardware.
- 15:52It just runs and there's nothing.
- 15:53There's no other preemptive multithreading or anything like that, right?
- 15:56Exactly.
- 15:57Yep.
- 15:57It's the only thing that chip knows how to do is run your program.
- 16:01Oh, very cool.
- 16:02So which one would you say is easier to work with?
- 16:04Ah, that's a great question.
- 16:05So, you know, there are advantages to both.
- 16:08In the microcontroller world, for the longest time, it was a little bit hard to get started,
- 16:13especially before these platforms like Arduino came around.
- 16:17Because in a lot of cases, those microcontrollers sometimes have very custom or specific tool chains
- 16:22where you couldn't just pick up, you know, the GCC compiler years ago and use that to write code for the processor that Arduino uses.
- 16:30You know, nowadays you can because they've added support to those platforms.
- 16:33But for a while, you had to get these custom tool chains and you'd have to figure them out.
- 16:37And they'd usually be more constrained and you'd have to know how to set those things up.
- 16:40So it was a big barrier to entry.
- 16:42And then platforms like Arduino came around and said, hey, let's simplify all that stuff.
- 16:46And let's just give you this prepackaged environment, like a little IDE that you can download that does all that for you.
- 16:52So you just write in your code and you still have to use kind of maybe those higher level or the C and C++ style languages, but we'll make it easier.
- 17:00So it's not as hard to get started in microcontrollers, whereas something like the Raspberry Pi that runs Linux,
- 17:06if you're already familiar with using Python on your desktop, just installing the Python, the CPython interpreter, it's really similar on those platforms.
- 17:15And so it's just, you know, learning, OK, how to hook up this Raspberry Pi and maybe how to connect to it.
- 17:19And then once you're connected, it's no different from your computer.
- 17:22So, you know, if you have absolutely no hardware experience at all and you're used to Python on your desktop,
- 17:29the Raspberry Pi might be a little bit easier to get started with, but Arduino and those systems aren't as bad.
- 17:35The one difference with Arduino, though, is that the language is different.
- 17:38So it's, you know, you have to use C and C++, but it's a little bit easier when you use some of the systems that give you,
- 17:43you know, here is a development environment that's kind of ready to go for that.
- 17:46So, you know, I'd say start with Raspberry Pi, but also look at things like Arduino and MicroPython also that I'm sure we'll talk about,
- 17:54you know, how to get into Python on some of these little microcontrollers.
- 17:58Yeah, absolutely. I mean, the devices are interesting, but to the Python audience, it's like, OK, well, how do I use Python on this device?
- 18:06Right. So back on episode 17, almost two years ago, I talked to Damian George, who was one of the guys that created MicroPython.
- 18:14Maybe tell us a little bit about what that is.
- 18:17Yeah, totally right. So MicroPython, it's a really cool project.
- 18:21And yeah, like you said, it was created by Damian George, I think maybe four years ago in 2013 or so.
- 18:26And it's basically a Python interpreter that runs on these small memory constrained environments,
- 18:32like little boards that might be used with Arduino.
- 18:35Now, it doesn't run on what is typically the Arduino that everyone uses, the Arduino Uno.
- 18:41That's a really low end. That's the one with two kilobytes of memory.
- 18:44It runs on a little bit larger microcontrollers.
- 18:47So microcontrollers that have around like 32 kilobytes of memory or so, or even much more in some cases.
- 18:53But it is a Python interpreter. And the nice thing is, it's not the first Python interpreter that runs on hardware.
- 18:59I think there have been a few other embedded Python projects, and there still are some other ones around.
- 19:04But one of the big goals and things that kind of separates from other Python on hardware implementations is that it tries to be a very strict implementation of the Python 3.0 core language.
- 19:15So basically, you know, all of the features that you would expect in Python as far as like classes and functions, you know, just the basic syntax.
- 19:24Most pretty much all of that is there.
- 19:27I think something like 90% of it is implemented and they're working on getting more support.
- 19:30So that makes it really cool as a Python user because you can kind of dive in and there are less surprises.
- 19:35You know, you do things that are a little more natural and it's, in most cases, works.
- 19:39The one thing I should say, though, is that not all of the Python library is implemented, though.
- 19:44So things like all the things that you've probably come to know and love on the Python world of just being able to import a JSON parser or, you know, import like a CSV parser or something like that.
- 19:52Some of that stuff is there in the MicroPython world.
- 19:54But again, these run on these tiny little microcontrollers that just have kilobytes of memory.
- 19:59So you have to make some tradeoffs there, unfortunately.
- 20:02Yeah, that's a pretty serious constrained environment compared to, you know, 16 gigs of RAM.
- 20:08Exactly.
- 20:09Yep.
- 20:09And it's just different priorities, right?
- 20:11So how do you get Python to work in that kind of a world with much less memory?
- 20:16So you basically put this on one of the microcontrollers, you put your Python code there, and then your Python code basically is the only thing running on that chip, more or less, right?
- 20:24Exactly.
- 20:25Yep.
- 20:25So there's not necessarily like an operating system that's running.
- 20:29Your code is actually it's compiled into a bytecode internally by MicroPython, and then it executes that bytecode.
- 20:36So it can be very dynamic and do all kinds of cool, fun kind of Python things.
- 20:40Nice.
- 20:40Can you pip install to it?
- 20:41A lot of that stuff is being kind of figured out in the MicroPython world.
- 20:44So like I said, MicroPython is still pretty new.
- 20:46Like it's only maybe four years old, which is actually really new in the grand scheme of things.
- 20:51And so there's not a super solid story yet on like libraries and modules.
- 20:57So MicroPython does have a concept of it supports packages where you can have a folder structure within a init.py,
- 21:05and you can have, you know, modules and things that you import based on that.
- 21:09And you can actually do this pre-compilation step where you convert a Python file into what's called an MPY file,
- 21:16which is just pre-compiling it into bytecode because, again, it's optimizing for the memory usage.
- 21:21Because if you're just storing the raw Python source code of your program, that's pretty large.
- 21:26You have, you know, big text files.
- 21:28And so if you're trying to fit a bunch of Python code onto like 256 kilobytes of flash memory, you're going to run out at some point.
- 21:34And so there are little optimizations you can make like pre-compiling some of the stuff into bytecode.
- 21:39But yeah, there's no pip.
- 21:41Well, there is a pip for MicroPython, but it's not the same pip that you might expect on the desktop.
- 21:48So it's not like you connect to your board and run a pip command and it goes to the internet and downloads your package.
- 21:55It's more on your desktop.
- 21:57You can grab these MicroPython libraries and then you still have to kind of get them onto your board and import them yourself.
- 22:05So it's, I think in the future, though, there'll probably be more of a story for how, you know, you get packages and things.
- 22:12But again, in the MicroPython world, they're definitely, they're trying to follow the Python kind of paradigms and systems out there.
- 22:18And so, you know, using things like PyPI and pip and the tools like that to make it work.
- 22:23This portion of Talk Python is brought to you by Advanced Digital.
- 22:26How would you like to build one of the most visited news sites in the U.S.?
- 22:30That sounds fun.
- 22:31The folks at Advanced Digital would love to talk to you.
- 22:33They're primarily a Python shop located in beautiful Jersey City, just one subway stop from lower Manhattan.
- 22:39Spend your time building an amazing web app with Python and do it with a small team of developers focused on agile development.
- 22:45Are you going to miss PyCon this year because your company wouldn't fund the travel and expense?
- 22:49If you join this team, they'll cover your conference and training initiatives.
- 22:53It's time to take your Python to the next level.
- 22:55Build an amazing web app.
- 22:57Get started by visiting python.advance.net right now.
- 23:02One of the things that Damian talked about was that you could basically hook a Lambda expression directly up to a hardware interrupt.
- 23:10And that kind of blew my mind.
- 23:11Yeah, it's really cool.
- 23:13I love it too because, like I said, with Python, I love how you can make it work the way you want.
- 23:18So if you want to do like really cool functional programming, you've got all of the constructs to do that in Python.
- 23:23You've got like filter and map and all these cool functions you can chain together and stuff and do reactive programming, whatever.
- 23:28And it's fascinating to transfer that over to the hardware world and start playing with it.
- 23:33Because at the end of the day, I mean, hardware, it's just a different set of functions you're calling.
- 23:38Like you're calling functions to control the voltage of an output or to read an analog input or something like that.
- 23:44So having that core language and, yeah, doing Lambda expressions with hardware interrupts, I mean, it is a really cool thing.
- 23:50And again, because it's so interesting to me because for the longest time, we really haven't had that in the hardware world.
- 23:56You know, you've had the lower level languages like C and C++ that are very static and everything is done up front ahead of time because you need it optimized for memory and stuff like that.
- 24:05So, yeah, it's kind of a brave new world in some ways of figuring out like because, yes, you can hook up a Lambda expression to a hardware interrupt.
- 24:11But, you know, maybe we'll learn like, well, maybe you shouldn't.
- 24:14You know, maybe there are reasons why it maybe doesn't make sense or it gets too complex or something.
- 24:18But that'll be fun to figure out what works and what doesn't work.
- 24:20Yeah, absolutely.
- 24:21It's being new.
- 24:22It really makes it exciting as well.
- 24:25When would make a lot of sense to use MicroPython and when would you maybe pick something else?
- 24:30MicroPython, it's good at some things and it's maybe not as good as at other things right now in the world, in the embedded world.
- 24:37Because, again, you can't get away from the fact that you're running on a much more constrained environment.
- 24:42So you have much less memory than your desktop computer.
- 24:46So things that you might do in the Python world that you might not even realize take a lot of resources, you know, like having a tight loop that's creating a bunch of objects, which might just be a few lines of Python code.
- 24:58You know, you might not even realize what's happening underneath the behind the scenes there.
- 25:02That might not be great in MicroPython because, sure, it can run that code, but it's going to be allocating a lot of memory.
- 25:09And then you're going to be having this garbage collector kicking in and things.
- 25:12So MicroPython, it's really good at, like I said, doing the high-level business logic of, you know, I'm creating like an IoT device.
- 25:21And I need to talk to a web service and get some data and process it and then maybe actuate some devices or maybe read some sensors and then send that reading up into the cloud.
- 25:32So it's really good at being kind of that glue that goes between the low-level hardware and other different things that you're doing.
- 25:39So it's great for that kind of thing.
- 25:40It's also great for, like, when you want to update and change how something works.
- 25:44Because, again, it's all interpreted code, so you can change the code on the fly.
- 25:48You know, if you want to change how your program runs with, like, Arduino or C and C++ or older kind of embedded-style programming,
- 25:55you have to, like, connect that board to your computer and just completely reprogram it.
- 26:00Whereas with MicroPython, you know, if you can just change that Python file,
- 26:03and it could even just be, like, downloading that file from the Internet itself.
- 26:06You know, you could send new code to the board and it can start running it.
- 26:09And actually, that's a cool use case that I heard about recently.
- 26:12I think the European Space Agency, they've been looking at MicroPython and potentially going to use that on satellites
- 26:18because they like that idea of being able to send new code up to the satellites and have it just run that code
- 26:25instead of having to reprogram the satellite while it's in orbit.
- 26:28Because sometimes things go wrong.
- 26:30You know, you're writing a flash memory and something might get corrupted.
- 26:33And so I think they like having that kind of capability.
- 26:36And so you can do that with MicroPython.
- 26:37And then the other cool thing, too, that you get because it's interpreted, you've got a REPL.
- 26:41So you've got an ability to just connect and arbitrarily run Python code.
- 26:46And so that's a really good case for, like, education and learning.
- 26:51And something I think that we'll see a lot with MicroPython,
- 26:53where it's a lot easier to learn about things like hardware
- 26:56when you can just connect to your board and run a function that says turn on this LED
- 27:01or turn off this LED or read this microphone value.
- 27:05And you can get that result back directly and kind of play with it
- 27:08and, you know, maybe build little programs from that.
- 27:10So, you know, MicroPython is really good at that stuff.
- 27:12Yeah, that sounds so much better than I'm going to recompile and ship a new binary
- 27:17and restart the device and all that kind of stuff, right?
- 27:20Exactly right.
- 27:21There's just more steps, more complexity.
- 27:23And especially for people that are learning things, it's, you know,
- 27:26it's difficult enough to even just understand how the tools work and things like that.
- 27:29And so just the less things that you have to learn, the easier it'll be
- 27:33and the more it opens up to more people to use.
- 27:36Oh, yeah, that's really great.
- 27:37And could you have the device auto-update itself
- 27:40or the Python auto-update its own code on MicroPython with over-the-air updates type things?
- 27:46Yeah, you definitely could.
- 27:47So, and there are a few different things you could do.
- 27:49So kind of the way MicroPython works is there's an interpreter,
- 27:54like a firmware that's written onto the chip that has the implementation of MicroPython.
- 27:58So it has things like how it converts your Python code into bytecode and how it executes that
- 28:04and how it turns your Python functions that might talk to hardware,
- 28:08how those actually access the hardware.
- 28:10And then there's actually a little file system that MicroPython adds,
- 28:14which is one of the cool things that it does differently, you know,
- 28:17or maybe that's an advantage over systems like Arduino.
- 28:21In MicroPython, there's a little file system that all the boards have,
- 28:25and it's just like a fat file system.
- 28:27So you can put .py files on there, but you can also put like text and data files on there.
- 28:32And so that's a case where, yeah, if you want to change your program code,
- 28:35you just have to figure out a way to update that file system.
- 28:38And you can usually write to that file system using all of the same Python functions,
- 28:42like open, read, write.
- 28:44So you could build a project where, you know, maybe it looks to a web service
- 28:48to download its latest code and it can see, okay, what's the version of my code
- 28:52and grab the latest code and update it.
- 28:54And so that would update your Python code.
- 28:56And then updating the MicroPython firmware itself, it's a little more challenging.
- 29:00There are ways to do that.
- 29:02Some boards and systems support this concept of, you know, doing an over-the-air update.
- 29:06It's usually a little more complicated because when you're changing the firmware itself,
- 29:10you sometimes have to have like two copies of it,
- 29:12and then you tell the microcontroller to kind of swap over.
- 29:14Yeah, I was thinking more of just your code, right, and just letting the MicroPython be.
- 29:19Exactly, yeah.
- 29:19And it's great for that because it's just a .py file.
- 29:23And so if you've got a way to tell the board to update that file,
- 29:26then it's, in a lot of cases, it's as easy as that.
- 29:29I'm thrilled to hear that the European Space Agency might be using it.
- 29:32How cool is that?
- 29:33Yeah, Python in space.
- 29:35That is just too cool, I think.
- 29:36I think, yeah, really, really neat.
- 29:38Yeah, you know, you hear about the thing is not responding,
- 29:42this rover is lost because, you know, something went wrong with its software and whatnot.
- 29:48This ability to go, we're going to ship you a few bytes of a new PY file,
- 29:51and you're going to come back to life.
- 29:53Like, that's pretty cool.
- 29:54Yeah, oh yeah, totally.
- 29:55And, you know, maybe not too far off in the future,
- 29:57maybe it'll be something that we could even do ourselves.
- 30:00You know, they've got cube satellites,
- 30:01and maybe when, you know, you've got kind of private enterprises sending shuttles and rockets and things up.
- 30:07And maybe one day there'll be a Raspberry Pi that I can send up and start, you know, controlling myself with Python.
- 30:13That would be really fun.
- 30:14Yeah, hook a little camera to it.
- 30:15That'd be awesome.
- 30:16Oh, yeah.
- 30:16All right, so that's when you, when it's a good idea to use it,
- 30:21maybe when would you say probably not the best option?
- 30:24The one big thing, though, with MicroPython is, again, it's interpreted,
- 30:27so you do pay a cost as far as performance goes with that.
- 30:30And it's a significant cost in some cases because, yeah, these little microcontrollers,
- 30:34they run at like, you know, maybe 80 megahertz, 40 megahertz or so.
- 30:39It's like a 486DX.
- 30:40Yeah, exactly right.
- 30:41So the kind of computer, when I got started programming, I think it was a 486, it was 50 megahertz.
- 30:46And even that's probably faster than some of the systems we have now.
- 30:48So, yeah, for a lot of people today that maybe got into programming later,
- 30:52they might not realize that computers back then were pretty slow.
- 30:55So that could be a little bit of a shock to some people where,
- 30:59especially if you've done things in Arduino, like blinking LED, you have a little loop,
- 31:03you turn it on, you turn it off, you sleep in between there.
- 31:05You try the same thing in Python and it might not work as well,
- 31:09or at least it might not go as fast as Arduino.
- 31:11So things that are timing critical, where like you're trying to generate a signal
- 31:16that maybe tells some hardware, you know, like talking to a servo,
- 31:19you need to generate a signal that has a very specific pulse width,
- 31:23or talking to a lot of these RGB LEDs, these NeoPixel strands.
- 31:28They need a very specific pulse train sent to them.
- 31:31So that type of stuff is more difficult with MicroPython because you've got less speed because it's interpreted.
- 31:37And so that just means that rather than your code running directly on the CPU,
- 31:42you've got code on the CPU that has to load your code from memory and then figure out,
- 31:47okay, what is it doing, and then actually convert that into CPU instructions.
- 31:50So there's overhead with that.
- 31:51And then there's also a little sometimes overhead with the memory management where,
- 31:55you know, in the Python world, you don't worry about managing memory because Python does that for you.
- 31:59But in the embedded world, when you're in this memory constrained environments,
- 32:02it doesn't come for free.
- 32:04Like there's no magic wand.
- 32:05You know, just when MicroPython manages your memory, it might not manage it the best way.
- 32:09You know, it might be creating and allocating memory,
- 32:12and then it has to go clean things up.
- 32:13And so that takes some time.
- 32:14So anyways, long story short, things that are timing critical are more difficult in MicroPython.
- 32:19Things that need that direct access to the hardware sometimes are more difficult.
- 32:24But it doesn't have to always be the case.
- 32:27I guess I say more difficult, but I don't really mean that it's impossible to do that stuff
- 32:30because the really cool thing that MicroPython did is make itself very easily extensible
- 32:36so that you can combine both C code and Python code in the MicroPython firmware
- 32:41so that when you need to do that advanced signal generation,
- 32:44you know, you can drop down to a C function that you implement that does that
- 32:48and has very critical, you know, loop code and things like that
- 32:52and very tight constraints on like how much memory it uses.
- 32:54And then you can just expose that as a Python function.
- 32:57And it's very similar syntax to how you do C extensions in desktop and CPython.
- 33:01So yeah, that was my next question.
- 33:04That sounds like, you know, there's your escape hatch for those little parts that are really critical.
- 33:08Exactly. Yeah. And I think that kind of plays back to the really big advantage of MicroPython
- 33:12of, you know, getting to that world where you do your low level interface logic
- 33:16and all that performance critical code in C
- 33:19and then do all of your business logic and all that interesting stuff.
- 33:22You know, the things that make your smart device smart,
- 33:24do all of that in Python and you get all the advantages.
- 33:27You know, you get both advantages.
- 33:28You get maybe easier, faster to iterate in the Python code,
- 33:31but then all the low level and fast control in the C functions.
- 33:35Nice. So let me run some examples by you.
- 33:38And you tell me if like good or not good for MicroPython.
- 33:41So if I was like a farmer and I wanted to have like an automated irrigation system
- 33:47or something that managed, like watched the pH level of all my dirt around all my plants
- 33:53and reported that back and maybe, you know, controlled valves for more water or whatever.
- 33:58Right. It seems like something like that would be totally fine for MicroPython.
- 34:02Yeah, I think that'd be great.
- 34:03That's a good option because you're talking to little sensors.
- 34:06And in a lot of cases, those sensors have kind of standard interfaces.
- 34:09There are some protocols.
- 34:11One's called I squared C or another one's called SPI.
- 34:14And so MicroPython has a lot of good support for that.
- 34:16And your hardware itself kind of generates those signals and knows how to talk those protocols.
- 34:21So, yeah, it's easy to hook up external sensors in a lot of cases and just talk to those directly from MicroPython.
- 34:27So, yeah, that's a great case.
- 34:28And then when you want to report back to some central service, it's amazing because you've got, you know,
- 34:32all of the great Python syntax and fun things you can do there.
- 34:36So, yeah.
- 34:36Okay.
- 34:37That sounds really awesome.
- 34:38What if I wanted to outfit the front of my drone with a camera?
- 34:42I don't have a drone.
- 34:43My brother has a drone, but I don't.
- 34:45With a camera.
- 34:46And when it saw like another drone, it would change color or something like that.
- 34:50Like almost like an image recognition thing or, you know, something like that.
- 34:55Would that make any sense?
- 34:56Yeah.
- 34:56Well, so that's a good case.
- 34:57Drones are interesting because, yeah, with the drone case, you know, maybe that case of like recognizing a thing that you might be able to do that MicroPython.
- 35:04That would probably be a little more challenging just because when you get into like advanced image recognition stuff,
- 35:09you probably want to use something more like a Raspberry Pi where you can use like OpenCV and some of these really powerful and amazing image processing libraries.
- 35:18Because you probably don't want to have to like, you know, hand code a neural network or something in MicroPython yourself.
- 35:24Yeah, exactly.
- 35:25But if I want to use like TensorFlow or something, like it obviously wouldn't make any sense, right?
- 35:29Exactly.
- 35:30Yeah.
- 35:31So, you know, use, yeah, use the tool for that.
- 35:33But then the other thing with the drone too, you might think like, well, could I have the drone, you know, the code that controls the motors?
- 35:39Could that be in MicroPython?
- 35:40Like that's controlling the actual flight of the drone.
- 35:42And that might be a case where you wouldn't want to use MicroPython because that's a very critical control loop where you need a lot of speed.
- 35:51You know, you need just milliseconds and microseconds of the sensor detected.
- 35:55I'm tilting slightly.
- 35:56So now I need to offset this motor and make it spin a little bit faster.
- 36:00And if you've got a loop in Python that has all this interpreter overhead, that could be the difference between, you know, your drone crashing or it staying in the air there.
- 36:08So, you know, that's maybe a case where you wouldn't want MicroPython to do that really timing critical control loop.
- 36:14Right.
- 36:14Okay.
- 36:15But maybe if it was a Raspberry Pi, I could do like a C extension in there.
- 36:19Right.
- 36:20Something like that.
- 36:21Some combo.
- 36:21Exactly.
- 36:22Yeah.
- 36:22And actually, there's a board that's even better for drones these days.
- 36:26The BeagleBone boards.
- 36:27BeagleBone Black is one because they're kind of cool.
- 36:30They're like the Raspberry Pi, but they add a little microcontroller that sits alongside the main processor that runs Linux.
- 36:36So you can run code on there that the Linux operating system doesn't even touch at all.
- 36:41And so that's where you put your little super critical control loops and things like that.
- 36:45And then your Linux processor can communicate with it and send it instructions and things like that.
- 36:49So, yeah, lots of options in that case.
- 36:51That sounds really cool.
- 36:52So what other hardware could I use MicroPython on?
- 36:55Yeah.
- 36:55So great question.
- 36:56So, again, it's a little bit new.
- 36:57So it's only four years old.
- 36:59There's just maybe a handful of boards right now that support it.
- 37:02The original board was called the PyBoard, and it's a pretty powerful microcontroller.
- 37:06It's this STM.
- 37:08I think it's an F4.
- 37:09It's basically a fancy processor.
- 37:11It runs at a couple, I think, like 70 or so megahertz, something like that.
- 37:14That was kind of the first board.
- 37:16It has a lot of peripherals and features.
- 37:17And then the ESP8266 is another board that came around, and this is a really popular board.
- 37:23It started out as the brains behind an internet-connected light bulb.
- 37:27And then the company that created it, they released, I think, the developer tool chain.
- 37:31It's a company called Espressif.
- 37:33And they realized, like, oh, people kind of like hacking this thing.
- 37:36And, like, this is cool.
- 37:37Because it was just a little microcontroller with a Wi-Fi radio.
- 37:40So, you know, it could run code that talks to your Wi-Fi network and web services.
- 37:43And so people kind of ran with that, and they integrated it into Arduino, and, you know, people take a lot of control over it.
- 37:50But that became a platform for MicroPython.
- 37:52There was a big Kickstarter for it a few years ago.
- 37:54And that became a really great platform for MicroPython because it's the ESP8266 has a good amount of memory and has that Wi-Fi chip, so you can do lots of cool stuff.
- 38:02So that's a great chip.
- 38:03And then let's see.
- 38:04There are some other boards, the Wi-Fi and the Low-Py and some of these boards that Pycom creates that are basically similar to, like, the ESP8266, more Internet of Things oriented.
- 38:14But they're also, you know, kind of moderate amounts of speed and performance and things like that for it.
- 38:19And then I think the last board that's really interesting that we're probably going to see a lot more of these types of boards are the MicroBit.
- 38:26So the BBC MicroBit was this really neat little board over in England that they gave to, I think, all of the seventh grade students in the country.
- 38:34So, you know, they made, like, maybe millions of these boards or hundreds of thousands of them.
- 38:37And they're little boards that have these tiny little microcontrollers that are a little more powerful than an Arduino, but not much more powerful.
- 38:46I think they only have, like, 16 kilobytes of memory.
- 38:48And there was a really nice effort to port MicroPython to run on those boards.
- 38:52And the cool thing with the MicroBit is that it's not just the microprocessor.
- 38:55It has a few peripherals.
- 38:57So it has some LEDs.
- 38:58It has some buttons and things.
- 38:59And the idea with it was, you know, you give this to a kid who's learning programming and they can get started right away.
- 39:04They don't have to learn, like, how to solder all this stuff together or how to install a tool chain.
- 39:08They make the tools really nice and easy.
- 39:10And that's a really cool fit with MicroPython because with things like the REPL where you can just connect to the board and start running Python code.
- 39:18And the MicroBit, it's even cooler because you just literally pick up this board, plug it into your computer, connect to a terminal, and then you start typing Python code.
- 39:26And you're turning on LEDs and you're, like, controlling a speaker and you're making it, like, say things and listening to microphone stuff.
- 39:32That's really cool.
- 39:33Yeah.
- 39:33But does it ship with MicroPython?
- 39:35It does not.
- 39:36I don't think it ships with MicroPython, but it's really easy.
- 39:38They have a web editor.
- 39:39I think you, if you just search online for, like, the BBC web editor, you go to a web page and it will give you, like, you type in your Python code on the web page and you click a button.
- 39:47It gives you a file and then you just drag that file onto the board.
- 39:51Like, the board shows up as a USB drive and it programs itself based on that.
- 39:54So it's really easy to get kind of MicroPython going on it.
- 39:57This portion of Talk Python is brought to you by the Strangelube Conference.
- 40:03Do you love to present technical topics?
- 40:05Are you looking for your first major speaking event?
- 40:07The Strangelube Conference just announced their call for proposals.
- 40:11Whether you're interested in languages, web development, distributed systems, AI, security, or something else, be sure to submit a proposal to Strangelube by May 8th.
- 40:20Their opportunity grant applications for developers in underrepresented groups.
- 40:24Last year, they were able to grant travel, hotel, and admission for 115 attendees, and they're hoping to expand on that for 2017.
- 40:31Don't just attend the Strangelube Conference.
- 40:33Submit a talk and you'll be speaking at a beautiful venue in St. Louis, Missouri, September 28th to 30th.
- 40:39Visit talkpython.fm/Strangelube to submit your proposal.
- 40:43Hurry.
- 40:44It closes May 8th.
- 40:46So, one more hardware question for you.
- 40:48One of my, well, I'd say my favorite smartwatch is the Pebble Time Round.
- 40:53And, you know, really thin, really small, little lightweight smartwatch.
- 40:57And those guys recently went out of business, which is a super sad story across the board.
- 41:01But could you build something like that?
- 41:04Like, could you build a smartwatch type thing with MicroPython?
- 41:07Oh, yeah, definitely.
- 41:08And I think that would be a great project with MicroPython.
- 41:10So, you know, like, if you just think of the components of the smartwatch, it's pretty straightforward.
- 41:15I mean, you've got your processor.
- 41:16You have a display of some sort.
- 41:19And most displays have a standard interface, like either this I2C or SPI protocol that most of the MicroPython boards support.
- 41:26So, you could get, like, a little OLED, an organic LED display.
- 41:30Or there even are e-paper displays, which are the really nice kind of, like, the Kindle style or what the original Pebbles used.
- 41:35Yeah, the Pebble Time Round has, like, a color E-ing.
- 41:38Exactly, yeah.
- 41:39So, you could get one of those displays.
- 41:40And that talks usually like an I2C or an SPI protocol.
- 41:43You'd have to figure out from the data sheet, you know, like, what are the commands to send it and things like that.
- 41:47But that would be perfect.
- 41:49That's easy to connect to the board.
- 41:50And then the actual clock part, you might want, like, a real-time clock connected to it where, you know,
- 41:56these are little hardware peripherals that have, or basically little watches that just run off of a coin cell battery
- 42:01so that, you know, your main watch might go to sleep just to save power.
- 42:05But this thing will keep the time running so that it always knows what's happening.
- 42:09And that's all you need for maybe a basic smartwatch or a basic watch.
- 42:13And then, you know, if you use a board that has, like, a Bluetooth radio or a Wi-Fi radio,
- 42:18then you can go crazy and add all kinds of things like, okay, you know,
- 42:21I want my watch to connect to some internet service and pull down, you know, the weather or the time.
- 42:25Or things like that from it.
- 42:27So, yeah.
- 42:27And that would be a great case for MicroPython, too.
- 42:29Because it's, again, you know, you want to write all of that fun watch logic in, like, Python code.
- 42:34But you don't want to write, you know, necessarily maybe, like, controlling the E-ink display.
- 42:39Like, that's maybe not as interesting.
- 42:40And so you'd maybe use a library or something like that or some C code, potentially, to talk to it.
- 42:44Yeah.
- 42:45And it would also have a great extensibility model.
- 42:47You want to write apps for it?
- 42:48Give a little Python file or something like that, right?
- 42:50Oh, that would be too cool.
- 42:52I mean, wouldn't that be amazing?
- 42:53You just plug your watch into your computer and you just edit .py files on it?
- 42:56That would be really cool.
- 42:57Like, 13-year-old me would just be, you know, probably freaking out.
- 43:01That would be so much easier than trying to figure out, like, I don't know.
- 43:03It would be more interesting than, I guess, like, opening up QBasic and loading nibbles or Gorilla or something like that.
- 43:09Yeah, for sure.
- 43:09All right.
- 43:10So let's move off of MicroPython just a little bit and sort of into the broader hardware world and talk about the company that you work for and what you guys are doing there with Adafruit.
- 43:20So what is Adafruit?
- 43:21Yeah.
- 43:22So Adafruit, it is an electronics company that helps make electronics more accessible to people.
- 43:28So it was founded about, I think, 11 years ago in 2005 by Lamore Fried.
- 43:33And she goes by the handle Lady Ada.
- 43:34Founded in her dorm room at MIT.
- 43:37So she's a brilliant electrical engineer.
- 43:39And really, the core DNA of Adafruit is showing people how things work, like, taking the mystery out of electronics.
- 43:47So a lot of things that Adafruit did early on were things around, like, Arduino, or even before Arduino actually even existed, of, like, hey, I'm building, I'm an artist, and I'm making a really cool installation, and I need to control some of these lights.
- 44:02I know how I want to animate them, but, like, I'm looking at all these wires, and what do I do now, and how do I make this stuff work?
- 44:07And so Lamore did a lot of great stuff.
- 44:10She had a website, LadyAda.net, where she would show tutorials that show, hey, here's how you program this little microcontroller.
- 44:16Here's how you set up this crazy tool chain.
- 44:19And, you know, make it as easy as just follow these steps, and you'll get this stuff working.
- 44:23And it just built on top of that, because, you know, people realize, like, oh, okay, well, now I can program this microcontroller, but I want to connect it to things.
- 44:30You know, I want to talk to this sensor.
- 44:31And unfortunately, you know, for a while, it was difficult in that if you wanted to, you know, maybe use, like, a temperature sensor, well, you'd have to build a board that has all the supporting hardware for it.
- 44:42Because you can buy the sensor, but when you read the data sheet for it, which, first of all, you have to figure out how to read data sheets, you know, then you realize, like, oh, man, I have to put this on a board, and I have to connect all these, like, components to it, maybe some capacitors or other things to it.
- 44:53So then at that point, it's like, oh, uh-oh, now I have to learn how to make a circuit board.
- 44:57So that's a little annoying and difficult.
- 44:59And so Adafruit does a lot of things, like builds a lot of breakout boards, you know, to take some of those interesting sensors and things and give you a board that just does all that grunt work for you of, okay, I buy this board, and then it gives me these connections that I care about.
- 45:12Like, you know, maybe the I2C or the SPI connection so that I can just run a few wires to my Raspberry Pi, and then you grab the code that we publish that knows how to talk to this device so that now you can just start running some Python code on your Raspberry Pi and dealing with it.
- 45:27So, again, it's all in that pursuit of making electronics easier for people because we want to open it up and make it less of, you know, an electrical engineer's playground and more of a playground for anyone.
- 45:37So that's the cool thing, and the thing that I get a lot of joy out of is just seeing what people do with this.
- 45:41Like, you know, seeing someone who's an artist who's totally intimidated by, you know, hardware and circuits and thinking, you know, there's no way I can make this thing work.
- 45:50And then building really cool interactive things or just, you know, things that blow your mind as far as, like, interesting art installations or even beyond that, like, things like students and learning and just hobbyists.
- 46:01Like, I still love just the projects that people do of, like, hey, I have my barbecue grill and I want to build a temperature sensor to, you know, maybe control, like, the opening and closing the vents on it to, you know, smoke a brisket or something like that.
- 46:13You know, just fun things that someone could do.
- 46:15Like, sure, you could buy, like, probably a $4,000 or $5,000 barbecue that does that.
- 46:19So I like the kind of do-it-yourself aspect of that, too.
- 46:22And, again, Adafruit is all about helping people do things themselves and, you know, taking the mystery out of a lot of this electronic stuff.
- 46:28Yeah, that's really cool.
- 46:30That's a great mission.
- 46:30You know, create more creators, right?
- 46:33Exactly, yeah.
- 46:33Limor was talking about open-source hardware at Adafruit.
- 46:37And I can imagine what that means, but what do you guys think that means to you there?
- 46:41Open-source hardware and open-source in general, again, is kind of a core of Adafruit because from the very beginning, you know, Adafruit was created to teach people how things work.
- 46:51And so it wouldn't have been very successful if it's like, well, get this board, but, you know, if you want to know how it works, that's off-limits.
- 46:57You know, we can't tell you that.
- 46:58That's our secret sauce or whatever.
- 47:00You know, we kind of realized early on that telling people how things work doesn't hurt.
- 47:04You know, it helps you because people will just build on your thing and they'll use more of your stuff because of that.
- 47:09But at the core, so open-source hardware, there is actually the Open-source Hardware Association, which has a concept.
- 47:16I think there's like an official definition.
- 47:18But the basic idea is, you know, you release the schematics and the build materials and how your device is built so that someone could replicate it themselves if they wanted to.
- 47:29The same idea with software.
- 47:30So, you know, something like the GCC compiler, you know, all of that source code is out there so that if you want to add a new language to it or whatever, you can take it and you can study it and you can extend it.
- 47:40And all of that code is available for you to change.
- 47:43Same thing with open-source hardware.
- 47:44You know, if you want to build one of these little temperature sensor breakout boards, you can do that.
- 47:49Like, you can get the design files.
- 47:50You can see how all of the layout was routed and you can tweak it if you want or you could even just go and build it yourself.
- 47:56You know, you're going to need like a big robot pick in place in a lot of cases to assemble the board.
- 48:01That's, you know, maybe one of the advantages of getting it from Aterfruits is that we've done that for you.
- 48:05Yeah, we don't want to constrain people.
- 48:07We want to put it out there so that people can build on it and learn from it.
- 48:10And, you know, the whole everyone kind of grows when everyone can kind of see how things work.
- 48:14Yeah, that's great.
- 48:15It seems to me like 3D printing would be a good complement to these kinds of things.
- 48:20Yeah, definitely.
- 48:21Well, especially for a lot of the projects that you see kind of in the maker world of, yeah, like I have, you know, maybe I'm building like a costume and cosplay.
- 48:28And so I have some like cool, maybe like a sword that I want to light up or something.
- 48:32And, yeah, being able to make some custom enclosure for it is really cool.
- 48:37But, yeah, I love, too, just seeing with 3D printing, just people using it in different ways.
- 48:41Like, again, like going back to the art aspect and building cool sculptures or things.
- 48:46It's just fascinating stuff.
- 48:47I think there's a lot more that we'll see with 3D printing.
- 48:48But, yeah, 3D printing dovetails very nicely with microcontrollers and, you know, because you're building things.
- 48:54And usually you want those things to move or to sense the world or light up or something like that.
- 48:58So, yeah.
- 48:59Yeah.
- 48:59Yeah, at least to be in some kind of enclosure so it looks shiny and not just a bunch of wires, right?
- 49:04Right.
- 49:04Not the box of wires, yeah.
- 49:06It might kind of scare airport security or something like that.
- 49:08Exactly.
- 49:09He has a bomb.
- 49:10It's always difficult for me.
- 49:13So I travel sometimes to Maker Faire.
- 49:15And, oh, I always worry every time I go through.
- 49:17I'm like, I just know they're going to look in my bag.
- 49:19And I've got like this, you know, box of wires and just having to explain to someone what an Arduino is.
- 49:24It hasn't happened yet, but I know at some point I'm going to have to do that.
- 49:27It's coming.
- 49:27Yeah, yeah, yeah.
- 49:30So one thing I saw you guys have is the Adafruit Web IDE.
- 49:33What's that?
- 49:34Yeah.
- 49:35So that was something in the Raspberry Pi world.
- 49:37Basically, it's a program you can run on your Raspberry Pi.
- 49:40And it gives you a little web interface to type in code and run it like Python code.
- 49:45I think you can even access the file system.
- 49:47It came about actually in the early days of the Raspberry Pi.
- 49:50So the Raspberry Pi, I think it's about four years old now.
- 49:52In those early days, you know, they initially were just had spent all their time getting this $35 computer out there and making it work and turning Linux into something that a beginner could, you know, reasonably get started with and use.
- 50:06So there wasn't telling a sixth grader to fire up Emacs is probably not the way.
- 50:10Exactly.
- 50:11Yes.
- 50:11And so early days in the Raspberry Pi world, it was still a little bit.
- 50:14I mean, it was good.
- 50:15Like they had a graphical interface, but it was maybe a little more difficult sometimes to just get going and start programming things.
- 50:20So, yeah, we kind of created that as a way to do some of these early Raspberry Pi tutorials to show people like, OK, here's how you connect your board and here's how you start running code.
- 50:28But nowadays, the Raspberry Pi Foundation, you know, they had a lot of time and they've grown quite a bit.
- 50:32So they've done a lot more polish as far as like how you go from zero to starting running code.
- 50:38I mean, they have their new pixel operating system, which is a really nice reskin of the Linux environment.
- 50:43They've got some nice editors.
- 50:45I think they're like graphical block based editors and things now.
- 50:48So, you know, these days, maybe WebID hasn't been updated as much to, you know, or maybe you might be able to get more things from kind of what Raspberry Pi is doing.
- 50:56But it was originally I just created as a way to get code running quickly on the Raspberry Pi for people.
- 51:02Sure.
- 51:03Very cool.
- 51:03So one of the places that I really one of the things that Adafruit I really like is your learn.adafruit.com.
- 51:10There's just all these projects and some of them are kind of like you talked about at the beginning, like here's how you understand batteries or displays or whatever.
- 51:16But a lot of them are, hey, I made a really cool like thing for Halloween and here's how I made it.
- 51:21Right.
- 51:22These projects that you you could make or take and customize.
- 51:25Right.
- 51:25Yeah, exactly right.
- 51:26And there's a ton of things.
- 51:28I think I just checked.
- 51:28There are 1200 tutorials on the Adafruit learning system.
- 51:31So there is an immense amount of things there.
- 51:33And yeah, you're right.
- 51:34Like it falls in a lot of different categories.
- 51:36So like every product usually has a guide that goes with it that just shows you, okay, here's what you do when you get it.
- 51:41Here's how you might have to solder some things to it.
- 51:43Or here's how you download the software to get started with it.
- 51:46But then, yeah, like you said, there are lots of projects that just serve as like sometimes as inspiration.
- 51:51Like, hey, this is cool.
- 51:52Like, you know, the GPS dog collar, you know, maybe I want to make a cat dog collar or something like that.
- 51:57So I can, you know, take some of the same code and ideas from that.
- 52:00So, yeah, inspiration is a good thing for it.
- 52:03You know, and yeah, just kind of showing off cool things you can do with the projects.
- 52:08There are also some guides that, yeah, teach the basics, interesting things.
- 52:12You know, there's one guide that kind of tells you how to do sensor readings and analog readings.
- 52:18It seems like a boring topic of like, okay, how do you read an analog to digital converter?
- 52:23And then how do you smooth out the data to make it maybe not jump around as much and stuff like that?
- 52:29And so, you know, there's a guide to learn stuff like that, which sounds boring,
- 52:32but it's actually like a really kind of critical thing that you need to learn when you deal with these analog things.
- 52:36So, yeah.
- 52:36So, yeah.
- 52:37So we span kind of quite a broad range.
- 52:39You know, there's, I don't think I know of any case where, you know, we've looked at something and said, no, that's not a guide or something.
- 52:44You know, there's almost anything we can turn into a guide because it's, you know, it's either teaching someone how to do something or it's showing how a product works or just giving inspiration.
- 52:53Like some of the guides and projects are really advanced.
- 52:56Like, you know, there's some of these light painting projects where like the Raspberry Pi light painter, you know, you take a wand of these RGB pixels.
- 53:04And when you wave it around, you can do the persistence of vision effects where, you know, if you light up the pixels in a certain time and then you have a camera that has like a long exposure, it can kind of average out the movement.
- 53:15And so you can see really cool things floating in the air.
- 53:18Like, you know, it looks like an image floating in the air.
- 53:21But some of those projects can be a little more advanced to build, you know, might require like more kind of difficult soldering and stuff like that.
- 53:27Sure.
- 53:27So, you know, everyone might not want to build those, but just seeing that like, wow, that's really cool.
- 53:31I had no idea that I could make something that looks like that, you know, maybe inspire you to do something a little bit simpler or, you know, more capable.
- 53:38Yeah, that sounds awesome.
- 53:39I've picked a few that I like.
- 53:40I'll read them off just so people kind of get a sense for what's up there.
- 53:42So one that you guys had was an onion pie, P-I, not P-Y, which was like a took a raspberry pie and made it a Tor proxy, which is kind of cool.
- 53:51A GPS dog collar for your dog's fitness.
- 53:54LED bicycle things, wrap it on your bike and it can light up in certain ways.
- 54:00A DeLorean time circuit, a raspberry pie streaming radio for like Pandora type stuff.
- 54:05There's a couple of Halloween things like costumes and whatnot.
- 54:08And I think my favorite was a solar charging handbag, which is pretty cool.
- 54:12Oh yeah, that's a great one.
- 54:13Yeah, I love, I love those projects where it's the kind of thing where, you know, you could see that being a commercial product, like something that people would probably pay hundreds of dollars for.
- 54:21And just, you know, with a few dollars of components, you can build it yourself and customize it, make it the way you want.
- 54:27Like if you want a cool design or whatever, if you want to put it into some really neat, funky bag that you have, you can do that.
- 54:32So yeah, it's great stuff.
- 54:34Yeah, that one was cool.
- 54:34That's one of the things like I could see myself using that GPS dog collar.
- 54:38Interesting, but probably not.
- 54:39Yeah, yeah.
- 54:40Right, right.
- 54:40So what are the common, a couple of common.
- 54:42things you see created with Adafruit hardware?
- 54:45I think there are a couple standout projects that are, you know, very Adafruit, I don't know, has Adafruit DNA in them for sure.
- 54:52The Pie Girl, which is basically a Raspberry Pi that you put into a 3D printed enclosure that looks like a Game Boy, like a portable game plane unit.
- 55:02And you add a little display to it.
- 55:04We have a display called the Pi TFT.
- 55:06It's a real low cost display that you just snap onto the Raspberry Pi.
- 55:10And it's cool because it gives you what looks like a Game Boy.
- 55:13So you've got, you know, your direction pad and a couple buttons.
- 55:15But because it's a Raspberry Pi, you can run any games and emulators and things that the Raspberry Pi has.
- 55:20So you can play like old Nintendo games or Super Nintendo games and stuff like that on there.
- 55:24And so that one's, yeah, that one's super popular.
- 55:27Can I play Pitfall on it?
- 55:28Oh, yeah, you can definitely play Pitfall.
- 55:30You can play, you know, the 2600 version.
- 55:32You can play the Super Nintendo, whatever versions of it.
- 55:35So, yeah, lots of options there.
- 55:36Another one is the Cupcade, which is a mini arcade cabinet with the Raspberry Pi.
- 55:42And this one's fun.
- 55:43Like both of these actually, I've seen kind of commercial projects now.
- 55:46Like I think I was just in a Target now recently.
- 55:49I saw this tiny little arcade cabinet that reminded me of this Cupcade project, which now is, I think, like three or four years old.
- 55:55But it's a little miniature, like, you know, an arcade cabinet.
- 55:58Like you might imagine a Pac-Man cabinet with a little joystick and a couple little buttons.
- 56:02But, again, it's got that little Raspberry Pi behind it in the display.
- 56:06And so you can run a full emulator.
- 56:07You can run all kinds of arcade games.
- 56:08So, you know, those are definitely really popular projects.
- 56:11Like things that use Raspberry Pi are really popular because the Raspberry Pi community is really large.
- 56:15But, yeah, we're really well known.
- 56:17We did a lot of things with wearables.
- 56:19So we have some different boards that are great for like sewing onto clothing and controlling things like lights and sensors and stuff like that.
- 56:26So we have fun projects like that.
- 56:28Nice.
- 56:29Yeah, I saw you had made, I saw some picture where you had one of those arc reactor type things from Iron Man.
- 56:34Yeah, exactly right.
- 56:35So I was at the Emerald City Comic Con here in Seattle.
- 56:38And, yeah, that was fun.
- 56:39Basically, I took a board that we have called Circuit Playground that has a ring of little lights on it.
- 56:44And then it's the easiest thing.
- 56:46I just put a magnet on the back, a name tag magnet, and just clipped it to my shirt.
- 56:50And it's this little circle of lights.
- 56:51But then I could control, I could program it.
- 56:53Because in the Iron Man universe, I think the arc reactor is a little boring.
- 56:57You know, Tony Stark, it's just, it only glows blue.
- 56:59And maybe that's because of the, you know, the way it works.
- 57:01But in my world, with my, with Tony D's arc reactor, I'm going to make it glow different colors.
- 57:07So I had mine going through, like, rainbow colors and pulsing in different effects and things like that.
- 57:10And that's cool because I could just write the code that controls it myself.
- 57:13You know, I built it myself.
- 57:14So I have total control over it.
- 57:16Those are all cool projects.
- 57:17So one more project question.
- 57:20Do you know of any, like, commercial projects or Kickstarter type things?
- 57:24Have people, like, used MicroPython or Adafruit to prototype something and then make it into a project?
- 57:29Even if it's...
- 57:30Good question, yeah.
- 57:30So I do see Kickstarters all the time.
- 57:32I can't think of any off the top of my head.
- 57:33But I've definitely seen, you know, if you look at a Kickstarter, in a lot of cases,
- 57:36they'll be showing the prototype that they built.
- 57:39And look for, like, a little blue board with a white star or a white flower on it.
- 57:44And that's, in a lot of cases, if they're using a sensor or something,
- 57:46they've probably got an Adafruit board on there.
- 57:47Because it's great for, you know, if you're doing a Kickstarter,
- 57:50you're trying to very quickly build this prototype.
- 57:52And so you don't have time yet to lay out that circuit board and figure out how it works.
- 57:56You know, just grab the sensor off the shelf and make it work.
- 57:59But then the cool thing is, because we publish all of our designs with open source,
- 58:03when you're ready to turn it into that product,
- 58:05you just grab our design files and you can see,
- 58:06oh, here's how they built their sensor board.
- 58:08And so now I can integrate it in my component.
- 58:09So yeah, I did.
- 58:11So one thing, though, that was a really popular Adafruit project was the Firewalker sneaker,
- 58:15which is basically you put a ring of LEDs,
- 58:18RGB controllable LEDs around the bottom of your shoes.
- 58:21And then you put some little sensors in the shoes to detect when you take a step
- 58:24and you can light up and animate the sneakers.
- 58:26That was a project, I think it's about four years old or so,
- 58:29and was really novel and cool.
- 58:31And nowadays, like you can walk into pretty much any shopping mall and there's like a stand in the middle of the shopping mall
- 58:36where they're selling commercial versions of these Firewalker sneakers.
- 58:39I have seen people walking around with these.
- 58:41Yeah.
- 58:42And a lot of them, if you look at them, they're not as advanced.
- 58:44Most of them don't have the sensors that detect when you take a step.
- 58:48They'll just like have a fixed animation.
- 58:50So that's, you know, not as interesting.
- 58:52Like when you build it yourself, you can make it more fun and interesting.
- 58:54And I haven't seen anything yet with MicroPython,
- 58:57but I'm pretty sure we'll start to see that in the near future because that would be fun.
- 59:01You know, make the MicroPython Firewalker sneakers where, you know,
- 59:05you can have like Python code controlling it or maybe use a board that talks to your phone.
- 59:09And, you know, maybe your sneakers can glow when you get like a notification or something.
- 59:13Your sneakers could tweet every time you take a step, which might be a little excessive.
- 59:17But yeah, so that's maybe the future of things that we'll see with products.
- 59:21That sounds pretty cool.
- 59:22Very nice.
- 59:23Okay.
- 59:23So I think we're pretty much out of time, Tony, but thank you for sharing all those stories.
- 59:28Hopefully people are inspired to go out and try to create cool things they've always wanted to see exist.
- 59:34Oh, yeah, totally.
- 59:35Exactly.
- 59:35You know, that's what we love to do in Adafruit is show people how things work and then show,
- 59:39see what you've done with it.
- 59:41You know, come back and show us what you built with it.
- 59:43Really?
- 59:43Show that it's not like so difficult.
- 59:45Like, hey, these are all the steps it takes.
- 59:47You can do this.
- 59:47Yeah, the greatest thing.
- 59:48So we do every Wednesday at, I think it's 4.30 Pacific, 7.30 Eastern time.
- 59:54We have a show and tell on our YouTube channel and it's a live show.
- 59:58People can come on and we have a hangout and you can show off the projects you built.
- 1:00:02And the best thing, and Lamora said, you know, the greatest moments for her are when
- 1:00:06you have like a seven-year-old girl come on to show off, you know, what she built or what
- 1:00:11she made.
- 1:00:12And it happens quite often.
- 1:00:14You know, we inspire someone.
- 1:00:16And then I think pretty soon we'll start to see that those seven-year-olds who came on the
- 1:00:20show, you know, five, six, seven years from now are going to be coming back and saying,
- 1:00:23hey, now I'm in college and look what, you know, you inspire me to do.
- 1:00:26So looking forward to that.
- 1:00:27Yeah, that's awesome.
- 1:00:29You know, it just came to mind, like you go to these school science fairs and they have
- 1:00:33these projects and a lot of them are like, well, I put a tadpole in a tank and we watched
- 1:00:37it and measured it.
- 1:00:38So, you know, it seems like if you took some of these things, you could do a really cool
- 1:00:42science project.
- 1:00:42Oh yeah, yep, exactly.
- 1:00:44This is maybe science projects on easy mode.
- 1:00:46You know, you just find cool projects we've done and then, you know, modify them yourself
- 1:00:50and build on top of them.
- 1:00:51Yep, exactly.
- 1:00:52Exactly.
- 1:00:52All right.
- 1:00:53Well, two final questions before I let you out of here.
- 1:00:55All right.
- 1:00:55So if you're going to write some Python code, what editor do you open up?
- 1:00:58Oh, I use the Atom text editor these days.
- 1:01:00So I like it a lot.
- 1:01:02You know, it's simple, runs on all the different operating systems.
- 1:01:04I like the color scheme it has by default too.
- 1:01:07Yeah, I like Atom as well.
- 1:01:08Nice one.
- 1:01:08And most notable or PyPI package you want to recommend?
- 1:01:12I really like the click package.
- 1:01:15It's used to build command line interfaces.
- 1:01:17So it's, I think it was created by the person who created the Flask web framework.
- 1:01:21And it's really nice.
- 1:01:22It has that same kind of concept of, you know, building command line apps, but breaking it down
- 1:01:27into kind of simpler functions that you implement for it.
- 1:01:29So it makes it really easy to build an app that does something or a command line tool that does
- 1:01:33something.
- 1:01:33Yeah.
- 1:01:34Excellent.
- 1:01:34Excellent.
- 1:01:34All right.
- 1:01:35Final call to action for people to get started with all this stuff.
- 1:01:38What should they do?
- 1:01:38Yes.
- 1:01:39If you're new to Python and hardware, you know, like I said, the Raspberry Pi is a great platform.
- 1:01:45If you're just used to desktop Python and you just want something that feels like a desktop
- 1:01:49computer.
- 1:01:50But then also explore MicroPython and some of the boards I mentioned, things like the ESP8266.
- 1:01:56That's probably the best entry level MicroPython board right now, just because it's a good balance
- 1:02:00of cost and performance and really easy to get started.
- 1:02:03But keep your eyes peeled for more boards coming in the future.
- 1:02:05Circuit Playground board I mentioned.
- 1:02:07We've got some boards that are coming soon that are going to run MicroPython and CircuitPython
- 1:02:11and some of these versions of Python that run on microcontrollers.
- 1:02:13So that'll be another good kind of getting started option for people.
- 1:02:16So yeah, definitely check out those boards.
- 1:02:17And yeah, don't be afraid to get started.
- 1:02:20You know, one thing that holds people back is just thinking, I'm going to break something.
- 1:02:23I'm going to spend a bunch of money.
- 1:02:24And, you know, it's going to just destroy this piece of hardware.
- 1:02:27They're more resilient than you think.
- 1:02:29And like I said, if you follow a guide, if you look at a project that someone's already done,
- 1:02:33you're going to run into less problems usually and have a little bit more fun
- 1:02:36and get kind of quicker feedback on things.
- 1:02:38Yeah, absolutely.
- 1:02:39Check out learn.adafruit.com.
- 1:02:41There's a ton of inspiration there for you.
- 1:02:43All right.
- 1:02:44Tony, thanks for being on the show.
- 1:02:45Oh, yeah.
- 1:02:46Thank you so much.
- 1:02:46This is great.
- 1:02:47Yeah.
- 1:02:47Talk to you later.
- 1:02:48Yeah.
- 1:02:48See ya.
- 1:02:48This has been another episode of Talk Python To Me.
- 1:02:53Today's guest has been Tony DeCola.
- 1:02:55And this episode has been sponsored by Advanced Digital and the Strange Loop Conference.
- 1:03:00Advanced Digital would love to work with you to build and extend one of the most visited websites
- 1:03:06in the US in Python.
- 1:03:08Reach out to them at python.advance.net to see if there's a fit.
- 1:03:12The Strange Loop Conference would love to have you present on languages, web development, AI,
- 1:03:17and much more.
- 1:03:18Visit talkpython.fm/strange loop to submit your proposal.
- 1:03:22Don't wait.
- 1:03:24The call for proposals closes on May 8th.
- 1:03:27Are you or your colleagues trying to learn Python?
- 1:03:29Well, be sure to visit training.talkpython.fm.
- 1:03:32We now have year-long course bundles and a couple of new classes released just this week.
- 1:03:38Have a look around.
- 1:03:39I'm sure you'll find a class you'll enjoy.
- 1:03:41Be sure to subscribe to the show.
- 1:03:43Open your favorite podcatcher and search for Python.
- 1:03:45We should be right at the top.
- 1:03:46You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct
- 1:03:53RSS feed at /rss on talkpython.fm.
- 1:03:56Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 1:04:01Corey just recently started selling his tracks on iTunes, so I recommend you check it out
- 1:04:05at talkpython.fm/music.
- 1:04:07You can browse his tracks he has for sale on iTunes and listen to the full-length version
- 1:04:12of the theme song.
- 1:04:13This is your host, Michael Kennedy.
- 1:04:15Thanks so much for listening.
- 1:04:16I really appreciate it.
- 1:04:17Smix, let's get out of here.
- 1:04:21Bye.
- 1:04:22Bye.
- 1:04:23Bye.
- 1:04:23Bye.
- 1:04:24Bye.
- 1:04:25Bye.
- 1:04:25Bye.
- 1:04:25Bye.
- 1:04:25Bye.
- 1:04:26Bye.
- 1:04:27Bye.
- 1:04:27Bye.
- 1:04:27Bye.
- 1:04:27Bye.
- 1:04:27Bye.
- 1:04:27Bye.
- 1:04:28Bye.
- 1:04:29developers developers developers developers developers developers developers developers
- 1:04:39Developers, developers, developers, developers.
- 1:04:42you
- 1:04:42you