Skip to content

Commit 13452db

Browse files
authored
Merge pull request #22 from Josverl/Josverl/issue21
Add MacOS support
2 parents 1f3c207 + df41399 commit 13452db

17 files changed

+679
-377
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JUPYTER_PLATFORM_DIRS=1
2+
JUPYTER_PLATFORM_DIRS=1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "micropython-magic"
3-
version = "0.8.1"
3+
version = "0.8.2a0"
44
description = "MicroPython Magic commands for use with Jupyter notebooks and Jupyter Labs"
55
keywords = [
66
"MicroPython",

samples/mem_info.ipynb

Lines changed: 219 additions & 202 deletions
Large diffs are not rendered by default.

samples/multi_file.ipynb renamed to samples/multi_file_rp2.ipynb

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,10 @@
99
"name": "stdout",
1010
"output_type": "stream",
1111
"text": [
12-
"no device found\n"
13-
]
14-
}
15-
],
16-
"source": [
17-
"%%micropython\n",
18-
"from machine import Pin, ADC\n",
19-
"\n",
20-
"\n",
21-
"def GetPicoModel():\n",
22-
" # Ensure Pin 25 Low...\n",
23-
" pin_25 = Pin(25, mode=Pin.IN, pull=Pin.PULL_DOWN, value=0)\n",
24-
" raw = ADC(3).read_u16() # Read the raw value (0-65535) from the ADC pin\n",
25-
" voltage = raw * 3.3 / 65535 # Convert the raw value to a voltage\n",
26-
" # 1/3 VSYS, Not Almost Zero? Test As 0.4 Or Greater\n",
27-
" model = \"Pico\" if (voltage > 0.4) else \"Pico-W\"\n",
28-
" return model\n",
29-
"\n",
30-
"\n",
31-
"print(\"Pico Model: {0}\".format(GetPicoModel()))"
32-
]
33-
},
34-
{
35-
"cell_type": "code",
36-
"execution_count": 3,
37-
"metadata": {},
38-
"outputs": [
39-
{
40-
"name": "stdout",
41-
"output_type": "stream",
42-
"text": [
43-
"no device found\n"
12+
"Traceback (most recent call last):\n",
13+
"\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",
14+
"\u001b[0m\n",
15+
"ValueError: not a Pin\n"
4416
]
4517
}
4618
],
@@ -49,7 +21,7 @@
4921
"# --writefile blink.py\n",
5022
"# blink the neopixel led on GPIO48\n",
5123
"from machine import Pin\n",
52-
"from neopixel import NeoPixel\n",
24+
"# from neopixel import NeoPixel\n",
5325
"import time\n",
5426
"led = Pin(\"LED\", Pin.OUT)\n",
5527
"# led.off()\n",
@@ -270,7 +242,7 @@
270242
"name": "python",
271243
"nbconvert_exporter": "python",
272244
"pygments_lexer": "ipython3",
273-
"version": "3.11.6"
245+
"version": "3.11.7"
274246
},
275247
"orig_nbformat": 4
276248
},

