As an almost everyday Android Studio user for past 2 years I feel like my whole programming effectiveness and efficiency became kind of ‘tightly coupled’ with IntelliJ’s IDE product family. Probably that’s why, when my new Arduino Yún finally arrived, the first thing on my to-do list was configuring a CLion template project. Most of IDE plugins and other minor solutions seemed not to be working, and that’s when I’ve found out about…



PlatformIO

In short words, it provides a very elegant, simple mechanism to generate all the code needed by CLion (and many other IDE’s) to get the thing going. My Yún model turned out to be the problematic, temporarily not working marginal case. That gave me an opportunity to get to know Ivan, the creator of PlatformIO himself (cheers!). Watching Ivan fast fixing these PlatformIO Python scripts on my computer through TeamViewer was an interesting experience :). Anyway, you can surely count on solid support here.

To the point

Assuming that you’ve already got the CLion and Python 2.6+ you can start installation of PlatformIO with below super-quick command:

python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"

Now you need to generate the code in reference to PlatformIO’s get started section, in my case it’s:

mkdir YunMe cd YunMe platformio init --board=yun --ide=clion

Open CLion and import YunMe project. Create a new file in /src directory:

#include "Arduino.h" // Most Arduino boards already have a LED attached to pin 13 on the board itself #define LED_PIN 13 void setup() { pinMode(LED_PIN, OUTPUT); // set pin as output } void loop() { digitalWrite(LED_PIN, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(LED_PIN, LOW); // set the LED off delay(1000); // wait for a second }

Build the project [Run->Build] (⌘F9) to test it out. You can also use below CLI command:

platformio run -t upload

Your Arduino should start blinking now. 🙂

Auto-completion & syntax highlighting

Open CMakeLists.txt file in root directory and modify it like below:

# # To enable code auto-completion, please specify path # to main source file (*.c, *.cpp) and uncomment line below # add_executable(YunMe src/blink.cpp)

Just in case…

If you’ve encountered an ‘Please specify ‘upload_port’ (…)’ error message, you need to manually find out your Arduino’s upload port and add it to configuration. Make sure it’s plugged with USB and execute:

ls /dev/cu.*

Edit platformio.ini and add proper upload_port configuration line:

# Project Configuration File # # A detailed documentation with the EXAMPLES is located here: # http://docs.platformio.org/en/latest/projectconf.html # # A sign `#` at the beginning of the line indicates a comment # Comment lines are ignored. # Simple and base environment # [env:mybaseenv] # platform = %INSTALLED_PLATFORM_NAME_HERE% # framework = # board = # # Automatic targets - enable auto-uploading # targets = upload [env:yun] platform = atmelavr framework = arduino board = yun targets = upload upload_port = /dev/cu.usbmodem1421

Other useful commands

sudo easy_install pip

pip show platformio

pip install -U pip setuptools

pip install -U platformio