Skip to content

Commit 01a7f59

Browse files
Merge pull request #35 from brainelectronics/feature/improve-docs
Update README for mpremote and package usage
2 parents 8e84bbb + bcaf260 commit 01a7f59

5 files changed

Lines changed: 122 additions & 22 deletions

File tree

.snippets/34.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Update README for mpremote and package usage
2+
<!--
3+
type: feature
4+
scope: all
5+
affected: all
6+
-->
7+
8+
This change updates the manual package installation instructions to use `mpremote` over `rshell`.
9+
10+
In the PyPI section the usage of `twine check` before `twine upload` is recommended.
11+
12+
An example instruction on how to install a specific version with `upip` was added.
13+
14+
The package usage example and the corresponding `main.py` example files are extended to set the LED pin based on the board extracted from `os.uname()`.
15+
16+
This closes [#34](https://github.com/brainelectronics/micropython-package-template/issues/34)

README.md

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
77
[![codecov](https://codecov.io/github/brainelectronics/micropython-package-template/branch/main/graph/badge.svg)](https://app.codecov.io/github/brainelectronics/micropython-package-template)
88
[![CI](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml/badge.svg)](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml)
9+
![Humans](https://img.shields.io/badge/Created_by-Humans-blue?style=flat
10+
)
911

10-
MicroPython PyPi package template project with auto deploy
12+
MicroPython (PyPI) package template project with auto deploy
1113

1214
---------------
1315

1416
## General
1517

16-
MicroPython PyPi package template with GitHub Action based testing and deploy
18+
MicroPython (PyPI) package template with GitHub Action based testing and deploy
1719

1820
📚 The latest documentation is available at
1921
[MicroPython Package Template ReadTheDocs][ref-rtd-micropython-package-template] 📚
@@ -23,17 +25,19 @@ MicroPython PyPi package template with GitHub Action based testing and deploy
2325
- [Installation](#installation)
2426
- [Install required tools](#install-required-tools)
2527
- [Setup](#setup)
26-
- [Install package](#install-package)
28+
- [Install package from the web](#install-package-from-the-web)
2729
- [General](#general)
2830
- [Specific version](#specific-version)
2931
- [Test version](#test-version)
3032
- [Manually](#manually)
3133
- [Upload files to board](#upload-files-to-board)
34+
- [mpremote](#mpremote)
35+
- [rshell](#rshell)
3236
- [Usage](#usage)
33-
- [Create a PyPi \(micropython\) package](#create-a-pypi-micropython-package)
37+
- [Create a PyPI \(micropython\) package](#create-a-pypi-micropython-package)
3438
- [Setup](#setup-1)
3539
- [Create a distribution](#create-a-distribution)
36-
- [Upload to PyPi](#upload-to-pypi)
40+
- [Upload to PyPI](#upload-to-pypi)
3741
- [Contributing](#contributing)
3842
- [Unittests](#unittests)
3943
- [Steps after using this template](#steps-after-using-this-template)
@@ -60,14 +64,21 @@ returned, use that command to proceed.
6064
python3 -m venv .venv
6165
source .venv/bin/activate
6266

67+
# to interact with a MicroPython board
6368
pip install -r requirements.txt
69+
70+
# to run all tests or contribute to this repo
71+
pip install -r requirements-test.txt
72+
73+
# to create and deploy a new version of this package
74+
pip install -r requirements-deploy.txt
6475
```
6576

6677
## Setup
6778

68-
### Install package
79+
### Install package from the web
6980

70-
Connect the MicroPython device to a network (if possible)
81+
Connect the MicroPython device to a network, otherwise check the section [Manually](#manually) down below.
7182

7283
```python
7384
import network
@@ -86,13 +97,24 @@ import mip
8697
mip.install("github:brainelectronics/micropython-package-template")
8798
```
8899

89-
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`
100+
For MicroPython versions below `1.19.1` use the `upip` package instead of `mip`
90101

91102
```python
92103
import upip
93104
upip.install('micropython-package-template')
94105
```
95106

107+
Run this code on the MicroPython device to check the used MicroPython version
108+
109+
```python
110+
try:
111+
from os import uname
112+
except ImportError:
113+
# u-packages might be deprecated in future
114+
from uos import uname
115+
os.uname().version
116+
```
117+
96118
#### Specific version
97119

98120
Install a specific, fixed package version of this lib on the MicroPython device
@@ -105,7 +127,7 @@ mip.install("github:brainelectronics/micropython-package-template", version="fea
105127
mip.install("github:brainelectronics/micropython-package-template", version="0.6.0")
106128
```
107129

108-
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.
130+
For MicroPython versions below `1.19.1` use the `upip` package instead of `mip`.
109131
With `upip` always the latest available version will be installed.
110132

111133
```python
@@ -125,28 +147,46 @@ import mip
125147
mip.install("github:brainelectronics/micropython-package-template", version="0.6.0-rc9.dev13")
126148
```
127149

128-
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.
129-
With `upip` always the latest available version will be installed.
150+
For MicroPython versions below `1.19.1` use the `upip` package instead of `mip`.
151+
If no specific version is set, `upip` will always install the latest available version.
130152

131153
```python
132154
import upip
133155
# overwrite index_urls to only take artifacts from test.pypi.org
134156
upip.index_urls = ['https://test.pypi.org/pypi']
135157
upip.install('micropython-package-template')
158+
159+
# install a specific version
160+
upip.install("micropython-package-template==0.12.0rc37.dev29")
136161
```
137162

138-
See also [brainelectronics Test PyPi Server in Docker][ref-brainelectronics-test-pypiserver]
163+
See also [brainelectronics Test PyPI Server in Docker][ref-brainelectronics-test-pypiserver]
139164
for a test PyPi server running on Docker.
140165

141166
### Manually
142167

168+
See [Install required tools](#install-required-tools) section on how to install the tools used onwards.
169+
143170
#### Upload files to board
144171

145172
Copy the module to the MicroPython board and import them as shown below
146-
using [Remote MicroPython shell][ref-remote-upy-shell]
173+
using [mpremote][ref-mpremote] or [Remote MicroPython shell][ref-remote-upy-shell].
174+
175+
##### mpremote
176+
177+
`mpremote` will auto-detect the MicroPython device. Check the [mpremote][ref-mpremote] documentation for further details.
178+
179+
```bash
180+
mpremote fs mkdir :/lib
181+
mpremote fs cp -r be_upy_blink/ :/lib/
182+
mpremote fs cp examples/boot.py examples/main.py :
183+
mpremote fs ls :
184+
```
185+
186+
##### rshell
147187

148188
Open the remote shell with the following command. Additionally use `-b 115200`
149-
in case no CP210x is used but a CH34x.
189+
in case no `CP210x` USB to UART bridge is used but a `CH34x`.
150190

151191
```bash
152192
rshell --port /dev/tty.SLAB_USBtoUART --editor nano
@@ -167,17 +207,35 @@ cp examples/boot.py /pyboard
167207

168208
## Usage
169209

210+
This is just a very lightweight MicroPython package template with a minimal functional library.
211+
170212
```python
171213
from be_upy_blink import flash_led
172214
from machine import Pin
173-
174-
led_pin = Pin(4, Pin.OUT)
215+
try:
216+
from os import uname
217+
except ImportError:
218+
from uos import uname
219+
220+
os_info = uname()
221+
222+
if 'pyboard' in os_info:
223+
led_pin = Pin(1, Pin.OUT)
224+
elif 'esp8266' in os_info:
225+
led_pin = Pin(2, Pin.OUT)
226+
elif 'esp32' in os_info:
227+
led_pin = Pin(2, Pin.OUT)
228+
elif 'rp2' in os_info:
229+
# RP2 has the LED on pin 25, Pico W on a custom pin routed to "LED"
230+
led_pin = Pin("LED", Pin.OUT)
231+
else:
232+
raise Exception("Unknown board, manually set pin here")
175233

176234
flash_led(pin=led_pin, amount=3)
177235
# flash_led(pin=led_pin, amount=3, on_time=1, off_time=3)
178236
```
179237

180-
## Create a PyPi (micropython) package
238+
## Create a PyPI (micropython) package
181239

182240
### Setup
183241

@@ -207,7 +265,11 @@ python setup.py sdist
207265
A new folder `dist` will be created. The [`sdist_upip`](sdist_upip.py) will be
208266
used to create everything necessary.
209267

210-
### Upload to PyPi
268+
The `dist/*.orig` file is the non stripped version of the created package.
269+
It contains further files which are necessary for a Python package but not
270+
required by MicroPython board and would use unnecessary flash on the device.
271+
272+
### Upload to PyPI
211273

212274
**Be aware: [pypi.org][ref-pypi] and [test.pypi.org][ref-test-pypi] are different**
213275

@@ -219,6 +281,7 @@ For testing purposes add `--repository testpypi` to
219281
upload it to [test.pypi.org][ref-test-pypi]
220282

221283
```bash
284+
twine check dist/*.tar.gz
222285
twine upload dist/micropython-package-template-*.tar.gz -u PYPI_USERNAME -p PYPI_PASSWORD
223286
```
224287

@@ -263,6 +326,7 @@ should be done and changes to these file being made
263326
| `.github/workflows/test-release.yml` | Path to `version.py` file | Use package version file to set changelog based version |
264327
| `.github/workflows/test.yml` | Path to `version.py` file | Use package version file to set changelog based version |
265328
| `.pre-commit-config.yaml` | Path to `version.py` file | Use package version file for validation against latest changelog based version |
329+
| `LICENSE.txt` | Year and/or type of license | |
266330
| `README.md` | Links in header section and installation instructions | |
267331
| `changelog.md` | Cleanup changelog from informations of template | Keep usage of SemVer |
268332
| `docs/DOCUMENTATION.md` | Kink to ReadTheDocs | |
@@ -278,6 +342,7 @@ Based on the [PyPa sample project][ref-pypa-sample].
278342

279343
<!-- Links -->
280344
[ref-rtd-micropython-package-template]: https://micropython-package-template.readthedocs.io/en/latest/
345+
[ref-mpremote]: https://docs.micropython.org/en/v1.28.0/reference/mpremote.html
281346
[ref-remote-upy-shell]: https://github.com/dhylands/rshell
282347
[ref-brainelectronics-test-pypiserver]: https://github.com/brainelectronics/test-pypiserver
283348
[ref-pypa-sample]: https://github.com/pypa/sampleproject

be_upy_blink/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
22
# -*- coding: UTF-8 -*-
33

4-
__version_info__ = ("0", "13", "1")
4+
__version_info__ = ("0", "14", "0")
55
__version__ = '.'.join(__version_info__)

examples/main.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@
88

99
from be_upy_blink import flash_led
1010
from machine import Pin
11+
try:
12+
from os import uname
13+
except ImportError:
14+
# u-packages might be deprecated in future
15+
from uos import uname
1116
from time import sleep
1217

1318

1419
def loop():
15-
# set pin D4 as output (blue LED) and turn it off
16-
led_pin = Pin(4, Pin.OUT)
20+
os_info = uname()
21+
22+
# set pin as output
23+
if 'pyboard' in os_info:
24+
led_pin = Pin(1, Pin.OUT)
25+
elif 'esp8266' in os_info:
26+
led_pin = Pin(2, Pin.OUT)
27+
elif 'esp32' in os_info:
28+
led_pin = Pin(2, Pin.OUT)
29+
elif 'rp2' in os_info:
30+
# RP2 has the LED on pin 25, Pico W on a custom pin routed to "LED"
31+
led_pin = Pin("LED", Pin.OUT)
32+
else:
33+
raise Exception("Unknown board, manually extend main.py")
34+
35+
# turn it off
1736
led_pin.value(0)
1837

1938
# loop forever

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
]
1515
],
1616
"deps": [],
17-
"version": "0.13.1"
17+
"version": "0.14.0"
1818
}

0 commit comments

Comments
 (0)