Labs / MicroPython tutorials / 13 ETH Ethernet

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

Author: Li Zisheng · Source: FreakStudio open documentation, v1.0 · License: CC BY 4.0

Contents

Introduction

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

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 —:

\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:

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:

  1. Dependent libraries will undergo version upgrades, making updates completely impossible after the merge.
  1. Dependency libraries are general-purpose tools that can be reused in countless projects
  1. 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.

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

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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:

Hands-on from Scratch: 3 Steps to Implement Dynamic Dependency Installation via Wiznet Ethernet

For instructions on how to download and upload driver packages, please refer to the wiki: https://freakstudio.cn/node/019c992e-2994-7180-b570-12199db1a7cb

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

code/math_utils.py The code is as follows:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

The code of code/test_core.py is as follows:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

We can also use the local installation method:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

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.

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Setup – Using the uPyPI Package Management Platform Copy

Revision History

Version Number

Revision Date

Modifier

Modify Content

v1.0

2026-04-04

Lee Eryong

Initialization version.