2015/04/26

A better Arduino IDE - Notepad++

Arduino IDE 1.6x has improved a lot over past few versions, such as adding line number, bug fixes, and many other features. However, Arudino IDE still has many miles to go to become a friendly editor for programmers. Syntax highlighting and programming language reference are programmer favorite features. However, they are not that fancy yet on the latest version of Arduino IDE V1.6.3.

I've been using Notepad++ (N++) for a while and Notepad++ is one of the most famous programming tools available for free!! Recently, I found josephdouce’s contribution on SourceForge that Joseph developed a N++ plugin for Arduino. Although it’s still in prealpha stage, it looks promising!

I would like to show you how to add N++ Arduino plugin into Notepad++ and use it as your editor.

Download Files:

  1. Download latest Notepad++ By Don Ho
    • You many select Installer, zip package, or 7z package
  2. Download latest Arduino IDE by Arduino.cc
    • Select Installer or zip package if you don't have admin access right
  3. Download N++ Arduino Plugin by josephdouce

Installation:

  1. Install Arduino by unzip the “Arduino-1.6.3-windows.zip” into your preferred folder or directly install it if you downloaded the Installer
  2. Install Notepad++ by unzip the download "npp.6.7.7.bin.zip" file into your preferred folder or directly install it if you downloaded the Installer
  3. Unzip N++ Arduino plugin zip files into an empty directory
Detailed N++ Arduino Plugin Settings:
  • First, let's import Arduino_Language_0.2.0.xml
    Start Notepadd++ application and click "Language", "Define your language..."
  • You should see "User Defined Language" window popup. Click on "Import..." and select the Arduino_Language_0.2.0.xml file  (This should be in the unzipped N++ Arduino plugin directory).  You will see import successfully message, then you may close this window.



  • Copy API files to Notepad++ plugins\APIs directory (This is where you installed the Notepad++).
    In my computer, it is in c:\Program Files\Notepad++\APIs\


  • In Notepad++, Click Preference



  • Click "Auto Completion" on the left (blue background) and then tick both "Enable auto-completion on each input" and "Function parameters hint on input", then close this window. (circled below)


How to use Arduino N++ Plugin:

When you start Notepad++ application, remember to click "Lanauages" then click on "Arduino". That's it! As you can see, as soon as you type, Notepad++ looks for variables or keywords from the XML file and show relevant candidates in a popup menu. As a programmer, it is a lot easier to just pick one up from the list. Isn't it?! ;)

Example:
A) I defined a variable called CheckStatus
B) As soon as I typed Check...
C) A list of suggested variable/command starting with letter C is listed in the box for you to pick up!

See below, Arduino language reference showing up automatically as you type!
This is really helpful!


Big thanks to these software contributors!!

How to invoke Arduino IDE for compiling and uploading to Arduino boards:
Quite few people was asking me if it's possible to compile code inside Notepad++. After few tries, I think it's impossible for now.  However, you may activate Arduino IDE inside Notepad++ with keystrokes you defined.

In Notepad++, Click "Run.."





You will see a popup window showed up. See illustration (A) below.
Click the 3 little dot button after the drop-down box and then select your Arduino executable file arduino.exe and then type "$(FULL_CURRENT_PATH)" right after the arduino.exe file. Double quotations are needed to make this work.

Here is mine for your reference:
"F:\arduino\arduino.exe" "$(FULL_CURRENT_PATH)"











Then Click "Save..." to assign a shortcut key. You will see another popup window(B). Tick the combination of CTRL, SHIFT, or ALT keys you like and pickup another key from the drop-down box. In my setup, I named it "Arduino" and selected CTRL + SHIFT + F5. From now on, I just need to hit the combination keys to invoke Arduino and bring the latest codes into Arduino IDE for compiling.

Hit CTRL + SHIFT + F5 you will see Arduino IDE invoking screen....


















See below, codes in Notepad++ are identical as those in Arduino IDE.











PS: One problem though.... Each time you hit the combination keys, one instance of Arduino IDE will start and reside in the PC..... I don't have solution for this yet!

Thanks author Sriram Iyer for this tip: Using-notepad-plus-plus-instead-of-the-arduino-ide

End
================================================================

一套比 Arduino IDE 更好用的編輯器 - Notepad++ / Arduino N++ Plugin


