First steps for an interactive micropython ... IPython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
torwag
Posts: 167
Joined: Fri Dec 13, 2013 9:25 am

First steps for an interactive micropython ... IPython

Postby torwag » Thu Apr 02, 2015 4:30 pm

Hi,
I was looking for an way to use micropython and the pyboards in classes.
There are some challenges:
1. Students are not always comfortable with the command line.
2. Creating a more interactive teaching environment, that is theory together with interactive code.
3. Being able to share and access within a classroom network.

All those points (and many more) are on the list for ipython. Thus, I was wondering if there is a way to use micropython within ipython. I read a bit and luckily this seems to be easier as expected.
Below you see the very first ipython notebook talking to an micropython kernel.
Be aware that this version of micropython is the unix port running on the host PC. Thus, next steps will be to access a micropython running on a pyboard.
screenshot_micropython.png
screenshot_micropython.png (46.24 KiB) Viewed 2294 times


After that we should have a nice set of possibilities. E.g. students can access a pyboards attached to other PCs, web-based interactive programming at a low hardware level, creating of course-materials which can interactively access a pyboard for hand-on experiments. I also want to add to save a ipython session directly on a pyboard, thus after an session of interactive fiddling, testing and debugging, one could load the final result on the pyboard to execute it standalone.

This is just the very beginning, there is a lot of room for further improvements like code completion, interactive plots of e.g. ADC data. However, it is a start. I will try to get the pyboard working next and after that one can think of more whistle and bells. Building on the shoulders of giants here... thanks to Micropython and ipyhton, I am just adding some glue

User avatar
dhylands
Posts: 2260
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: First steps for an interactive micropython ... IPython

Postby dhylands » Thu Apr 02, 2015 5:52 pm

Sweet.

I just started playing with IPython notebooks and was thinking along the same lines.

Are you planning on documenting how you set this up? I know I would definitely be interested in playing around with this.

torwag
Posts: 167
Joined: Fri Dec 13, 2013 9:25 am

Re: First steps for an interactive micropython ... IPython

Postby torwag » Fri Apr 03, 2015 9:16 am

Hi,
naa, I thought of keeping it closed source and selling it for big money ;)
As soon as I come to a stable and usable point, including adressing a micropython instance on a pyboard, I will create a repository on github...
If by time, Damien and the dev gang find it useful enough, we might could consider to ship it together with micropython.
Features I want to add after being able to talk directly to a pyboard are,
* code completion (since micropython libs are sometimes only a subset of the equivalent pc libs, this proves to be very valuable during interactive use)
* export the ipython notebook to the pyboard: This is not as easy as it might require source code changes in ipython, something I would like to avoid.
* process in and outgoing data within ipython: this is again part of the micropython kernelwrapper and would allow e. g. to directly draw a matplotlib-based plot for incomming ADC data.
Maybe we can have knobs and sliders for outgoing data too. Need to check on this.

As said in the first post I aim to create an interactive course material learning to use python and with the help of micropython and the pyboard to work on topics like embedded data processing, e. g. implementing a PID control algorithm on the pyboard, controlling a real world system (sitting right on the bench beside the student)

pfalcon
Posts: 893
Joined: Fri Feb 28, 2014 2:05 pm

Re: First steps for an interactive micropython ... IPython

Postby pfalcon » Sun Apr 05, 2015 1:08 pm

torwag wrote:Hi,
naa, I thought of keeping it closed source and selling it for big money ;)
As soon as I come to a stable and usable point, including adressing a micropython instance on a pyboard, I will create a repository on github...


"Release early, release often." What if tomorrow you'll find another interesting project to work on? All you work on this bit then likely will be lost to humanity. This happens to me all the time - I have tons of code not submitted upstream or not releases lying around.

If by time, Damien and the dev gang find it useful enough, we might could consider to ship it together with micropython.


This topic ("I wrote a piece of cool code, why not ship in micropython?") comes up regularly, so I guess it's time to come up with explicit: "Thanks, but no". IPython is not shipped with CPython. What makes Python community strive is that independent people and organizations ship their own Python code. So, if you like/need something, ship it on your own, support, maintain it, spend your time on it.



