MicroPython: Program ESP32/ESP8266 using VS Code and Pymakr

In this guide, you’ll learn how to program your ESP32 and ESP8266 boards with MicroPython using VS Code Editor (Visual Studio Code) with the Pymakr extension.

If you’re used to programming the ESP32 and ESP8266 boards using VS Code with PlatformIO IDE (Arduino core), and you also want to program them with MicroPython, using the Pymakr extension might be a good alternative.

Program ESP32/ESP8266 Boards with MicroPython using VS Code and Pymakr

We’ve experimented with several IDEs to program the ESP32 and ESP8266 boards with MicroPython. All IDES have advantages and disadvantages. In our opinion, this option works the best with fewer bugs when compared to other IDEs. However, it might be an overwhelming task getting used to VS Code.

If you’ve never used VS Code, it might be a little difficult getting started. If you find that this option is very advanced, you might consider using simpler IDEs like Thonny IDE and uPyCraft IDE to program your boards with MicroPython:

Getting Started

1) To properly follow this tutorial, you need a device with micropython firmware. Follow one of the next tutorials to flash micropython firmware on the ESP32 or ESP8266 boards:

* this option is easier, but requires that you install uPyCraft IDE software.

2) You need to install VS Code on your computer. Follow one of the next sections if you need to install VS Code:

3) Then, follow the instructions to set up Pymakr, connect a MicroPython device and run your first project:

A) Installing VS Code on Windows (Visual Studio Code)

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Windows).

Microsoft Visual Studio Code VS Code Download Page for Windows PC

Click on the installation wizard to start the installation and follow all the steps to complete the installation. Accept the agreement and press the Next button.

Microsoft Visual Studio Code VS Code Installation wizard

Select the following options and click Next.

Microsoft Visual Studio Code VS Code Installation wizard step 2

Press the Install button.

Microsoft Visual Studio Code VS Code Installation wizard step 3

Finally, click Finish to finish the installation.

Microsoft Visual Studio Code VS Code Installation wizard final step

Open VS Code and you’ll be greeted by a Welcome tab with the released notes of the newest version.

Microsoft Visual Studio Code VS Code Installation wizard welcome screen on a Windows PC

That’s it. Visual Studio Code was successfully installed.


B) Installing VS Code on Mac OS X (Visual Studio Code)

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Mac OS X).

Microsoft Visual Studio Code VS Code Download Page for Mac OS X

After downloading the Visual Studio Code application file, you’ll be prompted with the following message. Press the “Open” button.

Microsoft Visual Studio Code VS Code Downloading application file for Mac OS X

Or open your Downloads folder and open Visual Studio Code.

Microsoft Visual Studio Code VS Code Downloading application file for Mac OS X

After that, you’ll be greeted by a Welcome tab with the released notes of the newest version.

Microsoft Visual Studio Code VS Code Installation wizard welcome screen on Max OS X

That’s it. Visual Studio Code was successfully installed.


C) Installing VS Code on Linux Ubuntu (Visual Studio Code)

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Linux Ubuntu).

Microsoft Visual Studio Code VS Code Download Page for Linux Ubuntu

Save the installation file:

Microsoft Visual Studio Code VS Code Save installation file for Linux Ubuntu

To install it, open a Terminal windows, navigate to your Downloads folder and run the following command to install VS Code.

$ cd Downloads
~/Downloads $ sudo apt install ./code_1.49.1-1600299189_amd64.deb

When the installation is finished, VS Code should be available in your applications menu.

Microsoft Visual Studio Code VS Code Open application Linux Ubuntu

Open VS Code and you’ll be greeted by a Welcome tab with the released notes of the newest version.

Microsoft Visual Studio Code VS Code Installation wizard welcome screen on Linux Ubuntu

That’s it. Visual Studio Code was successfully installed.


Installing Pymakr Extension on VS Code

In this section, we’ll install the Pymakr extension on VS Code. This extension allows you to communicate to your MicroPython devices using the build-in command-line REPL. It provides a UI with buttons to run a single file to your board, sync your entire project or directly type and execute commands.

Prerequisites

To use Pymakr extension on VS Code, you need node.js installed on your computer.

Go to the node.js website Home or Downloads page and install node.js on your operating system.

Installing node.js setup windows

Installing Pymakr Plugin

1) Open VS Code.

VS Code Homepage welcome screen Visual Studio

2) Click on the Extensions icon to navigate to the Extensions page.

Vs Code Extensions plugins icon Visual Studio

3) Search for Pymakr and install it.

Install Pymakr VS Code Micropython Visual Studio Code

The Pymakr extension is now installed on VS Code. The Pymakr Console will open, and you should have new commands at the bottom bar.

Install Pymakr json config file VS Code Micropython

These are the new commands:

Install PymakrVS Code Micropython Commands
  • Pymakr Console: toggle board connection—connect/disconnect the board
  • Run: run currently open file on the board
  • Upload: upload project to your board
  • Download: download project from your board
  • All commands: list all available Pymakr commands

Select All commands:

Pymakr open all commands menu

This menu opens:

Install Pymakr VS Code Micropython Commands actions

Connecting a MicroPython Device to Pymakr

At the same time, Pymakr will automatically open the pymakr.json file. You should edit that file to connect a MicroPython device (for example: your ESP32 or ESP8266 with the MicroPython firmware flashed).

Note: if the pymakr.json file doesn’t open automatically, go to All Commands (at the bottom bar) and then select Pymakr > Global Settings.

pymakr global settings file

This opens the pymakr.json file.

Connecting a MicroPython Device to Pymakr pymark.json config file

Pymakr has a list of USB devices that it will connect to. You need to make sure that your device is on the list in the pymakr.json configuration file. You need to add the USB Manufacturer that the device uses to connect to the PC. In our case, both the ESP32 and ESP8266 use the Silicon Labs USB drivers.

To find which drivers your board uses, open your computer’s Devices Manager (with the board connected to your computer) and search for connected USB devices.

ESP32 or ESP8266 NodeMCU board drivers

On the Device Manager, you can also check which COM port is being used by the device. In our case, it is COM3.

Now, edit the file to add the Silicon Labs manufacturer (or other) to the autoconnect_comport_manufacturers section. Then, save the file.

"autoconnect_comport_manufacturers": [
  "Pycom",
  "Pycom Ltd.",
  "FTDI",
  "Microsoft",
  "Microchip Technology, Inc.",
  "Silicon Labs"
]

Selecting the COM port

After saving the file with the previous settings, you also need to set the COM port your board is connected to. Pymakr has the ability to automatically find your COM port (it may not work for some users).

For automatic connect, let the address setting empty, and set the auto_connect to true.

"address": "",
"auto_connect": true,

In my case, it was able to detect the COM port automatically (a ✓ shows up next to the Pymakr Console button).

If your board doesn’t connect automatically, you need to change the address section with the COM port of your board. For example:

"address": "COM3",

To find the board COM port, you can click on All Commands and select Pymakr > Extra > List Serial Ports.

pymakr extra list serial ports

To use a predefined COM port, you also need to set the auto_connect parameter to false:

"auto_connect": false,
Edit configure Micrpython Pymakr pymark.json config file

Save the pymakr.json configuration file (CTRL+S).

After saving the file, Pymakr will automatically detect your board (a ✓ will show up next to the Pymakr Console button). If that doesn’t happen, toggle the Pymakr Console button to try to do it manually. If nothing happens, we recommend restarting VS Code.

Pymakr pymark.json console window terminal connecting

Type help() on the Terminal window after the prompt (>>>) and see your board responding:

help()
Pymakr pymark.json console window terminal help run commands

That’s it! Pymakr was successfully installed on VS Code and you successfully connected a MicroPython device. Follow the next section to learn how to create, save and upload a project to your board.

ESP32/ESP8266 Creating a MicroPython Project on VS Code + Pymakr

Follow this section to learn how to create a MicroPython Project on VS Code using Pymakr to program your ESP32 and ESP8266 boards. As an example, we’ll upload a code to blink the on-board LED (GPIO 2).

