Package: micropython-magic
micropython-magicThese Jupyter magic methods allow MicroPython to be used from within any Jupyter Notebook or JupyterLab (formerly IPython Notebook)
The magics make use of thempremote toolto enable communication with the MCUsThis allows:Mixing of Host and MCU Code ( and languages if you wish)Creating graphs of the data captured by MCU sensorscreate re-uasable sequences ( download/compile firmware - flash firmware - uploade code - run expiriment - same outcome)Create and execute tests that require orchestration across multiple MCUs and hostsRapid PrototypingCapturing the results and outputs of your expiriments in a consistent wayMixing documentation with codeA few of the possibilitiesLive Plot of the cpu temperatureVisualize the memory map of the MCUMemory allocation of the MCU over timeFor the source please refer to the samples folderInstallationcreate and activate a venvpython3 -m venv .venvpip install -U "micropython-magic"or install directly into your notbook environment/kernel using the '%pip' magic by running%pip install -U "micropython-magic"Recommended : install stubs for your MCU of choiceInstall stubs for MicroPython syntax checkingpip install micropython-rp2-stubs(or your port of choise)Usage1) Create a notebookinstall your desired notebook environment:VScode and theJuypyter extension,Jupyter NotebookJupyterLabcreate a new notebook2) Load the magic%load_extmicropython_magicThis can also be configured once to always load automatically ( see below)3) add a cell with some code to run on the MCU# %%micropythonfrommachineimportPinled=Pin(25,Pin.OUT)led.value(1)The%%micropythoncell magic will instruct Jupyter to run the code on the connected MCU4) enable code highlighting for MicroPython%pipinstallmicropython-esp32-stubs==1.20.0.*# installs the stubs for MicroPython syntax checking (one time install per environment)# %%micropythonfrommachineimportPinled=Pin(25,Pin.OUT)led.value(1)This allows for syntax highlighting and code completion of MicroPython code.
Tested in VSCode withPythonextensionPylanceextensionMore ExamplesPlease refer to thesamples folderfor more examplesinstall- install the magicboard_control- basic board controlboard_selection.- list connected boards and loop through themdevice_info- Get simple access to port, board and hardware and firmware informationWOKWI- Use MicroPython magic with WOKWI as a simulator (no device needed)Plot rp2 CPU temp- create a plot of the CPU temperature of a rp2040 MCU(bqplot)Display Memory Map- Micropython memory map visualizerPlot Memory Usage- plot the memory usage of a Micropython script running on a MCU over timeAutomatically load the magic on startupIn order to automatically load the magic on startup, you can add the following to youripython_config.pyfile:create a ipython profileipython profile createadd the following to the configuration file (.../.ipython/profile_default/ipython_config.py)c=get_config()c.InteractiveShellApp.extensions=['micropython_magic']Configuration optionsConfiguration can be done via the%configmagic%configMicroPythonMagicMicroPythonMagic(Magics)options------------------------------MicroPythonMagic.loglevel=<UseEnum>Choices:anyof['TRACE','DEBUG','INFO','WARNING','ERROR']Current:<LogLevel.WARNING:'WARNING'>MicroPythonMagic.timeout=<Float>Current:300.0# example%configMicroPythonMagic.loglevel='TRACE'loglevel : set the loglevel for the magic ( default WARNING)timeout : set the timeout for the mpremote connection ( default 300 seconds - 5 minutes)Development and contributionsThe most welcome contributions are :Testing on different platforms (OS) but also different Jupyter environments ( Jupyter Notebook, JupyterLab, VSCode)Provide additional sample notebooksHelp add documentation (preferably in a notebook or .md file)Share this with other people that may be interested in this.See current statusand on Github