Installation
Install the library on MicroPython boards
Install package via network
This section describes the installation of the library on network capable boards.
Note
Not all MicroPython board have a network support, like the classic Raspberry Pi Pico or the pyboard. Please check the port specific documentation.
This is an example on how to connect to a wireless network.
import network
station = network.WLAN(network.STA_IF)
station.connect('SSID', 'PASSWORD')
# wait some time to establish the connection
station.isconnected()
Install with mip
mip
has been added in MicroPython 1.19.1 and later. For earlier MicroPython
versions check the upip section below
mip (“mip installs packages”) is similar in concept to Python’s pip tool, however it does not use the PyPI index, rather it uses micropython-lib as its index by default.
As this library is pushed to PyPi and TestPyPi, but not the default micropython-lib index the additional index has to be specified explicitly.
import mip
mip.install('micropython-modbus', index='https://pypi.org/pypi')
In order to install the latest release candidate version, set the index to
'https://test.pypi.org/pypi'
import mip
mip.install('micropython-modbus', index='https://test.pypi.org/pypi')
Install with upip
import upip
upip.install('micropython-modbus')
In order to install the latest release candidate version, use the following commands
import upip
# overwrite index_urls to only take artifacts from test.pypi.org
upip.index_urls = ['https://test.pypi.org/pypi']
upip.install('micropython-modbus')
Install package without network
mpremote
As of January 2022 the mpremote
tool is available via pip
and can be used to install packages on a connected device from a host machine.
As described in the Install required tools
section of SETUP, the
tool will be installed with the provided requirements.txt
file. Please
follow the mpremote documentation to connect to a
MicroPython device.
To install the latest officially released library version use the following command
mpremote connect /dev/tty.SLAB_USBtoUART mip install --index https://pypi.org/pypi micropython-modbus
In order to install the latest release candidate version, use the following command
mpremote connect /dev/tty.SLAB_USBtoUART mip install --index https://test.pypi.org/pypi micropython-modbus
Manually
Copy all files of the umodbus module to the MicroPython board using Remote MicroPython shell or mpremote
mpremote
Perform the following command to copy all files and folders to the device
mpremote connect /dev/tty.SLAB_USBtoUART cp -r umodbus/ :
rshell
Open the remote shell with the following command. Additionally use -b 115200
in case no CP210x is used but a CH34x.
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
Perform the following command to copy all files and folders to the device
mkdir /pyboard/lib
mkdir /pyboard/lib/umodbus
cp umodbus/* /pyboard/lib/umodbus
Additional MicroPython packages for examples
To use this package with the provided boot.py
and
main.py
file to create a TCP-RTU bridge, additional
modules are required, which are not part of this repo/package.
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
Install the additional package micropython-modbus
as described in the
previous section on the MicroPython device or download the
brainelectronics MicroPython Helpers repo
and copy it to the device.
Perform the following command to copy all files and folders to the device
mkdir /pyboard/lib/be_helpers
cp be_helpers/* /pyboard/lib/be_helpers
Additionally check the latest instructions of the brainelectronics MicroPython modules README for further instructions.