A first program with ESP8266/ESP-01, CLion and PlatformIO

When using the ESP8266 you also meet the ESP-01 and his CH340G adapter. You can buy both at aliexpress.

esp-01 esp-01_programmer_ch340g

The Arduino IDE does not support coding with autocomplete, so I decided to use CLion. First you have to download an install CLion. (Don’t forget – CLion is not free)

Now install the Arduino and SerialPorts plugins:

CLion_Arduino_plugin

Clion_SerialPort_plugin

Next you have to install PlatformIO. Because of working on a MacBook, I used Homebrew.

Next ist to install the Serial-to-USB Driver for the CH340.

So, now the preparations are finished. Let’s start to create an new project.

mkdir Blink
cd Blink
platformio init --ide clion --board esp01

To know, which board to use, you can use

platformio boards

or

platformio boards espressif8266

So, now we check, if the connection to the ESP8266 is working:

Plug in the ESP8266 and the programmer, but don’t bridge anything with a wire. Choose the port and the baud rate.

CLion_SerialPort_Config

Now you can use the AT-commands for testing the communication.

AT

AT+GMR

CLion_SerialPort_AT

Now open the project in CLion and create a source file. Pay attention, that the file ends with .cpp and write a small program like listed below. Don’t forget to #include "Arduino.h"

CLion_Arduino_Autocomplete

Wire the programmer like shown below

esp-01_programmer_wired esp-01_programmer_wired3

Connect it to the USP-port (maybe use a usb-hub for safety)
This small program comes from the examples in the Arduino-IDE (in the ESP8266-section):

#include "Arduino.h"
void setup() {
pinMode(BUILTIN_LED, OUTPUT);
}
void loop() {
digitalWrite(BUILTIN_LED, LOW);
delay(1000);
digitalWrite(BUILTIN_LED, HIGH);
delay(2000);
}

Now compile and upload the program:

CLion_Terminal

For compiling and uploading you can also use the build-button CLion_build_button, but never the run-button CLion_run_button.

When you want to upload again, you have to plug of and plug in again (?).

Sources:

http://www.instructables.com/id/Getting-Started-With-the-ESP8266-ESP-01/

https://www.xgadget.de/anleitung/esp-01-esp8266-mit-adapter-programmieren-so-gehts/

http://www.ches.pl/using-platformio-get-started-arduino-clion-ide/

Advertisements
This entry was posted in IoT and tagged , , , . Bookmark the permalink.

2 Responses to A first program with ESP8266/ESP-01, CLion and PlatformIO

  1. Simon Ludwig says:

    Thank you so much!! Blogger like you are my rescue!

  2. kiraleouf says:

    Thanks for the tutorial,
    I was not able to use ESP on MacOS easily but with Clion and platform.io it works fine and it’s very nice to have the power of jetbrain IDE for iot dev 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s