samples/pico_model_rp2.ipynb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"This sample works on the rp2 only\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 2,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"data": {
17+
"text/plain": [
18+
"{'ver': 'v1.22.0',\n",
19+
" 'version': '1.22.0',\n",
20+
" 'port': 'samd',\n",
21+
" 'mpy': 'v6.2',\n",
22+
" 'build': '',\n",
23+
" 'cpu': 'SAMD51P19A',\n",
24+
" 'family': 'micropython',\n",
25+
" 'board': 'Wio Terminal D51R with SAMD51P19A',\n",
26+
" 'arch': 'armv7emsp',\n",
27+
" 'serial_port': 'auto'}"
28+
]
29+
},
30+
"execution_count": 2,
31+
"metadata": {},
32+
"output_type": "execute_result"
33+
}
34+
],
35+
"source": [
36+
"%mpy --info"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"%%micropython\n",
46+
"from machine import Pin, ADC\n",
47+
"\n",
48+
"\n",
49+
"def GetPicoModel():\n",
50+
" # Ensure Pin 25 Low...\n",
51+
" pin_25 = Pin(25, mode=Pin.IN, pull=Pin.PULL_DOWN, value=0)\n",
52+
" raw = ADC(3).read_u16() # Read the raw value (0-65535) from the ADC pin\n",
53+
" voltage = raw * 3.3 / 65535 # Convert the raw value to a voltage\n",
54+
" # 1/3 VSYS, Not Almost Zero? Test As 0.4 Or Greater\n",
55+
" model = \"Pico\" if (voltage > 0.4) else \"Pico-W\"\n",
56+
" return model\n",
57+
"\n",
58+
"\n",
59+
"print(\"Pico Model: {0}\".format(GetPicoModel()))"
60+
]
61+
}
62+
],
63+
"metadata": {
64+
"kernelspec": {
65+
"display_name": ".venv",
66+
"language": "python",
67+
"name": "python3"
68+
},
69+
"language_info": {
70+
"codemirror_mode": {
71+
"name": "ipython",
72+
"version": 3
73+
},
74+
"file_extension": ".py",
75+
"mimetype": "text/x-python",
76+
"name": "python",
77+
"nbconvert_exporter": "python",
78+
"pygments_lexer": "ipython3",
79+
"version": "3.11.7"
80+
}
81+
},
82+
"nbformat": 4,
83+
"nbformat_minor": 2
84+
}

