If you're doing MicroPython embedded development, are you tormented by these issues every day? The code you wrote throws an error as soon as you run it, and after searching for ages you finda missing dependency file ; what's even more frustrating is that one library comes with several supporting files, and missing any one of them renders everything useless. Here, we first need to introduce the concept ofdependency library. In MicroPython development, the official definition of a dependency library is very clear:
Your main function code / main library cannot run properly on its own, and must call the. py code files provided by other independent parties functions, classes, hardware interfaces, and algorithm logic — these external code files being called are what we refer to as dependency libraries.
Here is a real embedded system case: driving the MAX30102 sensor with a microcontroller to implement heart rate and blood oxygen detection
Main function file: heart_rate.py (Responsible for: heart rate calculation, data display, abnormal alarm)
Dependency Library File 1: max30102.py (Responsible for: underlying hardware read/write of the sensor, register configuration)
Heart rate main program → must call sensor driver + filtering algorithm to run; without these two dependency libraries, your heart rate code will throw an error directly and cannot run at all.
Let’s extend with another real-world development scenario: using the Wiznet EVB-PICO development board to implement via the Wiznet network module TCP Client communication — the most commonly used network function that adapts to the core features of the development board —:
Main function file:\tcp_client. py\(responsible for: TCP connection establishment, data transmission/reception, connection status monitoring)
Dependency Library File 2:\socket\_utils.py\(Responsible for: socket communication utility functions, data formatting, exception handling)
\TCP Client main program\ → must call \Wiznet network driver\ + \socket utility library\ to run. Without these two dependency libraries, your network communication code will throw errors directly, the Wiznet module cannot be initialized, and it will not run at all.
Let’s extend to another real-world development scenario:
A certain \Wiznet network pass-through library\ you installed may depend on \wiznet5k.py\(the underlying driver);
\wiznet5k.py\ driver, which in turn depends on \spi_utils. py\(the low-level utility for SPI communication). This is multi-level nested dependency, the most common dependency scenario in Wiznet EVB-PICO development, and it fully aligns with the actual situation you encounter when developing network features in daily work.
Question
Beginner's Soul-Searching Question: Why can't I just copy and paste all the code and cram it into a single. py file?
This is a pitfall that 99% of beginners fall into. Based on practical work in embedded development, I will tell you the 4 core reasons why you must never do this:
Dependent libraries will undergo version upgrades, making updates completely impossible after the merge.
max30102.py Driver: The author will fix bugs, optimize reading accuracy, and upgrade hardware adaptation
filter_lib.py Algorithm: The author will optimize the filtering effect to reduce errors
If you merge all the code into a single file: every time a dependency library is upgraded, you have to rewrite the entire large file, which makes it extremely easy to modify or delete code incorrectly; by contrast, separating the code into an independent dependency library only requires upgrading a single file, with no changes needed to the main code at all.
Dependency libraries are general-purpose tools that can be reused in countless projects
max30102 Driver: not only supports heart rate monitoring, but also enables blood oxygen measurement and gesture detection
Filter Algorithm Library: It can be applied not only to heart rate monitoring, but also to temperature & humidity sensors and barometric pressure sensors.
After merging into one file, the code is completely "locked" in the heart rate project and cannot be reused. Independent dependency library, directly called by all projects, written once, used countless times.
Nested dependencies can send code completely out of control
A heart rate feature may rely on 2 libraries, and each of those 2 libraries in turn depends on 2 underlying libraries; the final dependency chain becomes: the main code → 4 dependent libraries. If all of them are merged into a single file, the code will reach thousands or even tens of thousands of lines, and when an error occurs, you will have no way to locate the root cause.
development and maintenance cost explosion
Embedded development is mostly a collaborative effort involving multiple people: Engineer A writes the sensor driver, Engineer B develops the algorithm, and Engineer C codes the main functionality. When the code is kept separate (in a dependency library model), everyone works without interfering with one another; if it is merged into a single file where all developers modify the same file directly, conflicts will inevitably arise and the code will end up being scrapped.
This is exactly why we must leverage Wiznet Ethernet modules to implement: Python pip-like online automatic installation + automatic dependency loading: with a single line of code, it automatically installs the main library + all dependent libraries + nested dependencies, and handles version upgrades automatically!
Core Solution: uPyPi + mip
The uPyPi we developed serves as the **PyPI (the official Python package repository)** for the MicroPython ecosystem. When paired with the officially built-in mip (mip installs packages) tool for MicroPython, it enables the following:
✅ Package Hosting: Upload driver packages and toolkits to uPyPi with one click, making them accessible to developers worldwide
✅ One-click installation: Connect the development board to the internet, and install the main package + all dependencies with a single line of code
✅ Automatic dependency management: mip automatically performs recursion to install the declared dependency packages without manual operation
✅ Full-chip compatibility: Designed as a pure software package, it supports all MicroPython development boards with no hardware coupling
✅ Version Management: Semantic versioning to completely eliminate version conflicts
Hands-on from Scratch: 3 Steps to Implement Dynamic Dependency Installation via Wiznet Ethernet
Step 1: Create the third-party dependency package math_utils
This is a pure software toolkit that contains no hardware code and serves as a dependency of the main package.
The folder structure is as follows:
code/math_utils.py The code is as follows:
The complete configuration of package.json is as follows:
{
"name": "math_utils",
"version": "1.0.1",
"description": "Pure third-party software dependency package (no hardware, for testing)",
"author": "test",
"license": "MIT",
"chips": "all",
"fw": "all",
"_comments": {
"chips": "Chip models supported by this package; all means no chip restriction",
"fw": "Specific firmware this package depends on, such as ulab, lvgl; all means no firmware dependency"
},
"urls": [
[
"math_utils.py",
"code/math_utils.py"
]
]
}
Package the folder and upload it to the uPyPi platform to obtain the package address:
Step 2: Create the main test suite test_core
The main package depends on the math_utils above; users only need to install the main package, and mip will automatically install the dependencies. Folder structure:
The code of code/test_core.py is as follows:
The complete configuration of package.json is as follows:
"name": "test_core",
"version": "1.0.4",
"description": "Pure software test main package (no hardware, depends on third-party packages)",
"author": "test",
"license": "MIT",
"chips": "all",
"fw": "all",
"_comments": {
"chips": "Chip models supported by this package; all means no chip restriction",
"fw": "Specific firmware this package depends on, such as ulab, lvgl; all means no firmware dependency"
},
"urls": [
[
"test_core.py",
"code/test_core.py"
]
],
"deps": [
["https://upypi.net/pkgs/math_utils/1.0.1", "latest"]
]
}
Here, we declare the uPyPi address of the main package dependency math_utils in the deps field. When the mip installs the main package, it automatically recurses to install the dependency package , and the user does not need to care at all; "support multiple dependencies, nested dependencies, mip automatically handles all dependency chains.
Package the folder, upload it to the uPyPi platform, and obtain the main package address:
Step 3: One-click Installation and Test for Wiznet EVB-PICO
The complete code is as follows:
# ==================== Wiznet EVB-PICO Ethernet pure software test (no hardware coupling) ====================
# Python env : MicroPython v1.23.0 on Wiznet W5500
# -*- coding: utf-8 -*-
# @Time : 2024/8/7 9:12 PM
# @Author : Li Qingshui
# @File : main.py
# @Description : Wiznet Ethernet + uPyPi automatic dependency installation, pure test code
import time
import network
import mip
from machine import Pin, SPI
# ==================== Configuration ====================
# Ethernet static IP configuration (Wiznet EVB-PICO)
ETH_IP = '192.168.1.20'
ETH_SUBNET = '255.255.255.0'
ETH_GATEWAY = '192.168.1.1'
ETH_DNS = '8.8.8.8'
# uPyPi main test package address (replace with the upypi address)
MAIN_PACKAGE = "https://upypi.net/pkgs/test_core/1.0.4"
# ==================== Ethernet connection (only modify this part!) ====================
def connect():
try:
print("Initializing Wiznet Ethernet...")
# W5500 SPI initialization (EVB-PICO standard pins)
spi = SPI(0, 2000000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
nic = network.WIZNET5K(spi, Pin(17), Pin(20))
nic.active(True)
# Configure static IP
nic.ifconfig((ETH_IP, ETH_SUBNET, ETH_GATEWAY, ETH_DNS))
# Wait for the Ethernet connection
timeout = 10
while not nic.isconnected() and timeout > 0:
timeout -= 1
time.sleep(1)
if nic.isconnected():
print("Ethernet connected successfully! IP:", nic.ifconfig()[0])
return True
else:
print("Ethernet connection failed!")
return False
except Exception as e:
print("Ethernet initialization failed:", e)
return False
# ==================== Remote installation (automatically install third-party software dependencies) [completely unchanged] ====================
def install():
print("Starting installation: main package + third-party pure-software dependencies...")
mip.install(MAIN_PACKAGE)
print("✅ Installation complete! No hardware dependencies")
# ==================== Pure software test (no hardware) [completely unchanged] ====================
def test():
# Import the installed pure software package
from test_core import TestCore
test = TestCore()
# Run the test
print("\n===== Pure-software test results =====")
print(test.test_add(10, 20))
print(test.test_multiply(10, 20))
print("=========================\n")
print("🎉 Test passed! Dependencies installed correctly")
# ==================== Main program [completely unchanged] ====================
if __name__ == "__main__":
if connect():
install()
test()
The running results are as follows:
We can also use the local installation method:
As can be seen: Wiznet has successfully implemented Python-like mip tool to realize the online dynamic installation capability similar to Python pip. After the device connects to WiFi, it automatically pulls and deploys the main test suite test_core.py and its third-party dependency packages math_utils.py to the /lib directory. Subsequent pure software tests verified that the main package can normally call the dependent libraries, and the results of addition and multiplication operations are completely correct. The solution fully implements online library installation, automatic dependency management and function verification on the embedded device side, thoroughly addresses the development pain points of traditional manual file copying and missing dependency installation, and realizes a standardized package management experience consistent with Python development on the PC side.