Tag Archives: Threads

AI on the Edge LESSON 12: Introduction to Python Threading on the Raspberry Pi

Hey everyone, and welcome back to the AI on the Edge series!

In today’s lesson, we’re tackling one of the most important programming concepts you’ll need as we build more advanced AI and robotics projects — Python Threading.

Up until now, our programs have been pretty linear — they do one thing at a time. But as our projects get smarter and more interactive, we often need several things happening at the same time. That’s exactly where threading comes in. In this lesson, I give you a gentle, practical introduction to threading by creating a program that blinks an LED while simultaneously listening for your commands to change the blink speed — all without one task blocking the other.

You’ll see how to create a separate thread that handles user input while the main program continues blinking the LED smoothly. We also use a Queue to safely pass data between the threads. This is a foundational skill that becomes incredibly valuable later in the class when we need to run voice recognition, camera processing, sensor reading, and motor control all at the same time.

I designed this lesson to be very beginner-friendly. If you’ve never used threading before, don’t worry — I walk you through every line of code and explain why we do things the way we do. By the end of this video, you’ll have a solid understanding of how to launch background threads, manage shared variables safely, and keep your main program responsive.

This lesson is a big stepping stone in our AI on the Edge journey. The ability to run multiple tasks concurrently is what separates simple scripts from real-world intelligent systems that can listen, think, and act at the same time.

So grab your SunFounder Fusion AI Hat, hook up an LED, and get ready to take your Raspberry Pi programming skills to the next level. Once you understand threading, a whole new world of possibilities opens up!

As always, I strongly encourage you to code along with me in the video and then experiment on your own. Try adding more LEDs, change the commands, or combine it with things we’ve learned in previous lessons. That hands-on practice is where the real learning happens.

I’m really excited for you to learn this one — it’s going to make the rest of the class a lot more fun and powerful!

In today’s lesson, this is the code we developed.

 

MicroPython MultiCore Programming on the Raspberry Pi Pico Using Threading

In this video I show how to use both cores on the Raspberry Pi Pico W. We will explore an example using threading where we will operate 2 LED and a servo.