Development Environment and Workflow for MicroPython

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.
mhepp
Posts: 19
Joined: Thu May 28, 2015 5:50 pm

Development Environment and Workflow for MicroPython

Post by mhepp » Sat May 20, 2017 8:59 am

Hi all,
I want to set up a productive development environment and workflow before starting to try more serious things with MicroPython. My main target platform is the ESP8266 family (mostly Adafruit boards), but I also have a few original Pyboards and almost all pycom.io boards and the BBC microbit in sample quantities.

I have seen PyMakr,

https://github.com/pycom/Pymakr

but I am unsure whether it can also be used for ESP8266 boards or only the WiPy, LoPy and the others from pycom.io. Also, there are some reports in this forum about various problems with PyMakr, so I would like to assess how mature and stable PyMakr is at this point.

Currently, I plan to simply use a TextMate or Sublime as an editor, Github for version control, and a few command line scripts for uploading code from the development machine to the MicroPython target.

As a general preference, I like light and fast development environments (like TextMate + Plugins) better than heavyweight ones like Eclipse/PyDev.

Any hints?

Thanks - Martin

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Development Environment and Workflow for MicroPython

Post by pythoncoder » Sat May 20, 2017 1:07 pm

Have you looked at rshell https://github.com/dhylands/rshell.git? I use it for Pyboards and ESP8266. I've no reason to think it wouldn't work with other MicroPython platforms.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Development Environment and Workflow for MicroPython

Post by Roberthh » Sat May 20, 2017 1:38 pm

I just tried LoPy with rshell, just to confirm Peter's statement. Lopy worked with the USB connection, calling it up with:

Code: Select all

rshell -p /dev/ttyUSB0 --buffer-size 30
That allows you to see and access the board on the file on the directory /flash. The buffer-size option is important. On the pycom devices you can also use ftp for transferring files in and out. rshell may not be foolproof, but less critical than the abandoned pymakr or it's replacement, the pymakr plug-in for Atom.

mhepp
Posts: 19
Joined: Thu May 28, 2015 5:50 pm

Re: Development Environment and Workflow for MicroPython

Post by mhepp » Sat May 20, 2017 4:51 pm

Thanks!

I will experiment with rshell. Ideal would be a plugin for the Sublime editor so that one can automatically sync files on the MicroPython device, similar to the available ones for plain FTP.

One could then simply save a file locally and have it transferred to the uP device in parallel.

The code will likely have to combine rShell with the boilerplate for a Sublime plugin, similar to

https://github.com/NoxArt/SublimeText2-FTPSync

I will not have the resources to tackle that myself, but maybe it is a promising direction for a Kickstarter campaign. Sublime is a really nice environment for Python development.

Martin

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: Development Environment and Workflow for MicroPython

Post by randmor » Sun May 21, 2017 3:12 pm

Hi Guys...
I was trying to get rshell to run on an ESP8266 board using what limited docs they had on the GitHub page, but was unable to complete their demo, failing with the "cp hello.py /flash" command. My assumption was that rshell's "/flash" feature probably had not yet been ported to the ESP8266, and so I've been using the "mpy-upload" utility instead (a bit of an inconvenience). Reading this series of posts offers me some encouragement to re-examine my problem. I assume now that perhaps I need to set up buffers size of 30 when invoking rshell:

rshell -p /dev/ttyUSB0 --buffer-size 30

Are there any other "special" things you had to do to make the "/flash" feature work with rshell?
My target ESP8266 platforms are the WeMos D1/R2 and Amica & Lolin brands of NodeMCUs.
Last edited by randmor on Sun May 21, 2017 4:33 pm, edited 1 time in total.

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: Development Environment and Workflow for MicroPython

Post by randmor » Sun May 21, 2017 4:01 pm

Okay, I got it figured out.

First, before you can run the rshell command "cp hello.py /flash", you have to create a "flash" directory in the ESP8266 FAT file-system. This can be done using these commands from rshell:

/home/username> cat hello.py
print("MicroPython is cool!")
print("And 'rshell' makes it even cooler!")

/home/username> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> import os
>>> os.mkdir('flash')
>>> os.listdir()
['boot.py', 'flash']
>>> (control-x)
/home/username> cp hello.py /flash
/home/randmor> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> import os
>>> os.listdir('flash')
['hello.py']
>>>
>>> os.listdir('flash')
['hello.py']
>>> import hello
MicroPython is cool!
And 'rshell' makes it even cooler!
>>>

Notice how "import hello" is used to execute the hello.py MicroPython program nowstore in the /flash directory. With the vi (vim) editor accessible in "rshell" using the "edit('filename')" command, rshell appears to be the closest thing to an IDE for MicroPython that I have come across. If you know better, let me know!

One last note: Can set up an Linux environment variable to simplify the 'rshell --port /dev/ttyusb0' command down to just 'rshell'
by entering the following command at the Linux shell prompt:'

export RSHELL_PORT="/dev/ttyUSB0"
Last edited by randmor on Sun May 21, 2017 4:36 pm, edited 3 times in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Development Environment and Workflow for MicroPython

Post by Roberthh » Sun May 21, 2017 4:10 pm

The top level directory on the ESP8266 can with rshell also be accessed as /pyboard, even if that directory does not exist on your device. So a command:
ls /pyboard
will list the tld of your device.

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: Development Environment and Workflow for MicroPython

Post by randmor » Sun May 21, 2017 4:38 pm

Thanks Robert. I'll try that as well. Yeah, that worked well!

/home/username> cp hello.py /pyboard
/home/username> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.8.7-7-gb5a1a20a3 on 2017-01-09; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> import os
>>> os.listdir()
['boot.py', 'flash', 'hello.py']
>>> import hello
MicroPython is cool!
And 'rshell' makes it even cooler!
>>>

And I take it that "tld" means "top level domain" or "root directory" as I'd call it.

mhepp
Posts: 19
Joined: Thu May 28, 2015 5:50 pm

Re: Development Environment and Workflow for MicroPython

Post by mhepp » Sun May 21, 2017 5:05 pm

Thanks! Having a single CLI like rshell helps a lot to solve this problem in a cross-platform way that will work on many if not all MicroPython boards.

If I find the time, the next thing I will try to to is develop a plug-in for the Sublime editor that will offer two functions:

1. Sync all local files (basically copy everything from the project directory (maybe minus files matching a pattern of an "ignore" directive, tbd)
2. Run the script on the MicroPython board and show the console in a terminal window

I switched to Sublime only recently, having been a happy TextMate user for almost ten years, but am pretty enthusiastic about it.

This might become a very lightweight yet productive MicroPython environment + workflow.

The specs for such plug-ins are here, btw:

http://docs.sublimetext.info/en/latest/ ... ugins.html

Should similar efforts exist, please let me know!

One minor thing that will be missing in such a Sublime-rShell "IDE" is proper auto-complete for the MicroPython specifics, but I think I can live with the standard Python 3.x one for the time being.

Martin

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

Re: Development Environment and Workflow for MicroPython

Post by dhylands » Sun May 21, 2017 5:43 pm

rshell has an rsync command that will keep a directory tree on the device in sync with a directory tree on the host.

Post Reply