Arduino 編輯器 V1.6x 雖然改進了不少,但是對寫程式的來說還是沒那麼好用。

Notepad++ 是一套很有名的文字編輯軟體。我自己曾使用 Notepad++ 寫 PHP,覺得它真的很好用。最近看到 SourceForge 上, 有位高手(josephdouce)寫了一套 N++ plugin for Arduino,雖然它只是 Prealpha 版本,但它已可以讓使用者在 Notepad++ 裡寫 Arduino,不但提供 Syntax highlight,變數及指令的提示, 也會給顯示語法使用方法及參數的提示,看來蠻有潛力的!

需下載的檔案:

  1. 由此下載最新版的 Notepad++ By Don Ho
    • 你可選擇要安裝版(Installer)或是壓縮檔(.zip or 7zip)再自行解壓縮也行
  2. 由此下載最新版的 Arduino IDE by Arduino.cc
    • 你可選擇要安裝版(Installer)或是壓縮檔(.zip or 7zip)再自行解壓縮也行
  3. 由此下載  N++ Arduino Plugin by josephdouce

安裝方法:

  1. Arduino: 選擇壓縮檔者,只要把 “Arduino-1.6.3-windows.zip” 解壓縮到你想要執行的目錄即可。 選擇安裝檔者,就按步驟執行即可。
  2. Notepad++: 選擇壓縮檔者,只要把 “npp.6.7.7.bin.zip” 解壓縮到你想要執行的目錄即可。 選擇安裝檔者,就按步驟執行即可。
  3. N++ Arduino plugin: 解壓縮 "Notepad++.Arduino.0.2.0.zip" 到自己想放的目錄即可。
N++ Arduino Plugin 安裝與設定:
  • 匯入 Arduino_Language_0.2.0.xml 設定檔
    開啟 Notepadd++ 然後點選 "Language/程式語言", "Define your language.../定義程式語言" 如下圖:
  • "User Defined Language/自訂程式語言" 視窗會跳出來。點選 "Import.../匯入"(見下圖) 然後由視窗裡點選 Arduino_Language_0.2.0.xml 檔案。 (這個檔案就是你剛剛解壓縮N++ Arduino plugin的目錄)。  如果匯入完成,你會看到完成的提示視窗。



  • 從N++ Arduino plugin解壓的目錄裡,把 API  "Arduinolbs" 目錄夾 整個 copy 到 Notepad++ plugins\API 目錄底下 ( Notepad++ 執行檔安裝位置裡有一個 \plugins\APIs 的目錄)  在我自己的電腦,Notepad++ 是安裝在 c:\Program Files\Notepad++\APIs\ 底下


  • 在回到 Notepad++, 點選 "Preference/自訂"



  • 從左邊點選 "Auto Completion/自動完成功能"  然後把 "Enable auto-completion on each input/啟動自動完成功能" 和 "Function parameters hint on input/自動顯示功能參數提示", 打勾 ,關掉視窗即設定完成。 參考下圖:

Arduino N++ plugin for Notepad++ 使用方法:

只要安裝成功,使用方法非常簡單! 打開 Notepad++, 在程式語言的清單裡選擇 Arduino 即可!
往後只要你一邊打字, N++ plugin 會把相關的指令或是你使用過的變數在一 個小視窗上列出來。這樣一來,你可以挑想用的變數或是指令, 降低變數/指令使用出錯率。

例如:
A) 我定義了 CheckStatus 變數
B) 只要我在 Notepad++ 裡打了 Check
C) 所有指令或是變數是由 C 開頭的都會顯示在小視窗裡,CheckStatus 就在最底下,如下圖:

Arduino 指令使用方法及參數也會自動顯示出來了! 對新手來說, 這樣可以減少查閱指令的使用方法,是不是太方便了!


如何在 Notepad++ 裡呼叫 Arduino IDE 來編譯及上傳到Arduino上:

有不少人問我,能不能在Notepad++ 裡直接呼叫 Arduino IDE 來編譯及上傳。找了網上的一些資料,發現目前還沒有方法可以做的到。不過,你可以自行定義快速鍵來呼叫 Arduino IDE 並且把正在編輯的程式碼直接傳到 Arduino IDE 裡。

在 Notepad++ 裡, 點選 "Run.."





