Visual Studio Code
For advanced developers and more complex projects it can be interesting to have an advanced IDE with GIT control, code completion, and a bunch of useful extensions to streamline the development process. For this purpose, it is possible to combine two powerful tools: Visual Studio Code, and PlatformIO.

Install Visual Studio Code

Visual Studio Code is a free distribution source-code editor developed by Microsoft for Windows, Linux and macOS. It can be extended via extensions, available through a central repository to add language support, new programming languages, themes, and debuggers, or perform static code analysis. It can be downloaded for free from the official website.

Install PlatformIO

PlatformIO is a cross-platform, cross-architecture, multiple framework, professional tool for embedded systems engineers and for software developers who write applications for embedded products. PlatformIO can be installed as a Visual Studio extension. To install the extension, just navigate to Extensions in Visual Studio Code (Ctrl + Shift + X on Windows or Command + Shift + X on Mac) in VS Code. Then, search forPlatformIO, click on PlatformIO IDE result, and click on Install button.

Starting a Project

Once Visual Studio code with PlatformIO is installed, it is possible to create a new project for our specific board. For this purpose, we can access PIO Home, and click on the New Project button:
Create a new Project from PIO Home.
For this example, we will be using the ESP32 board, so, in the Project Wizard pop-up we enter a Project Name, select the Espressif ESP32 Dev Module, as a generic ESP32 board, and the Arduino Framework. Once done, click on Finish and wait PlatformIO to download the required toolchains for the device.
PlatformIO project Wizard
After the project initialization is done, PlatformIO generates a file structure like the following:
PlatformIO default project structure
As shown in the above picture, each PlatformIO project has a configuration file named platformio.ini in the root directory for the project. This is a INI-stylefile.
platformio.ini has sections (each denoted by a [header]) and key / value pairs within the sections. Lines beginning with ;are ignored and may be used to provide comments.
In our default ESP32 project looks like the following:
1
[env:esp32dev]
2
platform = espressif32
3
board = esp32dev
4
framework = arduino
Copied!
Now, to start working with Thinger.io, it is required to add the Thinger.io client library using the lib_deps property:
1
[env:esp32dev]
2
platform = espressif32
3
board = esp32dev
4
framework = arduino
5
lib_deps = thinger.io
Copied!
After this configuration is done, it is possible to start compiling for our device. A basic example for our ESP32 device will look like the following:
main.cpp
arduino_secrets.h
1
#define THINGER_SERIAL_DEBUG
2
3
#include <ThingerESP32.h>
4
#include "arduino_secrets.h"
5
6
ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
7
8
void setup() {
9
// open serial for debugging
10
Serial.begin(115200);
11
12
pinMode(16, OUTPUT);
13
14
thing.add_wifi(SSID, SSID_PASSWORD);
15
16
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
17
thing["GPIO_16"] << digitalPin(16);
18
19
// resource output example (i.e. reading a sensor value)
20
thing["millis"] >> outputValue(millis());
21
22
// more details at http://docs.thinger.io/arduino/
23
}
24
25
void loop() {
26
thing.handle();
27
}
Copied!
1
#define USERNAME "your_user_name"
2
#define DEVICE_ID "your_device_id"
3
#define DEVICE_CREDENTIAL "your_device_credential"
4
5
#define SSID "your_wifi_ssid"
6
#define SSID_PASSWORD "your_wifi_ssid_password"
Copied!
Last modified 2mo ago