Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JUPYTER_PLATFORM_DIRS=1
JUPYTER_PLATFORM_DIRS=1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "micropython-magic"
version = "0.8.1"
version = "0.8.2a0"
description = "MicroPython Magic commands for use with Jupyter notebooks and Jupyter Labs"
keywords = [
"MicroPython",
Expand Down
421 changes: 219 additions & 202 deletions samples/mem_info.ipynb

Large diffs are not rendered by default.

40 changes: 6 additions & 34 deletions samples/multi_file.ipynb → samples/multi_file_rp2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"no device found\n"
]
}
],
"source": [
"%%micropython\n",
"from machine import Pin, ADC\n",
"\n",
"\n",
"def GetPicoModel():\n",
" # Ensure Pin 25 Low...\n",
" pin_25 = Pin(25, mode=Pin.IN, pull=Pin.PULL_DOWN, value=0)\n",
" raw = ADC(3).read_u16() # Read the raw value (0-65535) from the ADC pin\n",
" voltage = raw * 3.3 / 65535 # Convert the raw value to a voltage\n",
" # 1/3 VSYS, Not Almost Zero? Test As 0.4 Or Greater\n",
" model = \"Pico\" if (voltage > 0.4) else \"Pico-W\"\n",
" return model\n",
"\n",
"\n",
"print(\"Pico Model: {0}\".format(GetPicoModel()))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"no device found\n"
"Traceback (most recent call last):\n",
"\u001b[31m\u001b[1mERROR \u001b[0m | \u001b[36mmicropython_magic.interactive\u001b[0m:\u001b[36mdo_output\u001b[0m:\u001b[36m83\u001b[0m - \u001b[31m\u001b[1mValueError: not a Pin\n",
"\u001b[0m\n",
"ValueError: not a Pin\n"
]
}
],
Expand All @@ -49,7 +21,7 @@
"# --writefile blink.py\n",
"# blink the neopixel led on GPIO48\n",
"from machine import Pin\n",
"from neopixel import NeoPixel\n",
"# from neopixel import NeoPixel\n",
"import time\n",
"led = Pin(\"LED\", Pin.OUT)\n",
"# led.off()\n",
Expand Down Expand Up @@ -270,7 +242,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
},
"orig_nbformat": 4
},
Expand Down
84 changes: 84 additions & 0 deletions samples/pico_model_rp2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This sample works on the rp2 only\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ver': 'v1.22.0',\n",
" 'version': '1.22.0',\n",
" 'port': 'samd',\n",
" 'mpy': 'v6.2',\n",
" 'build': '',\n",
" 'cpu': 'SAMD51P19A',\n",
" 'family': 'micropython',\n",
" 'board': 'Wio Terminal D51R with SAMD51P19A',\n",
" 'arch': 'armv7emsp',\n",
" 'serial_port': 'auto'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%mpy --info"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%micropython\n",
"from machine import Pin, ADC\n",
"\n",
"\n",
"def GetPicoModel():\n",
" # Ensure Pin 25 Low...\n",
" pin_25 = Pin(25, mode=Pin.IN, pull=Pin.PULL_DOWN, value=0)\n",
" raw = ADC(3).read_u16() # Read the raw value (0-65535) from the ADC pin\n",
" voltage = raw * 3.3 / 65535 # Convert the raw value to a voltage\n",
" # 1/3 VSYS, Not Almost Zero? Test As 0.4 Or Greater\n",
" model = \"Pico\" if (voltage > 0.4) else \"Pico-W\"\n",
" return model\n",
"\n",
"\n",
"print(\"Pico Model: {0}\".format(GetPicoModel()))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
82 changes: 35 additions & 47 deletions samples/plot_cpu_temp_rp2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,34 @@
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"bqplot and numpy loaded\n"
]
"data": {
"text/plain": [
"{'ver': 'v1.22.0',\n",
" 'version': '1.22.0',\n",
" 'port': 'samd',\n",
" 'mpy': 'v6.2',\n",
" 'build': '',\n",
" 'cpu': 'SAMD51P19A',\n",
" 'family': 'micropython',\n",
" 'board': 'Wio Terminal D51R with SAMD51P19A',\n",
" 'arch': 'armv7emsp',\n",
" 'serial_port': 'auto'}"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%mpy --info"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# load / install libraries to display the plots\n",
"try:\n",
Expand All @@ -41,7 +62,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -64,7 +85,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"scrolled": true
},
Expand Down Expand Up @@ -92,18 +113,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"temperature: t=34.0666 C\n",
"<class 'float'>\n"
]
}
],
"outputs": [],
"source": [
"t = %mpy --eval cpu_temp()\n",
"print (f\"temperature: {t=} C\")\n",
Expand All @@ -120,18 +132,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"34.0666\n",
"[34.0666]\n"
]
}
],
"outputs": [],
"source": [
"# measure once and append to the list\n",
"t = %mpy --eval cpu_temp()\n",
Expand All @@ -150,24 +153,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4633418cb4a748e99441bd5c0098e989",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Figure(fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, scale_x=LinearScale(allow…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"# create a graph of the measurements using pyplot\n",
"cpu_graph = plt.plot(measurements)\n",
Expand All @@ -190,7 +178,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down
10 changes: 5 additions & 5 deletions samples/stop_cell.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['COM4']\n"
"['COM10']\n"
]
}
],
Expand All @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -81,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -151,7 +151,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.7"
},
"orig_nbformat": 4
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
],
"source": [
"# TODO replace this by a sample script that allocates memory \n",
"!mpremote cp ../../micropython-stubber/src/stubber/board/logging.py :logging.py\n",
"!mpremote cp ../../micropython-stubber/src/stubber/board/createstubs_info.py :createstubs.py\n",
"# !mpremote cp ../../micropython-stubber/src/stubber/board/logging.py :logging.py\n",
"# !mpremote cp ../../micropython-stubber/src/stubber/board/createstubs_info.py :createstubs.py\n",
"# !mpremote cp ../../micropython-stubber/src/stubber/board/createstubs.py :createstubs.py"
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/micropython_magic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""MicroPython magics for Jupyter Notebooks and JupyterLabs"""
__version__ = "0.8.1"
__version__ = "0.8.2a0"
__author__ = "Jos Verlinde"


Expand Down
7 changes: 4 additions & 3 deletions src/micropython_magic/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LogTags:


def ipython_run(
cmd: Union[List[str], str],
cmd: List[str],
stream_out=True,
timeout: Union[int, float] = TIMEOUT,
shell: bool = False,
Expand All @@ -50,7 +50,7 @@ def ipython_run(
]: # sourcery skip: assign-if-exp, boolean-if-exp-identity, reintroduce-else, remove-unnecessary-cast, use-contextlib-suppress
"""Run an external command stream the output back to the Ipython console.
args:
cmd: the command to run, as a list of strings or a single string
cmd: the command to run, as a list of strings
stream_out: stream the output back to the console as it is received (per line)
timeout: the timeout in seconds, defaults to 300 seconds (5 mins)
shell: run the command in a shell
Expand Down Expand Up @@ -95,7 +95,8 @@ def do_output(output) -> bool:
return False
return True

log.trace(f"per char , with timeout of {timeout} seconds")
log.debug(f"{'line' if line_based else 'char'} based, with timeout of {timeout} seconds")
assert isinstance(cmd, list)
try:
process = subprocess.Popen(
cmd,
Expand Down
Loading