Setup
Setup the development environment and the MicroPython board
Development environment
This section describes the necessary steps on the computer to get ready to test and run the examples.
Update submodule
brainelectronics python modules submodule have to be cloned as well. A standard clone command won’t clone the submodule.
git submodule update --init --recursive
cd modules
git fetch
# maybe checkout a newer version with the following command
git checkout x.y.z
# or use the latest develop branch
git checkout develop
git pull
Install required tools
Python3 must be installed on your system. Check the current Python version with the following command
python --version
python3 --version
Depending on which command Python 3.x.y
(with x.y as some numbers) is
returned, use that command to proceed.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -r modules/requirements.txt
MicroPython
This section describes the necessary steps on the MicroPython device to get ready to test and run the examples.
Flash firmware
Flash the MicroPython firmware to the MicroPython board with this call in case a ESP32 is used.
esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART erase_flash
esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART --baud 921600 write_flash -z 0x1000 esp32spiram-20220117-v1.18.bin
Install package with pip
Connect to a network
import network
station = network.WLAN(network.STA_IF)
station.connect('SSID', 'PASSWORD')
station.isconnected()
and install this lib with all its dependencies on the MicroPython device like this
import upip
upip.install('micropython-modbus')
Without network connection
Copy all files of the umodbus module to the MicroPython board using Remote MicroPython shell
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, additional modules are required,
which are not part of this repo/package.
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
Install additional package with pip
Again connect to a network and install the additional package on the MicroPython device with
import upip
upip.install('micropython-modbus')
Without network connection
To install the additional modules on the device, download the brainelectronics MicroPython Helpers repo and copy them 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.