Esp8266 Visual Studio Code



So now I have used the official Arduino IDE for some time to program the ESP8266. It is a convenient and quick-to-get-started method (check here). But recently I plan to write an application that I feel it would be uncomfortable to write codes using the limited features of Arduino IDE. I find particularly two feature-rich IDEs out there, which are free and highly recommended by communities, namely Atom and Visual Studio Code. With Atom, we need to add the PlatformIO extension for programming embedded systems, including the ESP8266. While with VS Code, we need to install either PlatformIO or Arduino extension.

Micropython Esp8266 Visual Studio Code

The ESP8266 is a low-cost Wi-Fi microchip, with a full TCP/IP stack and microcontroller capability, produced by Espressif Systems in Shanghai, China. The chip first came to the attention of Western makers in August 2014 with the ESP-01 module, made by a third-party manufacturer Ai-Thinker. This small module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP. The ESP8266 core for Arduino or ESP32 core for Ardiuno needs to be installed on your computer. For the ESP8266, it is best to use the Arduino IDE 's Board Manager (Tools/Board/Board Manager.) or use the Arduino for Visual Studio Code 's Arduino: Board Manager command. Visual Studio Code、clion、sublime、source insight等等均可以,但是我个人还是推荐用神器Visual Studio Code,理由你懂得 😄 其实, ESP8266开发环境现状 中所说的 1 & 2 & 3 就是基于上面所说的方法展开的,以下是我摸索出来的方法.

Esp8266

I had difficulties to get both Atom-PlatformIO and VS Code-PlatformIO working. Somehow the PlatformIO installation was not able to complete. I suspected it was caused by my office internet proxy. I spent quite some time to solve it but did not succeed, so I abandoned it and tried the Arduino extension.

Getting the VS Code with Arduino extension working was not that straight forward either. If you search for the Arduino extension, you will find two choices, either developed by Microsoft or Steve Yin. Initially I chose the one developed by Microsoft. Well, Arduino extension is just an extension that allows users to tell the VS Code where the tools for compiling and uploading code reside. So we must have the official Arduino IDE installed because its tools for compiling and uploading will be used by the VS Code. Then we need to specify the Arduino IDE path in the VS Code ‘User Settings’. Btw, my OS was Windows 8,and I installed the official Arduino IDE version 1.8.2. For unknown reasons compiling sketch using VS Code was always fail with a message saying ‘[Error] Exit with code=undefined’. Actually, I also had an Ubuntu machine, and I managed to get the Arduino extension working. I could compile and upload codes to the ESP8266. But for some reasons, I still preferred to work on my Windows 8 machine.

Visual

So, then I gave the Steve Yin’s Arduino extension a try on my Win 8. The compile and upload options in User Settings were more complicated than those of Microsoft one. But happily I succeeded to compile and write bits of codes to the ESP8266 flash memory. The easiest way to specify the compile and upload options is by adapting them from the command list spat out from the Arduino IDE console output. Again, you can follow this instruction to program ESP8266 using Arduino IDE.

Here is my VS Code ‘User Settings’:

In the “arduino.compileOptions” I omitted the built-path and built-cache options since they caused compiling to fail. The Arduino extension had its own built-cache which worked fine. I had not looked further for the meaning of the other options. They might be fine to be deleted. However they seems didn’t do any harm, by now I just leave it there.
In the “arduino.uploadOptions” we could set the COM port and upload speed. By default, the upload speed is 115200, which was quite slow. I found it somewhere that says we can increase the speed by a factor of 8, so it becomes 921600. It was indeed much faster. But the reference I read also says that this high speed can sometimes be unstable. So, bear this in mind. I did try other higher baud rates: 1500000, 1843200, 2000000. However the uploading time took longer than that of 921600.
Initially I thought installing these tools for programming ESP8266 would be just some clicks away. But in fact I had spent a lot of time to get it done properly. I hope you have a nice and smooth installation. In case you face the same problem, hope my experience would help.

Visual Studio Platformio Esp8266

Happy coding!