Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Playing With Circuits and Robots

Libraries linked in this lesson:

Real Python Embedded Electronic Resources:

00:00 In the previous lesson, I finished up section two covering web scraping. This lesson is on section three, embedded systems and robotics.

00:10 Python is pretty much everywhere. In fact, did you know there’s Python on some of the robots on Mars? There are all sorts of electronics out there that you can program using your favorite language.

00:21 That means you can do Internet of Things, home automation, hobby projects, robotics, and much more.

00:28 This is a Circuit Playground device. I bought a couple of these to help teach my nephews coding. When I grew up, just getting the computer to type my name over and over was exciting, but with the generation that grew up with phones and 120 hertz refresh rate video games, writing Ryan to the screen a hundred times just doesn’t seem that thrilling, but turning lights on and off on a circuit board somehow captures that same joy I had when I started out.

00:53 There are tons of devices like this and there’s lots of stuff jammed onto this board. You can use Python to control LED lights. There’s a USB port, and in fact, this is how you get code on the board.

01:04 You attach it to your computer and it shows up as a folder. This is a microphone. There’s a speaker, a temperature gauge, and this detects light. One of my nephews’ first projects was to make this play Mary Had a Little Lamb, while the other wrote a program so that the LED went red if it was warm and blue if it was cold.

01:23 There’s a whole community doing maker things with these kinds of devices with a lot of creative projects you can take on. The device I just showed you runs CircuitPython, a Python-compatible language for coding microcontrollers.

01:37 A similar device is the BBC micro:bit, which is a small computer that you can run Python upon. MicroPython is yet another way to get Python working on microcontrollers.

01:48 It has some, but not all, of the standard library, keeping it small enough to fit on almost any device.

01:56 You may have heard of Raspberry Pi, a general-purpose mini computer that runs Linux. Python is included in the distro. This isn’t so much a microcontroller kind of thing, but if you need a small computer somewhere, this is great and you don’t have to learn another language.

02:13 When playing with robotics, there are common algorithms you need like pathfinding, that PythonRobotics Library has these kinds of things included. And finally, if you’re working with ROS, that’s the Robot Operating System.

02:26 rospy is a Python library to interface with that.

02:31 There are even tutorials on Real Python to get you started in the microcontroller space. This one is on MicroPython and this one is on BBC micro:bit. If you want to play with your Raspberry Pi, you can check this tutorial out.

02:47 Next up, I’ll start section four, which is all about development tools and workflows.

Become a Member to join the conversation.