Introduction: Setup JetBrains Clion for Arduino Development

Picture of Setup JetBrains Clion for Arduino Development

Hi my name is adam, I love to work with Arduino for my hobby projects, but I find that Arduino IDE not very attractive and helpful tool. This days programmers have a lot of IDEs which do auto-complete, auto-formating code, show you mistakes and best practice before you push compile and run button. I work with Jet Brains IDES in my opinion they are the best and they can give you license free for open source projects. But if you wanna use it for programming arduino you have to done a little setup. In next steps I will show you all need to know for successfully install IDE and upload code to Arduino.

Advantages of Clion Arduino IDE:

  1. Auto-complete code
  2. Code formatter
  3. Intelligent refactoring tools
  4. Controlling code for mistakes and best practice without compiling and uploading
  5. Version control (Git, SVN, etc.)

Ps: I will use linux ubuntu mate, but it will works on windows Os to.

Step 1: 1. Download and Install Clion

Download Clion from

this website https://www.jetbrains.com/clion/download/#section=linux-version

Step 2: 2. Install Plug-gin for Arduino and Serial Port Monitor

Picture of 2. Install Plug-gin for Arduino and Serial Port  Monitor

Open Clion and go to Configure/Settings/Pluggins. Choose 'Browse Repositories' and click install, then restart Clion.

For https://plugins.jetbrains.com/plugin/8031?pr= use same approach as for Arduino plugin.

Step 3: 3. Do Little Setup for Arduino Board

Picture of 3. Do Little Setup for Arduino Board

After you installed

the plugin, you will see in Welcom window New Arduino Project click and start new arduino project.

PS: I like Dracula color theme in Clion, you can switch to it in File/Settings/Appearance & Behavior/Appearance switch Theme to Dracula.

In project you have
to most important files One “.ino” where is your code for Arduino, and the second which is named CMakeLists.txt where we need to do a little configuration. At line 6 you setup

what type of Arduino you are using (for my setup is “uno”). And at line 7 you setup port where is

Arduino connected to computer. Thats it for setup :)

Step 4: 4. Upload and Run Code

Picture of 4. Upload and Run Code

And for the last step you have to upload sketch to Arduino.

#include
void setup() {
pinMode(13,OUTPUT); Serial.begin(9600); }
void loop() {
Serial.println("Hi");
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW); delay(1000);
}

This is the code just make LED blink and write to serial monitor Hi. On the top right corner of IDE you have to push Play button and choose executable file where is your sketch. Than upload code to Arduino. Click on Serial Monitor on the bottom of window setup port and push button upper option button in Serial Monitor window. I you done everything correctly you will see “Hi” message every 2 seconds and blink LED on arduino.

This
is the code just make LED blink and write to serial monitor Hi. On the top right corner of IDE you have to push Play button and choose executable file where is your sketch. Than upload code to Arduino. Click on Serial Monitor on the bottom of window setup port and push button upper option button in Serial Monitor window. I you done everything correctly you will see “Hi” message every 2 seconds and blink LED on arduino.

Sorry for my English :)

Comments

WanekT (author)2016-06-29

hello!

i have followed this instructables exactly, but when i press the green 'play' button, i got the following error message:

"C:\Program Files (x86)\JetBrains\CLion 2016.1.3\bin\cmake\bin\cmake.exe" --build C:\Users\wanek\.CLion2016.1\system\cmake\generated\uno-931e5b88\931e5b88\Debug --target upload -- -j 4

[ 89%] Built target uno_CORE

[100%] Built target uno

avrdude.exe: ser_open(): can't open device "/dev/ttyUSB0": The system cannot find the path specified.

avrdude.exe done. Thank you.

mingw32-make.exe[3]: *** [CMakeFiles/uno-upload] Error 1

CMakeFiles\uno-upload.dir\build.make:56: recipe for target 'CMakeFiles/uno-upload' failed

CMakeFiles\Makefile2:172: recipe for target 'CMakeFiles/uno-upload.dir/all' failed

CMakeFiles\Makefile2:211: recipe for target 'CMakeFiles/upload.dir/rule' failed

mingw32-make.exe[2]: *** [CMakeFiles/uno-upload.dir/all] Error 2

mingw32-make.exe[1]: *** [CMakeFiles/upload.dir/rule] Error 2

mingw32-make.exe: *** [upload] Error 2

Makefile:169: recipe for target 'upload' failed

============================================================

i guess the problem is with the "/dev/ttyUSB0" parameter in the cmakelists.txt file.

this is what i have in the cmakelists.txt:

cmake_minimum_required(VERSION 2.8.4)set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)set(PROJECT_NAME uno)project(${PROJECT_NAME})set(${CMAKE_PROJECT_NAME}_BOARD uno)set(${CMAKE_PROJECT_NAME}_PORT /dev/ttyUSB0)set(${CMAKE_PROJECT_NAME}_SKETCH uno.ino)generate_arduino_firmware(${CMAKE_PROJECT_NAME})

============================================================

i would greatly appreciate some help.

thanks!

AdamL92 (author)WanekT2016-06-29

Hi I will try to install on Windows asap, but now just try this, in windows you dont have

/dev/ttyUSB0 but try one of this

private static final String PORT_NAMES[] = {


"/dev/tty.usbserial-A9007UX1", // Mac OS X


"/dev/ttyACM0", // Raspberry Pi

"/dev/ttyUSB0", // Linux


"COM3", // Windows
};

WanekT (author)AdamL922016-07-05

hello!

thank you for the answer. indeed, the 'com3' works with windows 10. now i can upload simple sketches.

however, i have one more question: what should i set up in clion, to recognise the arduino libraries? they are marked with red in the ide, and it says: can not find 'wire.h'. when i try to upload a sketch with some libs, at compilation says:

"C:\Program Files (x86)\JetBrains\CLion 2016.1.3\bin\cmake\bin\cmake.exe" --build C:\Users\wanek\.CLion2016.1\system\cmake\generated\UNO-931ddf68\931ddf68\Debug --target upload -- -j 4

[ 86%] Built target uno_CORE

[ 89%] Built target uno_EEPROM

Scanning dependencies of target UNO

[ 93%] Building CXX object CMakeFiles/UNO.dir/UNO_UNO.ino.cpp.obj

C:/Users/wanek/ClionProjects/UNO/UNO.ino:53:63: fatal error: SPI.h: No such file or directory

#include <SPI.h> //for digipot serial interface

^

compilation terminated.

mingw32-make.exe[3]: *** [CMakeFiles/UNO.dir/UNO_UNO.ino.cpp.obj] Error 1

mingw32-make.exe[2]: *** [CMakeFiles/UNO.dir/all] Error 2

mingw32-make.exe[1]: *** [CMakeFiles/upload.dir/rule] Error 2

CMakeFiles\UNO.dir\build.make:65: recipe for target 'CMakeFiles/UNO.dir/UNO_UNO.ino.cpp.obj' failed

CMakeFiles\Makefile2:99: recipe for target 'CMakeFiles/UNO.dir/all' failed

CMakeFiles\Makefile2:249: recipe for target 'CMakeFiles/upload.dir/rule' failed

Makefile:182: recipe for target 'upload' failed

mingw32-make.exe: *** [upload] Error 2

thanks again for help!

AdamL92 (author)WanekT2016-07-05

Hi ok fast solution in Clion je have in file tree on left site External libraries open it and you will see folders Arduino library, include library, .... find one where is inside folder with EEPROM, ESplora, ..... a check where they are in disk on that place just copy library you want a refresh Clion you will able to #include new library with autocomplete

WanekT (author)AdamL922016-07-05

unfortunately this is not working for me.

i've found the esplora lib located in c:\Program Files (x86)\Arduino\libraries\.

i've moved all my libs into this folder, restarted the ide, etc. clion lists them, but they are not active. i permanently got the: 'some source files are located outside of cmakelists.txt directory. you can change the project root, or ignore this in future' warning (you can see in the attached image).

iGyver (author)WanekT2016-11-13

Hi Wanek, I don't understand the answer of Adam. Do you solved that library at CLion issue now?

WanekT (author)iGyver2016-11-13

hi!

partially i've solved the problem, but there were some libs i could not import, no matter what i try. i wrote a detailed tutorial here: http://arduino.stackexchange.com/questions/20294/c...

however, this was a long time ago, since then clion has new versions, and other problems arise. so, i abandoned this approach, and continued to use the original arduino ide.

AdamL92 (author)WanekT2016-11-29

Hi I give up on that clion plugin, but I dont want use arduio ide ... so I try platformio for uploading code and dependencies managment and for coding I use clion, platformio generate clion project for you, I will post video how to do it but in the end I have fully working auto-complete code ad connection between libraries, so you can jump where you want and use InteliJ features but need some time to make video but stay calm :)

TheThinker (author)2016-05-06

Very useful!

tomatoskins (author)2016-05-06

Your English is great! Welcome to instructables!

About This Instructable

14,639views

26favorites

Bio: My name is Adam Luptak I creatively enthusiast for software development and everything related to information technologies. On the other hand, I am musician guitarist ... More »
Add instructable to: