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.
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 with Thonny MicroPython (Python) IDE for ESP32 and ESP8266
- Install and Getting Started with uPyCraft IDE:
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:
- Flashing MicroPython Firmware with esptool.py on ESP32 and ESP8266
- Flash/Upload MicroPython Firmware to ESP32 and ESP8266 (using uPyCraft IDE) *
* 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:
- A) Installing VS Code on Windows (Visual Studio Code)
- B) Installing VS Code on Mac OS X (Visual Studio Code)
- C) Installing VS Code on Linux Ubuntu (Visual Studio Code)
3) Then, follow the instructions to set up Pymakr, connect a MicroPython device and run your first project:
- Installing Pymakr Extension on VS Code
- Connecting a MicroPython device to Pymakr
- Creating a MicroPython Project on VS Code + Pymakr
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).
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.
Select the following options and click Next.
Press the Install button.
Finally, click Finish to finish the installation.
Open VS Code and you’ll be greeted by a Welcome tab with the released notes of the newest version.
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).
After downloading the Visual Studio Code application file, you’ll be prompted with the following message. Press the “Open” button.
Or open your Downloads folder and open Visual Studio Code.
After that, you’ll be greeted by a Welcome tab with the released notes of the newest version.
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).
Save the installation file:
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.
Open VS Code and you’ll be greeted by a Welcome tab with the released notes of the newest version.
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 Pymakr Plugin
1) Open VS Code.
2) Click on the Extensions icon to navigate to the Extensions page.
3) Search for Pymakr and install it.
The Pymakr extension is now installed on VS Code. The Pymakr Console will open, and you should have new commands at the bottom bar.
These are the new 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:
This menu opens:
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.
This opens the pymakr.json 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.
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.
To use a predefined COM port, you also need to set the auto_connect parameter to false:
"auto_connect": false,
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.
Type help() on the Terminal window after the prompt (>>>) and see your board responding:
help()
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:
- 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)
Save the file (CTRL+S).
Then, click on the Upload button.
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.
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.
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:
- MicroPython Programming Basics with ESP32 and ESP8266
- MicroPython with ESP32 and ESP8266: Interacting with GPIOs
- ESP32/ESP8266 MicroPython Web Server
Learn more about MicroPython with our resources:
Thanks for reading.
You are awesome guys!
Another useful tutorial.
Thanks for that!
Thanks 🙂
Hi Sara, thank you for your effort
I need, please a code with python for connecting ESP32 with other ESP32 cartes
Hi.
I don’t have that at the moment.
Regards,
Sara
Thanks a lot !!!
Beautifull tutorial
Thanks
very informative tutorial, thanks a lot guys
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
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
Hi.
I’m sorry, but I didn’t understand the issue.
Regards,
Sara
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.
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
Hi Alain.
I don’t know what the issue is, and unfortunately, I don’t have a MAC computer to experiment with.
Maybe it is best to post an issue in the pymakr plugin forum: https://github.com/pycom/pymakr-vsc/issues
There are also other IDES you can try:
https://randomnerdtutorials.com/install-upycraft-ide-mac-os-x-instructions/
https://randomnerdtutorials.com/getting-started-thonny-micropython-python-ide-esp32-esp8266/
Regards,
Sara
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”
Hi.
Don’t worry about that error.
It happens because “machine” is not a python module. It is a micropython module. At the moment, VS code only recognizes python language, not micropython (that includes different modules).
Regards,
Sara
Hi have a look at the micropy-cli project on github https://github.com/BradenM/micropy-cli
it adds VSCode Intellisense + other things to VS code
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
Place it inside the same folder as main.py and boot.py.
Regards,
Sara
I cannot get the plugin to do anything. I cannot even open the help screen under
“All Commands -> Pymakr > Help”
What am I missing?
Hi.
What happens exactly when you try to open the help screen?
Regards,
Sara
Hello Maam ,
I am facing issue in the Node Mcu esp8266. I want to communicate with other node mcu via mac address. but the node mcu is reseting itself and showing the error.
ets Jan 8 2013,rst cause:2, boot mode:(3,0)
Please maam Resolve this problem ! I can’t afford the courses right now!
Hi.
Check this tutorial: https://randomnerdtutorials.com/esp-now-two-way-communication-esp8266-nodemcu/
Regards,
Sara
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 …”
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
Hi.
After installing, restart VS Code.
Then, go to the extensions tab again and check that the extension is enabled for that specific workspace.
If this doesn’t work, it is better to post an issue on the Pymakr issues page:
https://github.com/pycom/pymakr-vsc/issues
This topic seems related to your issue: https://github.com/pycom/pymakr-vsc/issues/157
I hope this helps.
REgards,
Sara
Hi, i want to upload the OTA in esp, but i didn’t that
Sabes cómo hacer que autocomplete. Esquel nada que me sale, puedo hacer debug al codigo
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.
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
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)?
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
Hi.
Did you restart after install?
Does it display any message on the lower right corner?
Regards,
Sara
I miss the “t”
Of course i canT configure the ESP32
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).
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.
Well I tried uninstalling everything and reinstalling but to no avail. Pymakr seems to be installed but not running on my VSCode.
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.