If you're doing MicroPython embedded development, are you tormented by these problems every day? The code you wrote throws an error as soon as you run it, and after searching for ages you find that a dependency file is missing ; 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 functions, classes, hardware interfaces, and algorithm logic; these external code files being called are the 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, and abnormal alarm)
Dependency Library File 1: max30102.py (Responsible for: low-level 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 to a real 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, which 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 report errors directly, the Wiznet module cannot be initialized, and it will not run at all.
Let me share 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 what we call 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-paste all the code and cram it into a single. py file?
This is a pitfall that 99% of beginners fall into. Combining with the practical work of embedded development, I will tell you 4 core reasons why you must never do this:
Dependent libraries will undergo version upgrades, and will be completely unable to be updated after merging
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.
A dependency library is a general-purpose tool that can be reused in countless projects.
max30102 Driver: It supports not only heart rate monitoring, but also blood oxygen measurement and gesture detection.
Filter Algorithm Library: It can be applied not only to heart rate monitoring, but also to temperature, humidity 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 your code completely spiraling out of control
A heart rate feature may rely on 2 libraries, each of which in turn depends on 2 underlying libraries; the final dependency chain will be: 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, making it impossible to locate the root cause once an error occurs.
development and maintenance cost explosion
Embedded development mostly involves multi-person collaboration: Engineer A writes the sensor driver, Engineer B develops the algorithm, and Engineer C codes the main function. When the code is separated (in a dependency library mode), everyone works without interfering with each other; if the code is merged into a single file where all developers modify the same file directly, conflicts will arise and the code will end up scrapped.
This is exactly why we have to leverage the Wiznet Ethernet module 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 is the **PyPI (official Python package repository)** for the MicroPython ecosystem. Together with the mip (mip installs packages) tool built into official 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 installs the declared dependency packages via recursion 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, completely eliminating version conflicts
Hands-on from Scratch: Implement Dynamic Dependency Installation via Wiznet Ethernet in 3 Steps
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, upload it to the uPyPi platform, and 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 in 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 in the deps field the uPyPi address of the main package dependency math_utils; when mip installs the main package, it will automatically install dependent packages via recursion, requiring no intervention from the user at all. It supports multiple dependencies and nested dependencies, with mip automatically handling all dependency chains.
Package the folder, upload it to the uPyPi platform, and obtain the address of the main package:
Step 3: One-click Installation and Test of 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 operation 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 dependency libraries, and the results of addition and multiplication operations are completely correct. This 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 delivers a standardized package management experience consistent with Python development on the PC side.