The Internet of Things virus got me too 😉
I wanted to play and bought an ESP8266 development board, a temperature and humidity sensor and a small display. I had plenty of breadboards from my Raspberry Pi experiments. I was ready to follow Miguel Grinberg's excellent tutorial. I highly recommend this tutorial if you want to start playing with microcontrollers and micropyhton.
I'm not going to talk about the microcontroller or micropyhton here. But I will talk about VSCode and how you can make your life easier when programming with micropython and a firmware with baked classes you don't have locally on your development host.
First few lessons, first import, and pylint is already complaining. This gets out of hand very quickly. Not to mention, no Intellisense. Not cool.
New virtualenv, micro-cli installed, I install the stubs I need and create a new project.
~/Dev/micropy-cli via .env ➜ micropy stubs search esp8266 MicroPy Searching Stub Repositories... MicroPy Results for esp8266: MicroPy esp8266-micropython-1.10.0 MicroPy esp8266-micropython-1.11.0 (Installed) MicroPy esp8266-micropython-1.9.3 MicroPy esp8266-micropython-1.9.4 MicroPy esp8266-pycopy-1.11.0 MicroPy esp8266-pycopy-2.11.0 MicroPy esp8266-pycopy-188.8.131.52 ~/Dev/micropy-cli via .env ➜ micropy init esp8266 MicroPy Creating New Project ? Choose any Templates to Generate (Use arrow keys to move, to select, to toggle, to invert) ● VSCode Settings for Autocompletion/Intellisense ○ Pymakr Configuration » ● Pylint Micropython Settings ○ main.py & boot.py files (next step) MicroPy Creating New Project ? Choose any Templates to Generate done (2 selections) ? Which stubs would you like to use? (Use arrow keys to move, to select, to toggle, to invert) » ● esp8266-micropython-1.11.0 (next step) MicroPy Creating New Project ? Choose any Templates to Generate done (2 selections) ? Which stubs would you like to use? [esp8266-micropython-1.11.0] MicroPy Initiating esp8266 MicroPy Stubs: esp8266-micropython-1.11.0 MicroPy Rendering Templates MicroPy Populating Stub info... MicroPy Vscode template generated! MicroPy Pylint template generated! MicroPy ✔ Stubs Injected! MicroPy ✔ Project Created! MicroPy Created esp8266 at ./esp8266
I moved all the project files to my new esp8266 directory, launched VSCode, open main.py and ...
Dev/micropy-cli/esp8266 via .env ➜ cp -r ../../micropython/chapter6/* . Dev/micropy-cli/esp8266 via .env ➜ code .
Expected, the linter is less permissive than with the defautl VSCode settings. But this can be easily fixed. And Voilà! Pylint is happy, and Intellisense is working with the stubs.