你會看到一個 Run... 的視窗跳出來如下圖(A)
點一下有3個小點的鈕,然後選取你的 Arduino 的執行檔,再加上左右側的雙引號在路徑的前後,空一格,再加上 "$(FULL_CURRENT_PATH)" 

在我的PC上,它看起來應該像這樣:( 引號有四個,都要打上去才行)
"F:\arduino\arduino.exe" "$(FULL_CURRENT_PATH)"










按下 "Save.../存檔" 然後你會看到視窗(B) 自行定義快速鍵,把你想要指定的快速鍵打勾,再從下拉選單裡,選一個自己喜歡的組合,然後在 Name: 那裡自己取一個檔名來儲存。我自己取為 Arduino 並選取了 CTRL + SHIFT + F5. 按 OK, 關掉視窗。

往後我只要按下  CTRL + SHIFT + F5 在 Notepad++ 裡,即可直接呼叫 Arduino IDE 來編譯及上傳。


按下CTRL + SHIFT + F5 鈕後,會看到這個畫面表示 Arduino IDE 開始啟動:





















右側視窗的 Notepad++ 呼叫 Arduino IDE, 你可以看到左側是 Arduino IDE 裡的程式碼和右側
Notepad++ 裡的程式已經同步。














PS: 有一點小小的問題.... 每次你呼叫一次 Arduino IDE,它的程式就會長註一個在電腦裡。我還不知道有沒有解法!

謝謝網友 Sriram Iyer 網誌裡提供在 Notepad++ 裡呼叫 Arduion IDE 的方法: Using-notepad-plus-plus-instead-of-the-arduino-ide


結束



15 comments:

  1. Thank you very much as I love using NotePad++ and this will be a valuable addition.

    NOTE: the path to copy the .xml file in my machine was:
    C:\Program Files (x86)\Notepad++\plugins\APIs

    NOT

    C:\Program Files (x86)\Notepad++\APIs

    ReplyDelete
    Replies
    1. Thanks for pointed that out. For newer PC with Windows newer version, the path you provided is correct!!

      However, believe it or not, I am still using Windows 7! So, my path is actually c:\Program Files\Notepad++\APIs\

      Please remember to setup the path correctly or it would not work.

      Delete
  2. Quite few people was asking me if it's possible to compile code inside Notepad++. After few tries, I think it's impossible for now.

    POSSIBLE!
    http://habrahabr.ru/post/236213/
    use plugin NppExec

    ReplyDelete
  3. https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc

    OPEN -
    "C:\Program Files (x86)\Arduino\arduino.exe" "$(FULL_CURRENT_PATH)

    UPLOAD
    "C:\Program Files (x86)\Arduino\arduino.exe" --upload "$(FULL_CURRENT_PATH)

    VERIFY
    "C:\Program Files (x86)\Arduino\arduino.exe" --verify "$(FULL_CURRENT_PATH)"

    ReplyDelete
    Replies
    1. Hi BobiBobObana, thanks for the information! I will give a try soon.

      Delete
  4. Nice. May try this out later. The problem with a new instance of the IDE can be easily fixed with a batch running in the background checking for specific processes. Add a timer to it, gives the IDE a chance to compile + upload and afterwards closing the instance(s).

    ReplyDelete
    Replies
    1. Wow...maybe you can write a tutorial about your method. It's really advanced for me. :)

      Delete
  5. 你好,很感謝你提供的訊息,我有兩個小問題想請教
    1.如果npp的theme是選擇深色背景,套用這個arduino的plugin後,顯示的效果會變成只有文字部份背景變白色,這是這個plugin的關係嗎?
    2.當我輸入arduino的default指令時,並沒有自動跳出相關的語法,這是因為這個plugin搭配的Arduino IDE 需要用安裝的方式嗎?因為我的Arduino IDE是直接解開zip檔就使用了

    ReplyDelete
  6. Replies
    1. Thanks for the information!

      Delete
  7. When using Arduino language library option: „FUNCTION LIST” not working like in C od C++ language where you can see all program functions sorted by name (easy navigation from there). It is nice option with long code.

    ReplyDelete
  8. Thanks for sharing this Arduino NPP plugin, very useful... Btw, if you donot want Arduino IDE launch everytime you compile/upload, use PlatformIO as alternative for compile/upload. So you donot need Arduino IDE anymore, PlatformIO will handle it.

    ReplyDelete
    Replies
    1. Wow...even better! I will try it out soon. Thanks!

      Delete