Ask Your Question

CircuitPython workflow suggestions

asked 2019-12-21 16:46:23 -0500

Background: I am using CircuitPython, which is a fork of micropython. This version of Python runs on some microcontrollers, and is supported by AdaFruit. They also support the My Editor, which is another Python IDE. Instead, I use Wing Pro 7 for CircuitPython development.

The CircuitPython environment works by connecting the microcontroller over USB to the host, where Wing is running. The microcontroller shows up as a USB drive. I copy a file called to this USB drive, and the microcontroller runs the program. It is also possible to open a terminal on the microcontroller. For example, I can run the command 'screen /dev/tty.usbmodem1421401' and this opens a terminal where I can access the REPL, or switch modes and get stdout from a running

What works so far: I can edit with Wing, and I have configured the Build command to copy the file to the microcontroller. This has the desired effect: the program runs on the microcontroller. I am able to remotely write microcontroller code in pure Python using WingIDE.

Improvement I am seeking: I get warnings 'Import not found' for all of the CircuitPython-specific modules. I would like to somehow tell Wing about these modules that are in the microcontroller's version of Python. The challenge is that this Python runs on a different architecture and some of the modules call compiled C code on the microcontroller. Is there a way to tell Wing about these modules?

edit retag flag offensive close merge delete


Do you edit the code with a proper source name, then copy it over to on the target? Or just edit it as in an appropriately named subdirectory?

RufusVS's avatar RufusVS  ( 2021-04-30 16:29:37 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-12-25 03:05:47 -0500

The way to inform Wing about the modules is to use .pyi files, which are stub python files with class and function definitions. This is commonly used elsewhere for modules that are written in C. The older format is .pi files, but new work is supposed to use .pyi.

Here are the details about how I to set up the pyi files for usage with CircuitPython. First, install circuitpython source.

pip install install rst2pyi
cd circuitpython
make stubs

This creates stubs in the directory circuitpython-stubs. Either copy the required stubs to the project as needed, or put them in a directory, and add this directory to the path in Wing Pro: WingPro -> Preferences -> Source Analysis -> Advanced -> Interface File Path

Close the project. Re-open it. It is not sufficient to "Update all warnings in file". This covers the modules that are written in C. It is not a 100% solution, there are a few gaps, probably caused by errors in the automatic stub generation process. This is a known issue and it is open.

For pure Python modules, it is easier to copy the module directories into the project as needed. Or, look at the .pyi files and follow the pattern to make your own stubs.

edit flag offensive delete link more


I can't wait to try this.

RufusVS's avatar RufusVS  ( 2021-04-30 16:30:39 -0500 )edit

answered 2019-12-23 09:38:03 -0500

updated 2019-12-23 09:38:38 -0500

If you can ssh into the microcontroller (although I'm guessing probably not?) then you could use Wing Pro's remote development support so everything Wing does, including code analysis, happens on the microcontroller.

If not that, you could generate *.pi files on the microcontroller and move them to the IDE side. How to do that is described in

edit flag offensive delete link more


I can get a terminal on the microcontroller, but it is hard-coded to be either a python REPL or the running program. I am not able to get a shell, because there is no operating system or shell on the microcontroller that is running the Python code. I found that I can copy the python modules to the local directory, adjust the names a little, and this will get rid of the warning after I restart Wing. Running 'update all warnings in file' is not enough to clear the warnings. The name adjustment is that CircuitPython puts a name prefix on the module file names, and I need to remove this file name prefix for Wing to find the classes inside the file. There are other CircuitPython modules implemented in pure C. I don't know how to tell Wing about them. The microcontroller vendor (AdaFruit) provides a Python editor ...(more)

tomacorp's avatar tomacorp  ( 2019-12-24 16:19:59 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-12-21 16:46:23 -0500

Seen: 865 times

Last updated: Dec 25 '19