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!
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.
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.
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.
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.
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.
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.
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.
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.