Carglglz / jupyter_upydevice_kernel

Jupyter MicroPython Kernel made with upydevice
https://pypi.org/project/jupyter-micropython-upydevice/
BSD 3-Clause "New" or "Revised" License
14 stars 2 forks source link

Transfer files to device? #2

Open pgcudahy opened 4 years ago

pgcudahy commented 4 years ago

Is there a way to transfer files to the device from within a notebook? I'm currently using the notebook to prototype, and then when the code is ready I'd like to do

%local
%%writefile test.py
def adder(a, b):
    return(a + b)

Followed by something like

%put test.py

Is there a way to accomplish this within the jupyter notebook? Thanks

Carglglz commented 4 years ago

@pgcudahy Yes, I'm sure it can be done, but since I use upydev to to get/put files I did not need to add these commands in the kernel. The first cell works already:

%local
%%writefile test.py
def adder(a, b):
    return(a + b)

If you are using a serial connection check, serial shell-rep to upload files. You can be connected to the device with this serial shell-repl and the Jupyter kernel at the same

So in a terminal go to your current working directory, and connect with the serial shell-repl, then after saving the file with %%writefile command in the Jupyter cell, do in the serial shell-repl:

$ put test.py

Then you can import and run whatever is in the script.

e.g. example session:

%serialconnect /dev/tty.usbmodem387E386731342
** Serial connected **

/dev/tty.usbmodem387E386731342

MicroPython v1.12-665-g60f5b941e on 2020-08-18; PYBLITEv1.0 with STM32F411RE
Type "help()" for more information.
%local
%%writefile test.py
def adder(a, b):
    return(a + b)

Now in the terminal, in the current working directory start the serial shell-repl

upy_scripts$ upydev shr@fanpy
SERIAL SHELL-REPL connected

MicroPython v1.12-665-g60f5b941e on 2020-08-18; PYBLITEv1.0 with STM32F411RE
Type "help()" for more information.

Use CTRL-x to exit, Use CTRL-s to toggle shell/repl mode
Use CTRL-k to see more info
upy_scripts:/pyboard@fanpy:~ $ put test.py 
File/s to put:
- test.py
test.py  [0.03 KB]
▏██████████████████████████████ /  100 % | 0.03/0.03 KB |  0.08 KB/s | 00:00/00:00 s

upy_scripts:/pyboard@fanpy:~ $       

Now in the Jupyter cells

from test import adder
adder(1,2)
3

I hope this helps 👍