-
Notifications
You must be signed in to change notification settings - Fork 1
Sample Workflow 1
This tutorial is a work in progress
This example consists of a single file (main.py) that is created and tested using Visual Studio Code and the MPRemote extension. The purpose is to a simple example of managing a project. To follow along, you will need the following:
- A microcontroller flashed with the latest MicroPython version
- A development host with Visual Studio Code and the MPRemote extension installed
The example was written using an ESP32-C3-DevKitC-02 and MicroPython 1.20
We'll start from a fresh install of MicroPython, so grab an ESP32 you don't mind overwriting and flash it with the latest version of MicroPython.
I have another VS Code extension called ESPTool that provides a wrapper around esptool, letting you flash ESP from inside VS Code. But, you can always use the traditional command-line method if that's what you're used to. If you choose to install and use the ESPTool VS Code extension, here's how you use it to flash:
- Press CTRL + SHIFT + P and start typing write_flash to access
- Navigate the file selection dialog to find the MiscroPython download
- Choose Overwrite when prompted and watch the progress in the terminal window
If you get an error that says, Wrong boot mode detected, you may need to press and hold the BOOT button on the microcontroller as you begin flashing.
Restart the microcontroller and use MPRemote's devs command to verify it's attached and working. Then use the ls and cat commands to inspect the boot.py that comes preinstalled.
Press CTRL + SHIFT + P to access the command palette. Start typing devs to find the list files command.
>MPRemote: Scan for attached devices
You should see a line of information about the ESP32 in the terminal window.
PS C:\Users\Dave\Desktop\ESP Labs\neopixel> py.exe -m mpremote devs
COM7 ABCD1234DEF056789ABCD1234DEF0567 10c4:ea60 Silicon Labs None
Use the MPRemote ls command to show the files on the ESP32's flash filesystem and then cat to display the contents of boot.py.
PS C:\Users\Dave\Desktop\ESP Labs\neopixel> py.exe -m mpremote connect COM7 fs ls /
ls :/
431 boot.py
C:\Users\Dave\Desktop\ESP Labs\neopixel> py.exe -m mpremote connect COM7 fs cat /boot.py
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()
After verifying the flash was successful, the next step is to start coding.
In this example, we're going to create a MicroPython program to light up the onboard NeoPixel LED. It's a simple program and only consists of one file, main.py. But, main.py is not created directly on the ESP32. It's created on the development host and then copied to the ESP32, so we'll need a place to store it.
In this example, I've created a folder on my Windows Desktop called ESP Labs. Inside ESP Labs, I have a subdirectory called neopixel. This is where I'll store the local copy of main.py