Whenever I program an Arduino based project I would always use Sublime Text as my editor then compile and upload using the Arduino IDE. I prefer using Sublime Text as my Arduino Sketch editor as it gives more flexibility on color highlighting.
This post is a tutorial on how to use Sublime Text as an External Editor. It also answers the why, advantages and disadvantages of using External Editor.
In case you prefer to use Atom Text Editor or Visual Studio Code than Sublime Text then you may still do so by opening your code on Atom Text Editor.
- Using an External Editor without setting the Arduino IDE properly
- How to use an External Editor in Arduino IDE
Using an External Editor without setting the Arduino IDE properly
Before I show you on how to properly set the Arduino IDE to use an External Editor, let me show you first on what happens when you use an External Editor without doing the proper setup.
I opened the same .ino file on the Arduino IDE and on Sublime Text. Then I edited the one on Sublime Text.
Note: The code is a stripped down version of the Blink Code.
Then I edited the code on Sublime Text and saved it.
Then without editing or saving the code on the Arduino IDE I compiled the code.
The normal Blink code sketch would only use 928 bytes (2%) of program storage space. Therefore, the one compiled on the above experiment was the modified Blink code with 4 lines of additional code.
That is cool and all since you can modify your code on an External Editor and compile it on the Arduino IDE. But what if you forgot that you were using an External Editor and edited the code on the Arduino IDE instead? This actually happened to me and with a snap of a finger I said goodbye to 3 days worth of coding.
To avoid this we must set properly the Arduino IDE to use an External Editor. See the steps below.
How to use an External Editor in Arduino IDE
On your Arduino IDE go to File >> Preferences.
Inside the Preferences window find and check the Use external editor check box. Then press OK.
Once you have done the above instructions the Arduino IDE editor would then be colored grey. You can try editing the code on your Arduino IDE but the program would not allow you to do any changes.
I did the same experiment as the above.
I edited the code on Sublime Text and saved it.
When I clicked on anywhere in the Arduino IDE the code was updated to the new saved version.
With that I can make sure that what I compile on my Arduino IDE is the latest version of my Project Code without worrying that I would overwrite it whenever I forget that I am using a different editor.
Do you use an External Editor for your Arduino projects? What editor do you usually use? Tell me your answers on the comments below.
Very useful explanation.
As in many areas, the tools and options are all defined, but it’s hard to find a clear explanation (for a learner) of how to put them together.
(The same applies to many libraries)
I am using Notepad++ to edit sketches.
Regards
Peter A
Thanks for the feedback Peter. I’ll do my best to explain it in more detail on my next posts.
Does anyone know of a way for the Arduino IDE to open the external editor on the file of choice with just a button press or pop-up menu?
Hi Mike, sorry. I still do not know how to do that yet. Me will research but not promising anything.
Anybody here who already knows how to do this one?
Nice! Problem solved.
This works well for editing main programs and header files that are already in the Arduino library when you start the Arduino IDE. *However* if you add a new program or header file, you will have to exit and relaunch the Arduino IDE (for some bizarre reason, the Arduino IDE seems to read and store the directory tree)
Thank you for that information Cruzer57D! I did not know that. Will check.
I too agree that it would be a big advantage if the external editor completely replaced the Arduino one with its black on gray. Not only would that make reading the text much easier especially for old people who are half blind such as myself but also one would not have to switch back to the Arduino in order to compile and upload.
Hi Larry, I agree that reading code in Sublime Text is so much easier compared to doing it in the Arduino IDE.
By the way, the DevIOT that ShiroiAkuma recommended I think would help. I have not tested yet. Will test it in the next few days.
Nice post – thanks. I use Atom and arduino 1.8.8. I did not loose any code but then I closed the file in Atom first. Thanks so much as one day I will forget.
Hey Mike, I actually have not tested this on arduino 1.8.8 so with your comment I might test this in the very near future.
can we use visual code studio as external editor
Hi Sasi, yes. We can use Visual Studio Code as an external editor. In fact, I recently moved from Sublime Text to VSCode for coding my Arduino projects.
You can change the theme for Arduino. I have white lettering on black background for my old eyes. Look for “Arduino IDE themes” in Google. I also increased font size.
I use emacs, among many other things the automatic code indentation via TAB is perfectly solved there
Is there also with the new IDE 2.0 a possibility to fall back on an external editor, in the settings I could find nothing about it.
I like to use Geany. it works great!