samples/plot_cpu_temp_rp2.ipynb

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,34 @@
2222
"metadata": {},
2323
"outputs": [
2424
{
25-
"name": "stdout",
26-
"output_type": "stream",
27-
"text": [
28-
"bqplot and numpy loaded\n"
29-
]
25+
"data": {
26+
"text/plain": [
27+
"{'ver': 'v1.22.0',\n",
28+
" 'version': '1.22.0',\n",
29+
" 'port': 'samd',\n",
30+
" 'mpy': 'v6.2',\n",
31+
" 'build': '',\n",
32+
" 'cpu': 'SAMD51P19A',\n",
33+
" 'family': 'micropython',\n",
34+
" 'board': 'Wio Terminal D51R with SAMD51P19A',\n",
35+
" 'arch': 'armv7emsp',\n",
36+
" 'serial_port': 'auto'}"
37+
]
38+
},
39+
"execution_count": 1,
40+
"metadata": {},
41+
"output_type": "execute_result"
3042
}
3143
],
44+
"source": [
45+
"%mpy --info"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {},
52+
"outputs": [],
3253
"source": [
3354
"# load / install libraries to display the plots\n",
3455
"try:\n",
@@ -41,7 +62,7 @@
4162
},
4263
{
4364
"cell_type": "code",
44-
"execution_count": 2,
65+
"execution_count": null,
4566
"metadata": {},
4667
"outputs": [],
4768
"source": [
@@ -64,7 +85,7 @@
6485
},
6586
{
6687
"cell_type": "code",
67-
"execution_count": 3,
88+
"execution_count": null,
6889
"metadata": {
6990
"scrolled": true
7091
},
@@ -92,18 +113,9 @@
92113
},
93114
{
94115
"cell_type": "code",
95-
"execution_count": 4,
116+
"execution_count": null,
96117
"metadata": {},
97-
"outputs": [
98-
{
99-
"name": "stdout",
100-
"output_type": "stream",
101-
"text": [
102-
"temperature: t=34.0666 C\n",
103-
"<class 'float'>\n"
104-
]
105-
}
106-
],
118+
"outputs": [],
107119
"source": [
108120
"t = %mpy --eval cpu_temp()\n",
109121
"print (f\"temperature: {t=} C\")\n",
@@ -120,18 +132,9 @@
120132
},
121133
{
122134
"cell_type": "code",
123-
"execution_count": 5,
135+
"execution_count": null,
124136
"metadata": {},
125-
"outputs": [
126-
{
127-
"name": "stdout",
128-
"output_type": "stream",
129-
"text": [
130-
"34.0666\n",
131-
"[34.0666]\n"
132-
]
133-
}
134-
],
137+
"outputs": [],
135138
"source": [
136139
"# measure once and append to the list\n",
137140
"t = %mpy --eval cpu_temp()\n",
@@ -150,24 +153,9 @@
150153
},
151154
{
152155
"cell_type": "code",
153-
"execution_count": 6,
156+
"execution_count": null,
154157
"metadata": {},
155-
"outputs": [
156-
{
157-
"data": {
158-
"application/vnd.jupyter.widget-view+json": {
159-
"model_id": "4633418cb4a748e99441bd5c0098e989",
160-
"version_major": 2,
161-
"version_minor": 0
162-
},
163-
"text/plain": [
164-
"VBox(children=(Figure(fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, scale_x=LinearScale(allow…"
165-
]
166-
},
167-
"metadata": {},
168-
"output_type": "display_data"
169-
}
170-
],
158+
"outputs": [],
171159
"source": [
172160
"# create a graph of the measurements using pyplot\n",
173161
"cpu_graph = plt.plot(measurements)\n",
@@ -190,7 +178,7 @@
190178
},
191179
{
192180
"cell_type": "code",
193-
"execution_count": 7,
181+
"execution_count": null,
194182
"metadata": {},
195183
"outputs": [],
196184
"source": [

samples/stop_cell.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 1,
28+
"execution_count": 4,
2929
"metadata": {},
3030
"outputs": [
3131
{
3232
"name": "stdout",
3333
"output_type": "stream",
3434
"text": [
35-
"['COM4']\n"
35+
"['COM10']\n"
3636
]
3737
}
3838
],
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 2,
48+
"execution_count": 5,
4949
"metadata": {},
5050
"outputs": [
5151
{
@@ -81,7 +81,7 @@
8181
},
8282
{
8383
"cell_type": "code",
84-
"execution_count": 7,
84+
"execution_count": 6,
8585
"metadata": {},
8686
"outputs": [],
8787
"source": [
@@ -151,7 +151,7 @@
151151
"name": "python",
152152
"nbconvert_exporter": "python",
153153
"pygments_lexer": "ipython3",
154-
"version": "3.11.6"
154+
"version": "3.11.7"
155155
},
156156
"orig_nbformat": 4
157157
},

samples/mem_info_list.ipynb renamed to samples/unstable/mem_info_list.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
],
4848
"source": [
4949
"# TODO replace this by a sample script that allocates memory \n",
50-
"!mpremote cp ../../micropython-stubber/src/stubber/board/logging.py :logging.py\n",
51-
"!mpremote cp ../../micropython-stubber/src/stubber/board/createstubs_info.py :createstubs.py\n",
50+
"# !mpremote cp ../../micropython-stubber/src/stubber/board/logging.py :logging.py\n",
51+
"# !mpremote cp ../../micropython-stubber/src/stubber/board/createstubs_info.py :createstubs.py\n",
5252
"# !mpremote cp ../../micropython-stubber/src/stubber/board/createstubs.py :createstubs.py"
5353
]
5454
},

src/micropython_magic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""MicroPython magics for Jupyter Notebooks and JupyterLabs"""
2-
__version__ = "0.8.1"
2+
__version__ = "0.8.2a0"
33
__author__ = "Jos Verlinde"
44

55

src/micropython_magic/interactive.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class LogTags:
3535

3636

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

98-
log.trace(f"per char , with timeout of {timeout} seconds")
98+
log.debug(f"{'line' if line_based else 'char'} based, with timeout of {timeout} seconds")
99+
assert isinstance(cmd, list)
99100
try:
100101
process = subprocess.Popen(
101102
cmd,

0 commit comments

Comments
 (0)