@@ -18,13 +18,13 @@ Forked from [Exo Sense Py][ref-sferalabs-exo-sense], based on
18
18
[ PyCom Modbus] [ ref-pycom-modbus ] and extended with other functionalities to
19
19
become a powerfull MicroPython library
20
20
21
- The latest documentation is available at
22
- [ MicroPython Modbus ReadTheDocs] [ ref-rtd-micropython-modbus ]
21
+ 📚 The latest documentation is available at
22
+ [ MicroPython Modbus ReadTheDocs] [ ref-rtd-micropython-modbus ] 📚
23
23
24
24
<!-- MarkdownTOC -->
25
25
26
26
- [ Quickstart] ( #quickstart )
27
- - [ Install package on board with pip ] ( #install-package-on-board-with-pip )
27
+ - [ Install package on board with mip or upip ] ( #install-package-on-board-with-mip-or-upip )
28
28
- [ Request coil status] ( #request-coil-status )
29
29
- [ TCP] ( #tcp )
30
30
- [ RTU] ( #rtu )
@@ -41,17 +41,19 @@ This is a quickstart to install the `micropython-modbus` library on a
41
41
MicroPython board.
42
42
43
43
A more detailed guide of the development environment can be found in
44
- [ SETUP] ( SETUP.md ) . Further details about the usage can be found in
45
- [ USAGE] ( USAGE.md )
44
+ [ SETUP] ( SETUP.md ) , further details about the usage can be found in
45
+ [ USAGE] ( USAGE.md ) , descriptions for testing can be found in
46
+ [ TESTING] ( TESTING.md ) and several examples in [ EXAMPLES] ( EXAMPLES.md )
46
47
47
48
``` bash
48
49
python3 -m venv .venv
49
50
source .venv/bin/activate
50
51
51
52
pip install ' rshell>=0.0.30,<1.0.0'
53
+ pip install ' mpremote>=0.4.0,<1'
52
54
```
53
55
54
- ### Install package on board with pip
56
+ ### Install package on board with mip or upip
55
57
56
58
``` bash
57
59
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
@@ -60,6 +62,23 @@ rshell -p /dev/tty.SLAB_USBtoUART --editor nano
60
62
Inside the [ rshell] [ ref-remote-upy-shell ] open a REPL and execute these
61
63
commands inside the REPL
62
64
65
+ ``` python
66
+ import machine
67
+ import network
68
+ import time
69
+ import mip
70
+ station = network.WLAN(network.STA_IF )
71
+ station.active(True )
72
+ station.connect(' SSID' , ' PASSWORD' )
73
+ time.sleep(1 )
74
+ print (' Device connected to network: {} ' .format(station.isconnected()))
75
+ mip.install(' micropython-modbus' , index = ' https://pypi.org/pypi' )
76
+ print (' Installation completed' )
77
+ machine.soft_reset()
78
+ ```
79
+
80
+ For MicroPython versions below 1.19.1 use the ` upip ` package instead of ` mip `
81
+
63
82
``` python
64
83
import machine
65
84
import network
@@ -81,8 +100,7 @@ After a successful installation of the package and reboot of the system as
81
100
described in the [ installation section] ( #install-package-on-board-with-pip )
82
101
the following commands can be used to request a coil state of a target/client
83
102
device. Further usage examples can be found in the
84
- [ examples folder] [ ref-examples-folder ] and in the
85
- [ Micropython section of USAGE] ( USAGE.md )
103
+ [ examples folder] [ ref-examples-folder ] and in the [ USAGE chapter] ( USAGE.md )
86
104
87
105
#### TCP
88
106
@@ -110,15 +128,16 @@ print('Status of coil {}: {}'.format(coil_status, coil_address))
110
128
#### RTU
111
129
112
130
``` python
113
- from umodbus.serial import ModbusRTU
131
+ from umodbus.serial import Serial as ModbusRTUMaster
114
132
115
- host = ModbusRTU (
116
- addr = 1 , # address of this Master/Host on bus
133
+ host = ModbusRTUMaster (
134
+ pins = ( 25 , 26 ), # given as tuple (TX, RX), check MicroPython port specific syntax
117
135
# baudrate=9600, # optional, default 9600
118
136
# data_bits=8, # optional, default 8
119
137
# stop_bits=1, # optional, default 1
120
138
# parity=None, # optional, default None
121
- pins = (25 , 26 ) # (TX, RX)
139
+ # ctrl_pin=12, # optional, control DE/RE
140
+ # uart_id=1 # optional, see port specific documentation
122
141
)
123
142
124
143
# address of the target/client/slave device on the bus
@@ -130,7 +149,7 @@ coil_status = host.read_coils(
130
149
slave_addr = slave_addr,
131
150
starting_addr = coil_address,
132
151
coil_qty = coil_qty)
133
- print (' Status of coil {} : {} ' .format(coil_status, coil_address ))
152
+ print (' Status of coil {} : {} ' .format(coil_address, coil_status ))
134
153
```
135
154
136
155
### Install additional MicroPython packages
@@ -141,17 +160,22 @@ which are not part of this repo/package. To install these modules on the
141
160
device, connect to a network and install them via ` upip ` as follows
142
161
143
162
``` python
163
+ # with MicroPython version 1.19.1 or newer
164
+ import mip
165
+ mip.install(' micropython-brainelectronics-helpers' , index = ' https://pypi.org/pypi' )
166
+
167
+ # before MicroPython version 1.19.1
144
168
import upip
145
169
upip.install(' micropython-brainelectronics-helpers' )
146
170
```
147
171
148
172
Check also the README of the
149
- [ brainelectronics MicroPython modules] [ ref-github-be-mircopython-modules ]
150
- and the [ SETUP guide ] ( SETUP.md )
173
+ [ brainelectronics MicroPython modules] [ ref-github-be-mircopython-modules ] , the
174
+ [ INSTALLATION ] ( INSTALLATION.md ) and the [ SETUP] ( SETUP.md ) guides.
151
175
152
176
## Usage
153
177
154
- See [ USAGE] ( USAGE.md )
178
+ See [ USAGE] ( USAGE.md ) and [ DOCUMENTATION ] ( DOCUMENTATION.md )
155
179
156
180
## Supported Modbus functions
157
181
0 commit comments