1) First, connect an ESP32 or ESP8266 board with micropython firmware installed to your computer.

2) Create a folder for your project. For example: blink.

3) Open VS Code. Pymakr will automatically try to connect to your board. If it doesn’t do that, go to the Extensions menu and open the Pymakr extension. Additionally, double-check that you’ve edited the pymakr.json file with the right configurations to connect to your board. See Connecting a MicroPython Device to Pymakr.

4) Then, go to File > Open Folder and select the folder you’ve just created. Every MicroPython project should have two files: main.py and boot.py. Create those files in the project folder:

VS Code Visual Studio editor edit files
  • boot.py: runs when the device starts and sets up several configuration options;
  • main.py: this is the main script that contains your code. It is executed immediately after the boot.py.

In this section, we’ll upload a simple code that blinks the on-board LED. For this reason, you don’t need to copy anything to the boot.py file.

Copy the following code to the main.py file. It blinks the on-board LED every half a second.

# Complete project details at https://RandomNerdTutorials.com/micropython-programming-with-esp32-and-esp8266/

from machine import Pin
from time import sleep

led = Pin(2, Pin.OUT)

while True:
  led.value(not led.value())
  sleep(0.5)

View raw code

Save the file (CTRL+S).

VS Code Visual Studio editor edit main file

Then, click on the Upload button.

VS Code Visual Studio Upload files

It will upload the code to the board and automatically restart the board to start running the code.

The ESP32 or ESP8266 on-board LED should be blinking.

ESP32 board Built in LED turned on HIGH

Important: the Run command runs the code without uploading the code to the board. This means that the code will only run as long as it is connected to the computer. To upload code to the board, you should select the Upload option.

To make further changes (uploading a new code), press CTRL+C to stop any running code. You won’t be able to upload new code if the ESP is running another code.

You also won’t be able to execute any other commands while the board is running a code. If the prompt (>>>) is not displayed, it means the board is running a code. Press CTRL+C to stop running the code, and the prompt (>>>) will show up. After that, you can execute commands.

Disable/Hide Pymakr Extension

When you’re not using Pymakr, it can be useful to disable/hide the Pymakr commands at the bottom bar. This is especially useful if you’re programming the ESP boards using the PlatformIO extension. Having both extensions enabled at the same time can cause issues uploading the code and connecting to the board.

To hide the Pymakr commands, you need to go Extensions and search for the Pymakr extension on the installed extensions. Then, click on Disable.

Disable Pymakr extension plugin VS Code

Restart VS Code for the changes to take effect. The next time you want to use the Pymakr extension, you need to enable the extension again.

Wrapping Up

In this tutorial, you’ve learned how to use VS Code with the Pymakr extension to program your ESP32 and ESP8266 using MicroPython. This is a great option, especially for those already used to program the ESP boards using VS Code. We also recommend reading the official notes and instructions of the Pymakr extension here.

We hope you found this tutorial useful. What’s next? To get started programming with MicroPython, we recommend the following tutorials:

Learn more about MicroPython with our resources:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

