{"id":13802694,"url":"https://github.com/josverl/micropython-magic","last_synced_at":"2025-04-09T19:23:22.358Z","repository":{"id":153026734,"uuid":"627606378","full_name":"Josverl/micropython-magic","owner":"Josverl","description":"MicroPython integrated into Jupyter notebooks","archived":false,"fork":false,"pushed_at":"2025-03-06T13:37:50.000Z","size":14091,"stargazers_count":25,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T04:04:06.803Z","etag":null,"topics":["ipython","ipython-magic","jupyter-magics","jupyter-notebook","micropython","mpremote"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Josverl.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-13T20:19:58.000Z","updated_at":"2025-03-06T13:37:47.000Z","dependencies_parsed_at":"2024-07-09T11:01:07.410Z","dependency_job_id":"5c4ebb89-fa2f-4fea-9ed6-c71827955ab5","html_url":"https://github.com/Josverl/micropython-magic","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Josverl%2Fmicropython-magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Josverl%2Fmicropython-magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Josverl%2Fmicropython-magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Josverl%2Fmicropython-magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Josverl","download_url":"https://codeload.github.com/Josverl/micropython-magic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248095932,"owners_count":21046944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ipython","ipython-magic","jupyter-magics","jupyter-notebook","micropython","mpremote"],"created_at":"2024-08-04T00:01:50.445Z","updated_at":"2025-04-09T19:23:22.337Z","avatar_url":"https://github.com/Josverl.png","language":"Python","readme":"# micropython-magic\n![PyPI](https://img.shields.io/pypi/v/micropython-magic?style=plastic)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/micropython-magic?style=plastic)\n![PyPI - License](https://img.shields.io/pypi/l/micropython-magic?style=plastic)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/micropython-magic?style=plastic)\n\n\u003cimg src=\"docs/logo_S.jpg\" width=\"100\" align=\"right\"\u003e\n\n\n\nThese Jupyter magic methods allow MicroPython to be used from within any Jupyter Notebook or JupyterLab (formerly IPython Notebook)\nThe magics make use of the [mpremote tool](https://github.com/micropython/micropython/blob/master/tools/mpremote/README.md) to enable communication with the MCUs \n\n\nThis allows: \n * Mixing of Host and MCU Code ( and languages if you wish)\n * Creating graphs of the data captured by MCU sensors \n * create re-uasable sequences ( download/compile firmware - flash firmware - uploade code - run expiriment - same outcome) \n * Create and execute tests that require orchestration across multiple MCUs and hosts \n * Rapid Prototyping \n * Capturing the results and outputs of your expiriments in a consistent way\n * Mixing documentation with code  \n\n\n## A few of the possibilities\n\n\u003ctable\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\nLive Plot of the cpu temperature  \n\n\u003cimg src=\"docs/cpu_plot.gif\" width=\"300\" /\u003e\n\u003c/td\u003e\n\u003ctd\u003e\nVisualize the memory map of the MCU\n\n\u003cimg src=\"docs/memory_map.gif\" width=\"300\" /\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\u003ctd\u003e\n\u003c/td\u003e\n\u003ctd\u003e\nMemory allocation of the MCU over time\n\n\u003cimg src=\"docs/memory_map_sequence.gif\" width=\"300\" /\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nFor the source please refer to the samples folder\n## Installation\n- create and activate a venv `python3 -m venv .venv`\n - [ ] `pip install -U \"micropython-magic\"`\n\n- or install directly into your notbook environment/kernel using the '%pip' magic by running\n  - [ ] `%pip install -U \"micropython-magic\"`\n\nRecommended : install stubs for your MCU of choice\n- [ ] Install stubs for MicroPython syntax checking `pip install micropython-rp2-stubs` (or your port of choise)\n\n## Usage\n\n**1) Create a notebook**\n- install your desired notebook environment:\n  - [VScode and the **Juypyter extension**](https://code.visualstudio.com/docs/languages/python#_jupyter-notebooks) ,\n  - [Jupyter Notebook](https://jupyter.org/install#jupyter-notebook) \n  - [JupyterLab ](https://jupyter.org/install)\n\n- create a new notebook \n\n**2) Load the magic**\n```python\n%load_ext micropython_magic\n```\nThis can also be configured once to always load automatically ( see below)\n\n\n**3) add a cell with some code to run on the MCU**\n```python\n# %%micropython  \nfrom machine import Pin\nled = Pin(25, Pin.OUT)\nled.value(1)\n```\nThe `%%micropython` cell magic will instruct Jupyter to run the code on the connected MCU\n\n**4) enable code highlighting for MicroPython**\n```python\n%pip install micropython-esp32-stubs==1.20.0.*\n# installs the stubs for MicroPython syntax checking (one time install per environment) \n```\n\n```python\n# %%micropython  \nfrom machine import Pin\nled = Pin(25, Pin.OUT)\nled.value(1)\n```\nThis allows for syntax highlighting and code completion of MicroPython code.\nTested in VSCode with\n- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) extension\n- [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) extension\n\n## More Examples\n\nPlease refer to the [samples folder](samples/) for more examples\n\n\n1. [install](samples/install.ipynb) - install the magic \n1. [board_control](samples/board_control.ipynb) - basic board control\n1. [board_selection.](samples/board_selection.ipynb) - list connected boards and loop through them\n1. [device_info](samples/device_info.ipynb) - Get simple access to port, board and hardware and firmware information\n1. [WOKWI](samples/wokwi.ipynb) - Use MicroPython magic with WOKWI as a simulator (no device needed)\n1. [Plot rp2 CPU temp](samples/plot_cpu_temp_rp2.ipynb) - create a plot of the CPU temperature of a rp2040 MCU(bqplot)\n1. [Display Memory Map](samples/mem_info.ipynb) - Micropython memory map visualizer\n1. [Plot Memory Usage](samples/mem_info-plot.ipynb) - plot the memory usage of a Micropython script running on a MCU over time\n\n\u003c!-- 1. [](samples/mem_info_list.ipynb) - not currently working used to trace the m --\u003e\n\n\n\n## Automatically load the magic on startup\n\nIn order to automatically load the magic on startup, you can add the following to your `ipython_config.py` file:\n\n- create a ipython profile \n  - `ipython profile create`\n  - add the following to the configuration file (`.../.ipython/profile_default/ipython_config.py`)\n\n    ```python\n    c = get_config()\n\n    c.InteractiveShellApp.extensions = [\n        'micropython_magic'\n    ]\n    ```\n## Configuration options\n\nConfiguration can be done via the `%config` magic\n\n```python\n%config MicroPythonMagic\n\n    MicroPythonMagic(Magics) options\n    ------------------------------\n    MicroPythonMagic.loglevel=\u003cUseEnum\u003e\n        Choices: any of ['TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR']\n        Current: \u003cLogLevel.WARNING: 'WARNING'\u003e\n    MicroPythonMagic.timeout=\u003cFloat\u003e\n        Current: 300.0\n\n# example\n%config MicroPythonMagic.loglevel = 'TRACE'\n```\n- loglevel : set the loglevel for the magic ( default WARNING)\n- timeout : set the timeout for the mpremote connection ( default 300 seconds - 5 minutes)\n\n## Development and contributions\n\nThe most welcome contributions are : \n- Testing on different platforms (OS) but also different Jupyter environments ( Jupyter Notebook, JupyterLab, VSCode)\n- Provide additional sample notebooks \n- Help add documentation (preferably in a notebook or .md file)\n- Share this with other people that may be interested in this.\n\n[See current status](development_status.md) and on Github\n","funding_links":[],"categories":["Development"],"sub_categories":["Shells"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosverl%2Fmicropython-magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosverl%2Fmicropython-magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosverl%2Fmicropython-magic/lists"}