Why MicroPython Matters

SparkFun Embedded Software Engineer Malcolm breaks down why MicroPython has been such a game changer.

If you're a programmer curious about embedded systems, or an embedded engineer looking to speed up your prototyping process, MicroPython might just be your new favorite tool. In this video post, we’ll explore what MicroPython is, how it works, and walk through a hands-on example using SparkFun's Qwiic ecosystem. Follow along the video with this blog!

Ready to jump into embedded systems without the C/C++ learning curve?

What is MicroPython?

MicroPython is a lightweight implementation of Python 3 designed to run on microcontrollers without an operating system. While standard Python (CPython) is known for its large library support and ease of use, it's also too bulky for most embedded platforms. MicroPython strips away the unnecessary features while adding support for hardware interfacing, making it perfect for embedded development.

Why Use Python on Microcontrollers?

Python is an interpreted language, meaning it translates and executes code line by line using a runtime environment called the Python Virtual Machine (PVM). Unlike compiled languages like C or Rust, Python doesn't produce a static object file. Instead, the interpreter must be present on the device running the code.

MicroPython includes its own lightweight runtime that brings this functionality to embedded hardware. It allows developers to write readable, easy-to-debug scripts that interact directly with microcontroller peripherals.

Benefits of MicroPython

  • Cross-platform support: One software source file works across different development boards.
  • REPL access: Use a terminal emulator to interact directly with your board, run individual lines of code, and get instant feedback.
  • Rapid prototyping: Skip the compile-load-run cycle. Tweak values, test commands, and tune parameters on the fly.
  • Hardware abstraction: Easily interface with I2C, SPI, UART, and GPIO pins without deep platform-specific knowledge.

Hardware Setup

For the demo in our video, we used:

SparkFun IoT RedBoard - RP2350

WRL-27708
$39.95

SparkFun High Precision Temperature Sensor - TMP117 (Qwiic)

SEN-15805
$16.95

Qwiic Cable - 100mm

PRT-14427
$1.50

SparkFun 4-in-1 Multi-USB Cable - USB-C Host

CAB-21271
$14.95

Special Offer: When you purchase the SparkFun RP2350 IoT RedBoard you get a free Precision Temperature Sensor and Qwiic Cable! Only available while supplies last!

Add all three items to your cart and the TMP117 and Qwiic Cable will be free at time of checkout.

After flashing MicroPython onto the RedBoard, we connected it to a Windows computer and used the Thonny IDE to access the MicroPython REPL (Read-Eval-Print Loop). From here, we could execute Python commands directly on the board.

Live Coding Example

With the REPL open, we:

  • Imported the SparkFun Qwiic TMP117 MicroPython module.
  • Created an instance of the sensor class.
  • Called the begin() method to initialize the sensor.
  • Read live temperature data using read_temp_c().

This real-time interaction with the hardware is powerful for debugging and initial development.

Going Further: Hosting a Web App with MicroPython

We took things a step further by creating a web app served directly from the RedBoard. Using MicroPython's built-in WLAN support and the Micro Web Framework:

  • We set up the board as a Wi-Fi access point.
  • Served a thermometer web app with high/low limits and visual indicators.
  • Connected to the network and viewed live temperature updates in a browser.

This demonstration shows how easy it is to create fully functional IoT applications with minimal code.

Why MicroPython Matters

MicroPython isn't just a convenient tool for beginners, it's a serious productivity booster for seasoned engineers too. With its REPL interface, hardware libraries, and minimal setup overhead, you can spend less time configuring and more time building.

Resources

Viva open source! Stay safe, be kind, and happy prototyping!