Please, help me to set up Clion + Arduino.
Clion has an Arduino plugin which I've installed. Here is some instruction on Github but I'm fully noob about cmake
and other things which are talking about in instruction. I have only used Arduino IDE before for my simple projects. Now in CLion I can create an Arduino projects but autocompletion doesn't work. Actually it works but does it on true C, not for Arduino code.
So if you can please explain like for complete idiot, what I should change to get working Arduino autocompletion.
-
What do you mean by Arduino autocompletion?Avamander– Avamander2016年02月03日 20:53:36 +00:00Commented Feb 3, 2016 at 20:53
-
2look hereKvach– Kvach2016年02月03日 21:08:39 +00:00Commented Feb 3, 2016 at 21:08
-
It can't autocomplete what it doesn't know about. Have you installed all the libraries correctly according to what the plug in requires? (Try to compile the Blink example included with the Arduino IDE, do you get any errors?)Avamander– Avamander2016年02月03日 21:22:23 +00:00Commented Feb 3, 2016 at 21:22
-
If u explain how to do, I will do it.Kvach– Kvach2016年02月03日 21:43:33 +00:00Commented Feb 3, 2016 at 21:43
-
For anyone reading this now, Jetbrains has a very detailed blogpost on how to do thisMDMoore313– MDMoore3132021年07月27日 14:22:22 +00:00Commented Jul 27, 2021 at 14:22
2 Answers 2
Rather than using any plugin, I am using CLion with PlatformIO, which supports several IDEs. CLion then not only gives you code completion, but also full support for refactoring, Git, and much much more.
From its documentation:
[...] generate project via
platformio init --ide
command:platformio init --ide clion --board %TYPE% # For example, generate project for Arduino UNO platformio init --ide clion --board uno
Then import the project in CLion and you're about done.
Some hints:
Make sure your code is in the
src
folder, and that the main file has a.cpp
extension.For other files: either rename all
.ino
files to use.cpp
, or tell CLion to associate the.ino
extension with C++ files. (Preferences, Editors, File Types.)Whenever adding libraries to the
lib
folder (and using#include
to refer to them), just run the aboveinit
command again.If you're using ESP-boards and changed
platform.txt
for an alternativeesptool
, then note that PlatformIO needs a different hack.Rather than using the CLion Serial Monitor plugin, I simply use a Terminal within CLion to upload and start the monitor as soon as possible:
pio run -t upload; pio device monitor -b 115200
If you always want to upload and monitor whenever using
pio run
, then add:[env] targets = upload, monitor upload_protocol = esptool upload_speed = 115200 monitor_speed = 115200
Nowadays, CLion has a PlatformIO plugin as well, including a menu Tools, PlatformIO with commands such as Re-init.
-
thanks for your informative answer. it helped me quite a bit. just one thing: could you further elaborate on the last bullet point? how do you open custom terminals? does that command work on all platforms or just linux? thanks in advanceNeuron– Neuron2017年04月04日 11:10:10 +00:00Commented Apr 4, 2017 at 11:10
-
1@Neuron, in CLion on a Mac it's menu View, Tool Windows, Terminal. (On a Mac, the built-in bash shell is also called Terminal.) But there's no real difference with using a standalone terminal window, except for having all in one place, and it conveniently defaulting to the project's folder. As for the
pio
command: I only used it on a Mac, and it's exactly the same asplatformio
. (Both are installed when installing PlatformIO.)Arjan– Arjan2017年04月04日 17:07:54 +00:00Commented Apr 4, 2017 at 17:07 -
1Okey, it is
platformio device monitor
nowinvis– invis2019年12月16日 17:06:38 +00:00Commented Dec 16, 2019 at 17:06 -
1@invis, doesn't the 3rd bullet point work for you?Arjan– Arjan2019年12月16日 18:27:52 +00:00Commented Dec 16, 2019 at 18:27
-
1@Arjan hmm, actually
pio init
with argumets helps. Mylib
directory is empty, thats why I was confused.pio
adds dependencies to his own directory named.pio/libdeps
invis– invis2019年12月16日 18:51:27 +00:00Commented Dec 16, 2019 at 18:51
I know this was asked a long time ago, but maybe it will be useful for someone. I'm a beginner, regarding all this stuff, so if anybody knows a better way to do it, please correct me. here is how I set up CLion for Arduino (on Windows 10):
CLion 2016年1月3日 + Arduino 1.6.9 + plugin
Download and install the official Arduino IDE (1.6.9).
Download and install MinGW to 'C:\MinGW'
In MinGW, install: 'mingw32-base' and 'mingw32-gcc-g++'
Download and install CLion.
Create an 'untitled' project, just to open CLion.
In CLion> Settings> Plugins> Browse Repositories> Search for and install: 'Arduino' (tools integration), and 'Serial Monitor' (misc).
In CLion> Settings> Search> type 'MinGW'
At the environment select 'Use MinGW home', and browse to MinGW folder ('C:\MinGW'). Press apply, and wait until CLion finds the environment.
In File> Close project.
Open any file manager and go to 'c:\Users\name\ClionProjects\' and delete the 'untitled' project you just created.
Open CLion, select 'New Arduino sketch project'
In the project directory> 'open cmakelists.txt' and configure lines:
6: set board version 7: set port (you can find out port# from the Arduino IDE) 8: set the path where you installed your Arduino libraries (Arduino sketch folder) set(${CMAKE_PROJECT_NAME}_BOARD uno) set(${CMAKE_PROJECT_NAME}_PORT COM3) LINK_DIRECTORIES(c:\\ARDUINO\\libraries)
In the upper right corner in CLion, near the green 'Play' button, select 'Edit Configuration', on the left select 'Application'> 'Upload', and set:
-target: 'upload' -configuration: 'debug' -executable: the project name
then press ok.
In the project .ino file, write some really simple code (blink).
Connect an Arduino Uno via USB, and press the green 'play' button to upload the sketch.
To start serial monitor:
- In CLion main window bottom left, click serial monitor tab (in 'the tool buttons')
- Click the wrench icon to set up port and baud rate.
- On the top of the wrench icon, click the blue 'connect' icon.
- If values did not appear 'correctly', click the white 'switch to hex' icon (on the right of the wrench).
- Before uploading sketch, disconnect the serial monitor.
For CLion to properly find the libraries, make sure to use the same name for the lib folder as for the '.h' file. example: for DallasTemperature.h use folder name DallasTemperature. After #inlcude-ing new libs, right click on 'External libraries folder' and select 'Reload cmake project'.
You may want to do further configuration in CLion settings like: theme, colours, text size, etc.
Also, you can configure some handy 'live templates', like:
serialprintln
,digitalwrite
,pinmode
,switch
, etc. to enhance your productivity.
-
1It
s very nice tutorial dude, thx very much but unfortunately I
m using linux (. Instead of mingw what should I install?Kvach– Kvach2016年09月30日 22:13:29 +00:00Commented Sep 30, 2016 at 22:13 -
sorry, i don't use linux, have no idea about it.Wanek T– Wanek T2016年11月01日 09:48:17 +00:00Commented Nov 1, 2016 at 9:48
-
@Kvach you will need to install
cmake
,gcc
,git
.zoonman– zoonman2018年10月25日 19:16:20 +00:00Commented Oct 25, 2018 at 19:16 -
Thank you! This is the best way to do it for windowstcallred– tcallred2018年11月17日 23:35:54 +00:00Commented Nov 17, 2018 at 23:35
-
There is no such a plugin
Arduino
in Clion Plugins Marketplace. Pribably it's been depricated.zhekaus– zhekaus2025年02月11日 14:43:57 +00:00Commented Feb 11 at 14:43