Manage cookies

We use cookies to improve our services. Read more about how we use cookies and how you can refuse them.

The necessary cookies help to make the website work properly.

Anonymous statistical cookies help to understand how visitors use the website.

  • MicroPython
    3 min | 111655

    #MicroPython: Visual Studio Code (VSCode) as IDE

    MicroPython | 3 min | 111655


    Quoting the official MicroPython's website:

    MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.

    Besides C++ and C, I use MicroPython to program microcontrollers, especially the ESP32/ESP8266 types. These two microcontrollers are compatible with MicroPython and it is easy to integrate sensors and actors programming using this language. I wrote a tutorial about installing MicroPython on the ESPs, as well a lot of articles about these microcontrollers and MicroPython. This is an update to the "Getting started with MicroPython": I am changing from Atom to Visual Studio Code (VSCode), and using the PyMakr extension, it is possible to program and debug MicroPython on VSCode.

    Visual Studio Code

    The open-source VSCode is a code editor redefined and optimized for building and debugging applications. It is compatible with Windows, Linux and Mac OS X.

    “The majority of Google developers are using it now,” Chris Capossela, Microsoft’s chief marketing officer, said on the Windows Weekly podcast. :)


    Visual Studio Code - Pymakr extension
    Fig. 1: Visual Studio Code - Pymakr extension

    To use VSCode for MicroPython, you need to install the Pymakr extension (see Fig. 1).

    This extension enables VSCode to communicate to a board running MicroPython using the build-in command line REPL. Thus, you can run a single file on my board, sync your entire project or directly type and execute commands using the Terminal on VSCode.

    However, you'll miss some of the main features of VSCode, namely intellisense, autocompletion, and linting capabilities. You can combine this extension with the micropy-cli Python module to get those features. You can find more information in this tutorial.

    Configuration

    You can configure the plugin using Ctrl+Shift+P and search for Pymakr > Global Settings, you get something like this:

    {
        "address": "COM9",
        "username": "micro",
        "password": "python",
        "sync_folder": "",
        "open_on_start": true,
        "safe_boot_on_upload": false,
        "sync_file_types": "py,txt,log,json,xml,html,js,css,mpy",
        "ctrl_c_on_connect": false,
        "sync_all_file_types": false,
        "auto_connect": false
    }

    That is the global configuration. If you want to have a local configuration you need to create a file called pymakr.conf inside the folder of the project with the content from above.

    I had some issues with connecting the WiPy 3.0 (pycom). With all the other ESP boards, VSCode works really good. But with the WiPy, it was difficult to connect, and I got usually an error, when I tried to upload the files! :( I was not able to enable the safe booting because I did not find the option! If you have some tips, write them on the comment section!
    The safe booting option can be enabled with this option: "safe_boot_on_upload": true in the `pymark.conf` file.
    The new plugin version includes an auto connect option set to true. You need to disable it on the settings "auto_connect": false, if your board is not found. I have some issues with this option.

    Node.js

    The PyMakr requires Node.js. Instructions to install it are available here. For Ubuntu users to install the latest LTS version, you can use the following lines

    sudo apt-get install curl python-software-properties
    curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
    sudo apt-get install nodejs

    MicroPython IDE for VSCode

    There is also another extension for MicroPython: MicroPython IDE for VSCode. This allows to flash the firmware using the esptool.py, but it works on Linux, but not on Windows (esptool.py is not an executable on Windows).

    VSCode PyMakr Error (Update 01.08.2019):

    Today, I tried to upload the files to an ESP32 and I got the following error on VSCode:

    There was an error with your serialport module, Pymakr will likely not work properly. Please try to install again or report an issue on our github (see developer console for details)

    Apparently this is caused by VSCode switching to a newer version of Electron (4.2.5), which requires a different binding for the serialport module in order to work. If you go to VSCode > Help > About, you can see your Electron version as in Fig. 2.

    electron.png
    Fig. 2: VSCode About

    To solve the problem you need to rebuild the binding. Thus, open a CMD or Terminal and type the following:

    npm install -g prebuild-install # use sudo if required
    cd ~/.vscode/extensions/    # depeding on your platform this changes (see Note 1)
    cd pycom.pymakr-1.1.3  
    cd node_modules/@serialport/bindings
    
    prebuild-install --runtime electron --target 4.2.5 --tag-prefix @serialport/bindings@ --verbose --force
    
    # Restart VSCode, then all is working
    Note 1: Depending on your platform, go to the extension location in the following folder:
    • - Windows %USERPROFILE%\.vscode\extensions
    • - macOS ~/.vscode/extensions`
    • - Linux ~/.vscode/extensions`

    Comments

    Leo Cardinale 06.01.2019

    Hello! Have you been working with PyMakr for ESP32 since december with no problems? Do you still recommend it for nowadays? Thanks for this post!

    martin 09.13.2019

    unable to flash micropython to esp 32: open serial error__

    dear community

    issue: unable to flash micropython to esp 32: open serial error, please try again. hope to connect internet and try again.

    pretty new to micropython - want to flash micropython to esp 32 ( resp 8266) board. cf this docs: https://maker....

    getting this errors all the time.

    open serial error, please try again.
    hope to connect internet and try again.
    current version only open py txt json ini file.
    hope to connect internet and try again.
    hope to connect internet and try again.

    any idea;

    many thanks for any and all help in advance.

    Greg Woods 06.01.2020

    FYI: I use esptool on Windows all the time!

    Bill E 10.28.2020

    Sadly, this is yet another example of how immature and flakey tools for micropython continue to be.

    Ariel 04.21.2021

    Hello friends!! Tengo un problema con pymakr, mi esp8266 tiene el chip hl-340 y no puedo lograr que me lo reconozca vscode. Help....!!!