And of related stuff, I'm myself growing to treat comfortable interactive usage in MicroPython more important. In that regard, https://github.com/micropython/micropyt ... 752c8c253f was committed. I also seriously consider adding "tab to indent" and "autointent" features for bare-metal ports.

pfalcon
Posts: 893
Joined: Fri Feb 28, 2014 2:05 pm

Re: First steps for an interactive micropython ... IPython

Postby pfalcon » Sat Apr 11, 2015 11:21 am

Another idea I contemplated for some time is implementing onboard text editor. I actually wanted to lure dhylands into, whose seems to like terminal stuff, but I just had occasion for another project which needs similar functionality, so gave in and went for it myself. The WIP is here if anyone is interested: https://github.com/pfalcon/pyedit . I didn't actually test on pyboard, and it probably won't work because of packet size/transfer delays (would need to use dedicated UART classes), but it works really well on Linux with both MicroPython and Python3. Here's some thing I'm not sure about: on one hand, I'd like to keep it really simple and minimal, so it could run on as small as possible boards and edit as large as possible files, on the other hand, I'd like it to be configurable and reusable, e.g. to be a part of Text UI library. Revision 1 in the repo above represent "minimal" version, further commits add more features. The solution may be to maintain 2 version - one hardcoded and minimal, another - extensible. I welcome feedback on whether someone finds this useful at all and thinking above makes sense.

Damien
Site Admin
Posts: 505
Joined: Mon Dec 09, 2013 5:02 pm

Re: First steps for an interactive micropython ... IPython

Postby Damien » Sun Apr 26, 2015 12:27 pm

@torway did you get any further with this? Can you post the code somewhere so I can take a look at how it is done? If you can interface with unix micropython then it should be relatively easy to interface with tool/pyboard.py and hence the pyboard.

@pfalcon your text editor is nifty! I didn't try it on pyboard though.

I think all these avenues have their own merits: IPython for sophisticated interfacing and plotting; a web-based IDE a la Espruino for those who don't want to install any programs; and an enhanced REPL with a mini text editor, auto tabbing, auto completion etc.

pfalcon
Posts: 893
Joined: Fri Feb 28, 2014 2:05 pm

Re: First steps for an interactive micropython ... IPython

Postby pfalcon » Sun Apr 26, 2015 4:25 pm

Damien wrote:@pfalcon your text editor is nifty! I didn't try it on pyboard though.


Neither me still, unfortunately. With some latest changes it might even work, but need more robust parsing of ESC sequences, assuming you can't rely on timing characteristics of a serial stream. Anyway, I split off discussion of pyedit (might select a better name too, upyedit? ;-) ) to viewtopic.php?f=5&t=669

I think all these avenues have their own merits: IPython for sophisticated interfacing and plotting; a web-based IDE a la Espruino for those who don't want to install any programs; and an enhanced REPL with a mini text editor, auto tabbing, auto completion etc.


I surely agree.

pfalcon
Posts: 893
Joined: Fri Feb 28, 2014 2:05 pm

Re: First steps for an interactive micropython ... IPython

Postby pfalcon » Sun Apr 26, 2015 5:19 pm

Btw, seeing https://github.com/micropython/micropython/pull/1200 reminded me about http://www.bpython-interpreter.org/ which I stumbled upon some time ago. (I didn't try it myself though.)

Damien
Site Admin
Posts: 505
Joined: Mon Dec 09, 2013 5:02 pm

Re: First steps for an interactive micropython ... IPython

Postby Damien » Sun Apr 26, 2015 9:17 pm

pfalcon wrote:http://www.bpython-interpreter.org/ which I stumbled upon some time ago


Some cute ideas to copy. Definitely we can support colours, at least making exceptions highlighted in red would be useful. micropython.repl_config(colour=True) anyone? :)

pfalcon
Posts: 893
Joined: Fri Feb 28, 2014 2:05 pm

Re: First steps for an interactive micropython ... IPython

Postby pfalcon » Sun Apr 26, 2015 10:00 pm

Well, I'd consider those ideas to be interesting to be implemented in Python, not C. There're more important stuff to implement in C ;-).


Return to “Programs, Libraries and Tools”

Who is online

Users browsing this forum: No registered users and 1 guest