Labs / MicroPython tutorials / 13 ETH Ethernet - Document Tutorial Draft

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Installation - Using uPyPI Package Management Platform

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

Contents

Introduction

As a MicroPython embedded developer, are you tortured by these problems every day?
Write a good code to run an error, turn over half a day found that less than installed a dependency file ; more collapse is that a library with several subsidiary files, missing a whole scrap.
Here, we need to introduce the concept of dependency libraries . In MicroPython development, the official definition of dependency libraries is very clear:

Your main function code / main library cannot run independently and normally, and must call .py code files provided by other independent functions, classes, hardware interfaces, and algorithmic logic . These external code files being called are dependency libraries .

Let's take a real embedded case: using a microcontroller to drive the MAX30102 sensor to performheart rate and blood oxygen detection

Heart Rate Main Program → Must call Sensor Driver + Filtering Algorithm to run. Without these two dependent libraries, your heart rate code will directly report an error and won't run at all.

Extend to another real-world development scenario: using the Wiznet EVB-PICO development board, implement via the Wiznet network moduleTCP Client communication (the most commonly used network function, adapted to the core features of the development board):

TCP Client Main Program → Must call Wiznet Network Driver + socket Tool Library to run. Without these two dependent libraries, your network communication code will directly report an error, the Wiznet module cannot be initialized, and it will not run at all.

Extend it to another real development scenario:

Doubt

Xiaobai's soul-searching question:Why can't I copy and paste all the code and combine it into a single.py file?

This is a pitfall that 99% of beginners will fall into. I will combine the actual work of embedded development to tell you the 4 core reasons why you must never do this:

  1. Dependencies version upgrade , after merging, it is completely unable to update
  1. Dependencies are general-purpose tools that can be reused in countless projects
  1. Nested dependencies can cause code to completely spin out of control

A heart rate function may depend on 2 libraries; these 2 libraries, in turn, each depend on 2 underlying libraries; ultimately, the dependency relationship will become: main code → 4 dependent libraries. If all are merged into a single file, the code will reach thousands or tens of thousands of lines , and it will be impossible to find the problem when an error occurs.

  1. Development and maintenanceCost explosion

Embedded development mostly involves multi-person collaboration: Engineer A writes sensor drivers, Engineer B writes algorithms, and Engineer C writes main functions. When the code is separated (in the dependent library mode), everyone works without interfering with each other; when merged into a single file, everyone modifies the same file, leading to direct conflicts and code becoming obsolete.

That's why we must implement it with the Wiznet Ethernet module: Online automatic installation + automatic dependency loading similar to Python pip : One line of code, automatically install the main library + all dependent libraries + nested dependencies, and automatically handle version upgrades!

Core solution: uPyPi + mip

92

The uPyPi we developed is the **PyPI (Python official package repository)** for the MicroPython ecosystem, working in conjunction with the mip (mip installs packages) tool built into the MicroPython official distribution to achieve:

Hands-on from Scratch: 3 Steps to Dynamically Install Dependencies via Wiznet Ethernet

For information 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 Installation - Using uPyPI Package Management Platform

Step 1: Create the third-party dependency package math_utils

This is a pure software toolkit, without any hardware code, and serves as a dependency for the main package.

The folder structure is as follows:

1

code/math_utils.py The code is as follows:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Installation - Using uPyPI Package Management Platform

The complete configuration of package.json is:

{
  "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:

1.6.1 2026 04 1

Step 2: Create the main test suitetest_core

The main package depends on the above math_utils , users only need to install the main package, mip automatically installs dependencies.
Folder structure:

1KB 2

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

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Installation - Using uPyPI Package Management Platform

The complete configuration of package.json is:

"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, mip automatically recursively installs the dependent packages when installing the main package , and users don't need to worry about it at all; Supports multiple dependencies, nested dependencies, and mip automatically handles all dependency chains.

Package the folder, upload it to the uPyPi platform, and obtain the main package address:

1.0.4 2

Step 3: One-click Installation + Testing 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 running results are as follows:

30 200

We can also use the local installation method:

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Installation - Using uPyPI Package Management Platform

It can be seen that: Wiznet successfully achieved the online dynamic installation capability similar to Python's pip through MicroPython's mip tool. After the device connected to WiFi, it automatically fetched and deployed the main test_core.py test suite and its third-party dependency package math_utils.py to the /lib directory.
Subsequent pure software testing verified that the main package can normally call the dependent libraries, the results of addition and multiplication operations are completely correct, and the online library installation, automatic dependency management, and function verification on the embedded device side have been fully implemented, thoroughly resolving the development pain points of traditional manual file copying and missing dependency installations, and achieving a standardized package management experience consistent with Python development on the PC side.

Wiznet Ethernet Module Enables Online Dynamic Library Installation and Automatic Dependency Installation - Using uPyPI Package Management Platform

Version History

Version Number

Revision Time

Modifier

Modify content

v1.0

2026-04-04

Lee Eryong

Initial version.