Install the library on MicroPython boards
This section describes the installation of the library on network capable boards.
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()
mip
has been added in MicroPython 1.19.1 and later. For earlier MicroPython
versions check the upip section below
.. epigraph::
`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 not pushed to the default
micropython-lib index, the installation has
to be done via the package definition file (package.json
) provided with this
repo.
import mip
mip.install('github:brainelectronics/micropython-modbus')
In order to install the latest release candidate version, select a version from the repo tags overview
import mip
mip.install('github:brainelectronics/micropython-modbus', version='2.3.3-rc31.dev59')
This library is pushed to PyPi and TestPyPi. The installation from those package indices is currently not supported with MicroPython v1.19.1 or newer. The package can be installed on older MicroPython versions with the following commands.
`upip` is not able to install a specific version of a package. It will always
use the latest available version.
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')
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 github:brainelectronics/micropython-modbus
In order to install the latest release candidate version, use the following command
mpremote connect /dev/tty.SLAB_USBtoUART mip install github:brainelectronics/micropython-modbus
Copy all files of the umodbus module to the MicroPython board using Remote MicroPython shell or mpremote
Perform the following command to copy all files and folders to the device
mpremote connect /dev/tty.SLAB_USBtoUART cp -r umodbus/ :
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
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.