TL;DR: PlatformIO offers a complete toolchain, libraries, makefile and IDE integration
Making a new microcontroller work is hard. You need to get a feel for the surrounding community and the way the manufacturer imagined them to work. PlatformIO solves all those problems and more.
What you get is:
- the toolchain
- package management for libraries
- makefile
- integration into your IDE of choice
- tools necessary for upload
- over-the-air (OTA) update if possible
- support of frameworks like Arduino and mbed
You can use pip (Python Package Manager) for a fast platform-independent install. Yes, that means you can flash your ESP8266 from your smartphone or your Mac.
pip install -U platformio
Afterwards it’s ready to use. I’ll show you a quick walk through for a new ESP project.
platformio platform search esp
delivers this result:
espressif8266 ~ Espressif 8266 ============================== Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications. Home: http://platformio.org/platforms/espressif8266 Packages: tool-mkspiffs, tool-esptool, framework-arduinoespressif8266, toolchain-xtensa Version: 1.1.3
We can install it using
platformio platform install espressif8266
This will install the complete toolchain. Including the tools necessary for upload.
Afterwards you can create a new folder and initialize your first project:
platformio init --ide eclipse --board nodemcuv2
which gives you the following output:
The current working directory /var/tmp will be used for project. You can specify another project directory via `platformio init -d %PATH_TO_THE_PROJECT_DIR%` command. The next files/directories have been created in /var/tmp platformio.ini - Project Configuration File src - Put your source files here lib - Put here project specific (private) libraries Project has been successfully initialized! Useful commands: `platformio run` - process/build project from the current directory `platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board `platformio run --target clean` - clean project (remove compiled files) `platformio run --help` - additional information
In eclipse chose
File -> Import -> Existing Projects into Workspace. Leave the “copy project into workspace” unchecked.
Eclipse’s autocomplete feature works after you enable an index rebuild via
Project -> C/C++ Index -> Rebuild
That’s it. You have a basic project. And you can use all the fast, easy and ugly Arduino code instead of the stable, efficent and hard C/C++ code.
Let’s say you want to attach a display to your ESP8266. Search for the available OLED libraries with
platformio lib search oled
with the result
Found 143 libraries: [ ID ] Name Compatibility "Authors": Description --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [ 366 ] SparkFun Micro OLED Breakout arduino, atmelavr, atmelsam, espressif8266, intel_arc32, microchippic32, nordicnrf51, teensy, timsp430 "SparkFun Electronics": Library for the SparkFun Micro OLED Breakout [ 108 ] I2Cdevlib-SSD1308 arduino, atmelavr "Jeff Rowberg": SSD1308 is a single-chip CMOS OLED/PLED driver with controller for organic / polymer light emitting diode dot-matrix graphic display system [ 135 ] Adafruit SSD1306 arduino, atmelavr "Adafruit Industries": SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs [ 156 ] SSD1331 arduino, atmelavr "Watterott electronic": OLED-Display (SSD1331, SPI) [ 188 ] Adafruit_GFX mbed, freescalekinetis, nordicnrf51, nxplpc, ststm32, teensy "Neal Horman": A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C. [ 260 ] SparkFun_MicroView arduino, atmelavr "SparkFun Electronics": The MicroView is a chip-sized Arduino with a built-in OLED, available from SparkFun Electronics [ 262 ] Adafruit-SSD1331 arduino, atmelavr, espressif8266 "Adafruit Industries": This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip [ 312 ] SH1106 arduino, espressif8266 "Rene-Martin Tudyka": SH1106 Oled driver which offers scrolling frames, custom fonts, etc [ 562 ] ESP8266_SSD1306 arduino, espressif8266 "Daniel Eichhorn, Fabrice Weinberg": A I2C display driver for SSD1306 oled displays connected to an ESP8266 [ 732 ] FaBo 214 OLED EROLED096 arduino, atmelavr "FaBo, Hideki Yamauchi": A library for FaBo OLED I2C Brick Show next libraries? [y/N]:
Install your choice with
platformio lib install 156
Library Storage: /var/tmp/.piolibdeps LibraryManager: Installing id=156 Downloading [####################################] 100% Unpacking [####################################] 100% SSD1331 @ 227cf96d60 has been successfully installed! Installing dependencies Looking for digitalWriteFast library in registry Found: http://platformio.org/lib/show/142/digitalWriteFast LibraryManager: Installing id=142 Downloading [####################################] 100% Unpacking [####################################] 100% digitalWriteFast @ 227cf96d60 has been successfully installed! Looking for GraphicsLib library in registry Found: http://platformio.org/lib/show/146/GraphicsLib LibraryManager: Installing id=146 Downloading [####################################] 100% Unpacking [####################################] 100% GraphicsLib @ 227cf96d60 has been successfully installed! Installing dependencies Looking for digitalWriteFast library in registry Found: http://platformio.org/lib/show/142/digitalWriteFast LibraryManager: Installing id=142 digitalWriteFast @ 227cf96d60 is already installed
You can update all installed components using
platformio update && platformio upgrade
OTA update works using
platformio run -t upload --upload-port=<IP-OF-ESP-MODULE>
This makes starting a project so much easier. And I really like that it’s unnecessary to download libraries manually