38 thoughts on “MicroPython: Program ESP32/ESP8266 using VS Code and Pymakr”

  1. 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)

    Platform: Raspberry Pi 4
    Linux RPi4 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux

    Reply
  2. 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)

    Platform:
    Raspberry Pi 4
    Linux RPi4 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux

    VS Code: 1.55.2
    Electron: 11.3.0
    Node.js: 12.18.3
    Pymakr: 1.1.11

    https://github.com/pycom/pymakr-vsc/issues/53

    Reply
    • Has anyone been successful in getting the Pymakr extension to work within VSCode running on a Raspberry Pi? I’m seeing the same errors that ur7imd is seeing.

      Note that I am not trying to install micropython on a Raspberry Pi Pico.
      Rather I am trying to use VSCode running on a Raspberry Pi 4 to program ESP32 boards using the (micro)Python language

      I currently use a Raspberry Pi 4 running VSCode with the PlatformIO extension to program ESP32 boards using the C++ language. I want to be able to use the Raspberry Pi 4 and VSCode in a similar fashion to program ESP32 boards using the (micro)Python language.

      I have successfully used VSCode / Pymakr running on an iMac to program ESP32 boards in (micro)Python.

      Reply
  3. Hi Sara and Rui,
    I’m using a Mac with Big Sur.
    As described in the tutorial, VScode get installed in the downloads. I copied it in the apps instead.
    nodejs is also installed.
    But for a reason that I don’t understand I can’t succeed to install Pymakr. It ask to download it manually and afterwards I can’t install it. VScode does not open it or it says that the file is corrupted.
    Is there an alternative to Pymakr? What is missing in the tutorial to get it done?
    I could install another extension without problem at all (prettier)
    Regards
    Alain

    Reply
  4. Hello.
    I’ve successfully uploaded the code to my esp8266 and the LED is blinking but I get a problem on the VSCode screen saying “import “machine” could not be resolved”

    Reply
  5. thanks for your quick reply.
    Just another doubt if you please.
    which is the correct folder to place modules you need to import such as umqttsimple.py?
    thanks

    Reply
  6. I cannot get the plugin to do anything. I cannot even open the help screen under

    “All Commands -> Pymakr > Help”

    What am I missing?

    Reply
  7. I have
    VS code 1.59.1
    Pymaker V1.1.12
    NodeJS 16.7.0
    Windows 10 64 bit

    Pymaker does not show at the bottom of VS code
    I can’t run Pymakr globel settings
    When VS code starts I get the messge
    “There was an error with your seialport module, Pymakr will likley not …”

    Reply
  8. when i installed pymakr – it said it was installed – but the icons did not apear in the status bar and the promised new window with commands did not open –

    when i open a terminal (powershell) and type Pymakr > Global Settings. says it is not a command

    Reply
  9. Hi Sara; I purchased a “Adafruit HUZZAH32 – ES” from Mouser Electronic -The IC on the circuit board says “Express ESP32 WROOM” . How do I get started and what software do I need to – What do I need to install on the circuit board IFF I would like to use MicroPython to program instead of Arduino.? I use “Thonny” with microPython code- to program the raspberry PI Pico.
    I own a Mac Pro.BTW: Do you have a YouTube Videos on this? There are SO many videos that it gets confusing.
    I appreciate your help!
    M.

    Reply
    • Hi.
      I think that to program that board with MicroPython is the same as for other “regular” ESP32 boards.
      So, I think you just need to follow our instructions and it will work.
      Regards,
      Sara

      Reply
  10. Hi Sara,
    After installing the extension, I don’t get the Pymakr commands at the bottom bar. All I see is the “home” icon for PlatformIO, and the bottom bar is blue instead of purple. How do I get the Pymakr bar?

    Going further a bit, I’m presented with pymakr.conf, not pymakr.json. Is this because I’m suing a newer version of Pymakr (2.22.5) and vscode (1.70.2)?

    Reply
  11. Hi sara!
    I have installed Node and VS Code properly, but the bottom bar is not violet, is black…

    Then when i install the extension pymakr (the installation was fine), but the bottom bar is still black instead violet, and i dont have the Pymakr Console. of course i can configure the ESP32

    Do you have any idea about where could be my mistake?

    Cheers

    Reply
  12. This instruction applies to Pymakr version 1.1.11 and today it has version 2.22.5 perhaps due to this situation when installing Pymakr it doesn’t match the explained instructions (Pymakr console doesnot open).

    Reply
  13. The Pymakr extension is now installed on VS Code. The Pymakr Console will open, and you should have new commands at the bottom bar.

    Pymakr Console does not open and I don’t have any new commands at the bottom. There is no “All Commands” at the bottom of my screen.

    Reply
  14. Well I tried uninstalling everything and reinstalling but to no avail. Pymakr seems to be installed but not running on my VSCode.

    Reply
  15. So this just isn’t working. Tried on my work computer this afternoon and got the same results. Pymakr seems to be installed but not working. I’m going looking for a tutorial on using VSCode without pymakr. The pymakr getting started guide is pretty much useless as well.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.