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.
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.
Menu
If you’ve never used VS Code, it might be a little di cult getting started. If you
nd 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:
Windows PC Instructions
Mac OS X Instructions
Linux Ubuntu Instructions
Getting Started
1) To properly follow this tutorial, you need a device with micropython
rmware. Follow one of the next tutorials to ash micropython rmware 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 rst project:
Installing Pymakr Extension on VS Code
Connecting a MicroPython device to Pymakr
Creating a MicroPython Project on VS Code + Pymakr
Menu
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.
Menu
Select the following options and click Next.
Menu
Press the Install button.
Menu
Finally, click Finish to nish the installation.
Menu
Open VS Code and you’ll be greeted by a Welcome tab with the released notes of
the newest version.
Menu
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).
Menu
After downloading the Visual Studio Code application le, 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.
Menu
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).
Menu
Save the installation le:
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
Menu
When the installation is nished, 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.
Menu
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 le 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.
Menu
2) Click on the Extensions icon to navigate to the Extensions page.
3) Search for Pymakr and install it.
Menu
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:
Menu
Pymakr Console: toggle board connection—connect/disconnect the
board
Run: run currently open le 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 le. You
should edit that le to connect a MicroPython device (for example: your ESP32 or
ESP8266 with the MicroPython rmware ashed).
Note: if the pymakr.json le doesn’t open automatically, go to All
Commands (at the bottom bar) and then select Pymakr > Global Settings.
Menu
This opens the pymakr.json le.
Menu
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 con guration le. 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 nd 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 le to add the Silicon Labs manufacturer (or other) to the
autoconnect_comport_manufacturers section. Then, save the le.
"autoconnect_comport_manufacturers": [
"Pycom",
"Pycom Ltd.",
"FTDI", Menu
"Microsoft",
"Microchip Technology, Inc.",
"Silicon Labs"
]
Selecting the COM port
After saving the le with the previous settings, you also need to set the COM port
your board is connected to. Pymakr has the ability to automatically nd 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 nd the board COM port, you can click on All Commands and select Pymakr
> Extra > List Serial Ports.
Menu
To use a prede ned COM port, you also need to set the auto_connect
parameter to false :
"auto_connect": false,
Menu
Save the pymakr.json con guration le (CTRL+S).
After saving the le, 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.
Menu
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
Menu
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 rmware 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 le with the right
con gurations 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 les: main.py and boot.py. Create those
les in the project folder:
Menu
boot.py: runs when the device starts and sets up several con guration
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 le.
Copy the following code to the main.py le. It blinks the on-board LED every half
a second.
# Complete project details at https://RandomNerdTutorials.com
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 le (CTRL+S).
Menu
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.
Menu
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.
Menu
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 e ect. 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 o cial 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
Menu
Learn more about MicroPython with our resources:
MicroPython Programming with ESP32 and ESP8266 eBook
More MicroPython projects…
Thanks for reading.
[eBook] Build Web Servers with ESP32 and
ESP8266 (2nd Edition)
Build Web Server projects with the ESP32 and ESP8266 boards to control outputs
and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server
communication protocols DOWNLOAD »
Recommended Resources
Build a Home Automation System from Scratch » With Raspberry Pi,
Menu
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…
Menu
Control ESP32 and ESP8266 GPIOs from Anywhere in the World
ESP8266 Web Server with Arduino IDE
Retrieving Bitcoin Price Using ESP8266 WiFi Module Menu
ESP-NOW with ESP32: Receive Data from Multiple Boards (many-to-one)
Get Epoch/Unix Time with the ESP32 (Arduino)
Menu
ESP32/ESP8266 Thermostat Web Server – Control Output Based on
Temperature
Enjoyed this project? Stay updated by subscribing our weekly
newsletter!
Your Email Address
SUBSCRIBE
11 thoughts on “MicroPython: Program ESP32/ESP8266
using VS Code and Pymakr”
Tamas
April 16, 2021 at 6:13 pm
You are awesome guys!
Another useful tutorial.
Thanks for that!
Reply
Menu
Sara Santos
April 16, 2021 at 9:27 pm
Thanks
Reply
luiz
April 17, 2021 at 12:14 am
Thanks a lot !!!
Reply
Romeo Nguyen-Tuong
April 17, 2021 at 9:43 am
Beautifull tutorial
Thanks
Reply
ardiwan
April 17, 2021 at 2:52 pm
Menu
very informative tutorial, thanks a lot guys
Reply
ur7imd
April 18, 2021 at 11:58 am
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
ur7imd
April 18, 2021 at 12:01 pm
VS Code: 1.55.2
Electron: 11.3.0
Node.js: 12.18.3
Pymakr: 1.1.11
Reply
Menu
ur7imd
April 18, 2021 at 12:03 pm
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
Sara Santos
April 18, 2021 at 3:26 pm
Hi.
I’m sorry, but I didn’t understand the issue.
Regards,
Sara
Reply
Menu
Alain
April 18, 2021 at 6:35 pm
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 le 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
Sara Santos
April 19, 2021 at 9:15 am
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,
Menu
Sara
Reply
Leave a Comment
Name *
Email *
Website
Notify me of follow-up comments by email.
Notify me of new posts by email.
Post Comment
Menu
Visit Maker Advisor – Tools and Gear
for makers, hobbyists and DIYers »
Home Automation using ESP8266
eBook and video course » Build IoT and
home automation projects.
Build a Home Automation System
from Scratch » With Raspberry Pi,
ESP8266, Arduino, and Node-RED.
About Support Terms and Conditions Privacy Policy Refunds Complaints’ Book
MakerAdvisor.com Join the Lab
Copyright © 2013-2021 · RandomNerdTutorials.com · All Rights Reserved