This sample shows how to use the Notecard to update a Python application.
- Raspberry Pi Pico running Micropython
- [TODO] SWAN runing circuitpython
- Raspberry Pi running Linux OS with CPython v3
- Laptop or PC with standard OS and CPython v3
Notecard Interface Options | {UART, I2C} |
Default Notecard Interface | UART0 (GPIO pins 16 and 17) |
MCU Platform | Micropython |
MCU Python version | Micropython |
MCU Debug Interface | USB |
Example Configuration
// secrets.json
{
"product_uid":"my-secret-product-uid",
"debug": false
}
Notecard Interface Options | {UART, I2C, USB} |
Default Notecard Interface | I2C (Notecarrier PI)* |
MCU Platform | Linux |
MCU Python version | Python3 |
MCU Debug Interface | SSH terminal |
*Default configuration is for use with Notecarrier PI mounted on a Raspberry Pi 4
Example Configuration
// secrets.json
{
"product_uid":"my-secret-product-uid",
"debug": false,
"port_type": "i2c",
"port_id": "/dev/i2c-1"
}
Notecard Interface Options | {USB, UART, I2C} |
Default Notecard Interface | USB* |
MCU Platform | Linux/Windows |
MCU Python version | Python3 |
MCU Debug Interface | system terminal |
Notecard USB appears as serial port on PC. You can select USB or UART and get the same results.
Example Configuration
// secrets.json
{
"product_uid":"my-secret-product-uid",
"debug": false,
"port_type": "usb",
"port_id": "COM4"
}
The main application establishes a periodic loop that will execute the next step in the firmware update process. The steps are small, and should not block execution for very long.
TODO - include example of a blocking version of the firmware update process, not just the version that can be used in a background process
A secrets.json
file is used to store application configuration information
Create this file in the same location as main.py
.
For the Raspberry Pi Pico, you will need to create and copy this file onto the Raspberry Pi Pico
The format of the file is JSON, where the root field names are the configuration parameters, with the values assigned as the associated configuration values
Name | Default Value | Description | Info |
---|---|---|---|
product_uid | (empty) | Notehub project identifier | REQUIRED The application will not function correctly without setting this parameter to a valid product UID |
port_type | uart | Selects communication method with Notecard | Select from {i2c , uart , usb } (USB is also a UART connection) |
port_id | 0 | Port identifier used to connect to Notecard | Defaults is UART0 on Raspberry Pi Pico. Use serial port name in a string (for example) "COM4" using a UART connection on a standard OS. Use the I2C numeric port ID for I2C |
port_baudrate | 9600 | Baud rate in bits-per-second when using UART | Options are {9600,115200}. 115200 is only valid when using auxillary UART |
debug | true | Display Notecard request and response messages | Options: {true,false} |
// secrets.json
{
"product_uid":"my-secret-product-uid",
"port_type": "uart",
"port_id": "COM4",
"port_baudrate": 9600,
"debug": true
}
-
Create a
secrets.json
file in the root folder -
Execute
deploy-micropy.cmd
OR Copy the following to the Raspberry Pi PicoSource Destination secrets.json
./secrets.json
app
./
lib
./lib
src
./
-
Restart the Pico
-
Open a serial terminal to monitor output from Pico over USB connection
-
Restart the Pico to begin execution
- Clone this repository
- Create
secrets.json
file in the root folder - Run
pip install -r requirements.txt
to install all of the prerequisites. - Run
chmod a+x app/main.py
to allowapp/main.py
to reload itself after it loads an updated file. - Run
python3 app/main.py
-
Modify
app/version.py
to a new version number -
Generate a TAR-file that includes
app/version.py
A utility script
generateTarFile.sh
can be used to create new TAR-file from the contents of theapp
folder -
Upload the TAR-file to your Notehub project using the steps outlined here: https://dev.blues.io/notehub/notehub-walkthrough/#manage-host-firmware
-
Deploy the TAR-file to your Notecard by following: https://dev.blues.io/notehub/notehub-walkthrough/#deploy-firmware
-
After the installation completes, Notehub should register a new version that matches the change in step 1
For doing additional development work and executing tests refer to the following sections
To install all of the package prerequisites
pip install -r requirements-ci.txt
Use the runtests.py
script to execute test suite with code coverage.
python runtests.py
The Micropython update scripts use ampy
to copy source files to the microprocessor.
To install ampy
pip install adafruit-ampy
❗ Configure Serial Port: Be sure to set the correct serial port by setting the
AMPY_PORT
environment variable.
Linux/Mac
export AMPY_PORT=/dev/tty.SLAB_USBtoUART
Windows
set AMPY_PORT=COM4
For convenience in copying the SDK package to the microprocessor, this repository contains a copy of the Notecard SDK note-python
To update the version of the Notecard SDK you can copy the contents of the latest note-python
version to ./lib/notecard
- Download the latest release here: https://github.com/blues/note-python/releases
- Extract the ZIP-archive
- Copy the contents of the
notecard
directory to./lib/notecard
- Execute
ampy
to copylib
folder to the microprocessorampy put lib lib
Python source for modules that define OTA update process
dfu |
abstracts the interactions with Notecard to migrate the content from the Notecard to the host processor |
updater |
state machine for managing file update process. See doc\dfuFlow.md for more details |
utarfile |
reading and extracting content from TAR-file |
Unit tests for modules in src
Python files defining example main host MCU application. Application written to work in Python3 and Micropython executing on Raspberry Pi Pico.
config |
class defining application configuration and defaults |
version |
class defining current application version info |
main |
entry point file. Establishes configuration, connects to Notecard, and executes main loop |
Source for Python modules to augment Micropython
haslibextras |
implement MD5 hash function, which is not available in hashlib library in Micropython |
notecard |
Notecard SDK |
abc |
stub implementation for Python abstract classes which are not supported in Micropython |