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.
6064python3 -m venv .venv
6165source .venv/bin/activate
6266
67+ # to interact with a MicroPython board
6368pip 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
7384import network
@@ -86,13 +97,24 @@ import mip
8697mip.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
92103import upip
93104upip.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
98120Install 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
105127mip.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 ` .
109131With ` upip ` always the latest available version will be installed.
110132
111133``` python
@@ -125,28 +147,46 @@ import mip
125147mip.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
132154import upip
133155# overwrite index_urls to only take artifacts from test.pypi.org
134156upip.index_urls = [' https://test.pypi.org/pypi' ]
135157upip.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 ]
139164for 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
145172Copy 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
148188Open 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
152192rshell --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
171213from be_upy_blink import flash_led
172214from 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
176234flash_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
207265A new folder ` dist ` will be created. The [ ` sdist_upip ` ] ( sdist_upip.py ) will be
208266used 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
219281upload it to [ test.pypi.org] [ ref-test-pypi ]
220282
221283``` bash
284+ twine check dist/* .tar.gz
222285twine 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
0 commit comments