Use what you learned about MicroPython and PyBoard in part one to build this LED flasher project.

In our last post, we introduced you to MicroPython and pyboard. Now it's time to put that knowledge to use by building this LED flasher project!

df7a4c8ecea77d154fa846806cac25a5.jpeg

MicroPython LED Flasher

In testing new development tools and software, it’s quite easy to build an LED flasher for this validation purpose. The hands-on lab concept is to flash two LEDs in sequence while pressing a pushbutton switch. Upon releasing the pushbutton switch, the two LEDs will turn off. I created a block diagram to capture the device’s basic functional design requirements.

e844af7b5719083d397ff240b6e71925.jpeg

Figure 5. A MicroPython LED flasher block diagram.

The MicroPython LED Flasher block diagram is easily converted into an electrical wiring diagram. The STM32F411RE can source 25mA (milliamperes) of current from each GPIO pin. Therefore, a transistor is not required to drive the LEDs.

88f868dbb102649b8116160043503d59.jpeg

Figure 6. A MicroPython LED flasher electrical wiring diagram.

Although the electrical wiring diagram shows discrete components, I built the LED flasher device using a Radio Shack Electronics Learning Lab kit. The kit expedited the build of the flasher device because of the pushbutton switch and LEDs provided by the trainer.

a7548d783fea7d2bb3913b3d3181678d.jpeg

Figure 7. A Radio Shack Electronics Learning Lab expedited the build of the MicroPython LED flasher device.

Here’s the circuit schematic diagram I created and used to wire the LED flasher device on the Radio Shack Electronics Learning Lab kit.

0766c79f2a28f1a300dbe0a855fac45a.jpeg

Figure 8. The MicroPython LED flasher device circuit schematic diagram. View the full-size schematic.

Creating the Code

Developing the MicroPython code for the LED flasher was quite easy based on prior knowledge of the Python language.

4b351ee2000638049eba611d00e017a8.jpeg

Source Code Listing: A MicroPython LED flasher code.

This code and pyboard circuit provides a hardware version of the infamous Hello World program used in introductory computer science courses taught in colleges and universities. Not only does the MicroPython code flash the onboard and external LEDs in sequence, but Hello World is displayed on a software communication terminal window as well.

6cbc3b2ee3d5c7fcaac0a281afae4397.jpeg

Figure 9. Binary data and Hello World displayed on communication terminal window. 

Pressing the first pushbutton switch on the trainer starts the sequencing of the flasher device LEDs.

88381639e01c84ac35d7dda720d6155b.jpeg

Figure 10. The MicroPython code sequence flashing of all LEDs flasher. 

I was quite pleased with the operation of the pyboard and the ease of use of the MicroPython programming language. This tiny embedded development platform opens a world of project possibilities in areas of environmental sensing, home automation, robotics, and wearable devices. I plan to investigate some of these project idea themes with my electrical systems technology students at the college. Additional information on code examples, programming documentation, and the pyboard component specification can be found at MicroPython’s website.

Related Articles

Don Wilcher
Don is an educator, author, and EE who's worked on a wide array of robotics and controls systems in his career.

Maker Pro Logo
Continue to site
Quote of the day

-