Sunday, July 3, 2016

How to Compile and Upload Arduino Sketches with Notepad++ -- Simple, Convenient, Accessible

Introduction

Blind people living in the real world are constantly working out hacks and alternatives to “normal” work flows that are inaccessible in whole or in part. Arduino software development is no exception, and many of the posts in this blog have been devoted to working around the sketchy (sic) accessibility of the Arduino IDE itself. For example, in an earlier post I describe (perhaps in more detail than strictly necessary) how to set up and configure the Arduino IDE from the Windows command line. In another post, Chancey Fleet provided excellent step-by-step instructions for installing and using Visual Micro to compile and upload Arduino sketches directly from Visual Studio. The current post offers the most convenient Arduino development tool chain I have yet found –editing, compiling, and uploading sketches directly from Notepad++.

Notepad++ (hereafter Npp) is my text editor of choice for almost any simple editing work including coding Arduino. It is used by many developers who don’t want the overhead of a giant IDE just to edit a bit of code. It’s free, open source, simple to install, and largely accessible with whatever screen reader you happen to prefer. It has features such as code completion, line numbers, support for different character encodings, and many others, yet it remains extremely compact and easy to use. Perhaps my favorite feature is that it doesn’t care what kind of line endings you use, CR/LF or just LF – it just does the right thing. This is really nice when using cross-platform source files such as Arduino sketches. If you don’t know what I’m talking about, just take my word for it: Notepad++ is extremely convenient and easy to use as a code editor.

Compiling and uploading Arduino sketches from the command line is great for those of us who are really old school and feel at home typing incredibly long text-based commands. For others though, those long commands are just opportunities for typos and inexplicable DOS error messages. Similarly, for hardcore hackers who have millions of lines of code under their belts, Visual Studio might be the best Arduino development environment you could want. Speaking for myself, however, Visual Studio makes me feel like the Sorcerer’s Apprentice with too many options, settings, and terms that I don’t quite understand, and an incredibly complex interface as reins to ultimate unwanted and undeserved power. In fact, I recently hit an accidental keystroke in VS and the entire thing stopped working. Of course, if I knew what I was doing in there then I’d be able to fix it, but I don’t have that kind of time and I don’t want that kind of power. I just want to write a little Arduino code!

In contrast, Npp is just my speed. It lets me do what I need to do without giving me a dangerous amount of rope. At the same time it has hidden depths which can be quite handy. You could say that I am definitely down with Npp…

But Npp is just an editor. It is not a compiler or an integrated development environment, so it can’t compile or upload your Arduino sketches. On the other hand, it can be configured to interact with other programs on your computer (such as the Arduino IDE) which can. This article explains how to set things up to let you edit an Arduino sketch with Notepad++, and then compile and upload that sketch with a single command without ever leaving Npp. The resulting Arduino compiler output and error messages are even displayed in a Notepad++ window for easy review.

The following sections offer two scripts that can be executed from inside Notepad++. The first allows you to set the Arduino COM port – convenient since this may change frequently with different boards and USB ports. The other compiles and uploads the Arduino sketch that is currently open in Notepad++.

Setting It Up

Step 1: Download the latest Arduino IDE and install it. If necessary, check out my instructions on installing and configuring the Arduino IDE from the command line.

Step 2: Download the latest version of Notepad++ (Npp) and install it. This process is easy and you should have no accessibility-related problems. Take note of the directory where you are installing it because you’ll need to find it later to install the Npp plugin.

Step 3: Download NppExec (a plugin for NPP) and install it. The installation process consists of unzipping the NppExec archive and copying the appropriate DLL into the plugins directory of the Npp installation directory. You are probably using the Unicode version of Npp, so copy the NppExec.dll file from the DLL_Unicode folder of the archive to the plugins directory of Npp and restart Npp to complete the installation. For example, my Npp plugins directory is "C:\Program Files (x86)\Notepad++\plugins"

Step 4: Set up the following Arduino-related NppExec scripts in Npp. You can either copy and paste them from below or download the NppExec scripts in this convenient archive.

The easiest way to install these scripts is to copy and paste them individually into the Execute dialog in NPP. This dialog can be opened with a keyboard shortcut (F6 inside Npp), or through Npp’s menus (Plugins > NppExec > Execute…).

The Execute dialog has a multi-line edit field for pasting or typing the script itself, a Save button for naming and saving scripts, a combo box for recalling previously saved scripts, and an OK button to execute the selected script. All the controls in this dialog are accessible with NVDA or JAWS.

The Arduino COM Port Script

This script makes it easy to quickly update the Arduino IDE’s COM port. This is the port used to upload the sketch to the board. When you invoke this script from inside Npp, a dialog pops up asking for the Arduino’s COM port. Appropriate responses are like the parameters you would use on the command line when setting the com port (e.g., com3, com4, etc.).

To set up the port selection script, open the Execute dialog by pressing F6 or by selecting Execute from the NppExec sub-menu of the Plugins menu. Paste the following script into the edit field and press the Save button. In the Save dialog, type something like “ Arduino Port,” and press return. The port selection script will then be saved for future use using that name.

Before saving, be sure to edit this script to reflect the actual location of your Arduino installation. I have mine in the root directory for convenience – “c:\arduino”.


//This NppExec script sets the com port of your Arduino IDE
//By Josh Miele -- June 27, 2016
//The Blind Arduino Project
//http://blarbl.blogspot.com
set arduino_path = c:\arduino\arduino_debug //the path to your Arduino IDE.
//put up a dialog box requesting com port name
inputbox "Please enter the COM port of your Arduino (e.g., com5):" //gets com port value
//use result to set port value doesn't verify
cmd /c "$(arduino_path)" --port $(input)
npp_console 0 //hide the console

Note: This script does no checking to make sure that you have entered a valid COM port or string. If you make an error typing or enter an invalid com port, you will get no error message or other feedback to indicate your mistake. Take care!

The Compile and Upload Script

This script saves the currently open Arduino sketch, then calls the Arduino IDE with the command line parameters to compile and upload it. It then passes any output, including errors to a new Npp file so that you can easily see what happened.

To set up the compile/upload script, open the Execute dialog by pressing F6 or by selecting Execute from the NppExec sub-menu of the Plugins menu. Paste the following script into the edit field and press the Save button. In the Save dialog, type something like “ Arduino Upload,” and press return. The compile/upload script will then be saved for future use using that name.

Before saving, be sure to edit this script to reflect the actual location of your Arduino installation. I have mine in the root directory for convenience – “c:\arduino”. Also make sure that the Arduino_output.txt file is being created in a directory where you have write privileges and where it won’t cause any problems. I put mine in “c:\temp”. The first time the script runs it will ask for permission to create the output file. After that it will quietly overwrite the file with each new execution of the script.


//This NppExec script compiles and uploads the current Arduino sketch in Npp
//By Josh Miele -- June 27, 2016
//The Blind Arduino Project
//http://blarbl.blogspot.com
//Set where the output goes. Make sure you have write privileges
set arduino_output = "c:\temp\arduino messages.txt" 
//Set location of Arduino executable. 
set arduino_path = c:\arduino\arduino_debug 
npp_save //save current file before uploading
//Compile and upload sketch in current Npp window and send stdOut and stdErr to arduino_output
cmd /c "$(arduino_path)" --upload $(full_current_path)>$(arduino_output) 2>&1
npp_console 0 //hide the console
//show the results of the compile/upload in Npp window
npp_open $(arduino_output)  

Note: This script does not account for the fact that the Arduino IDE will move your sketch if it is not already inside a folder of the same name as the stem of the script. For example, if you are editing a file called MySketch.ino located in c:\temp, executing the above NppExec compile/upload script will compile and upload the sketch, but the Arduino Ide will create a directory called c:\temp\MySketch and move the file MySketch.ino inside it. Notepad++will be left with an open file that has been moved out from under it. This has the potential to lead to unexpected errors and problems, so I recommend making sure your sketches are contained within folders of the appropriate name as modeled in the Arduino examples directory.

Using the Scripts

To invoke these scripts from inside Npp, press F6 to bring up the Execute dialog, then use your arrow keys to select the desired script from the combo box and press return. Pressing ctrl-F6 will execute the last script without invoking the execute dialog.

Note: There is a way to map individual NppExec scripts to their own keyboard shortcuts using the Shortcut Mapper under the Settings menu. Unfortunately, this dialog is not accessible using NVDA or JAWS. I believe there is a way to modify the shortcut mappings by editing one of Npp’s XML files, but I don’t yet know how to do this. In the interest of getting this info into your hands, I decided to post this anyway and update the post when I find an accessible way to map the shortcuts. If you have info about how to do this, please leave it in the comments.

References and Disclaimers

I’m no expert in any of the several areas necessary for creating elegant and effective NppExec scripts. I encourage feedback in the comments and invite suggestions for improvement and additional helpful scripts.

In developing these scripts I found the following resources extremely informative:

66 comments:

  1. cooll.., visite me , informatikkita.blogspot.co.id

    ReplyDelete
  2. Good stuff!
    One comment: If there are any spaces in the arduino_path, it won't work, even with quotes around it.

    ReplyDelete
    Replies
    1. I think adding the installation Path to your the PATH environment variable will solves this problem.

      Delete
  3. I like notepad++ as well, thanks for sharing this!

    ReplyDelete
  4. can notepad++ also open a serial port monitor?

    ReplyDelete

  5. Great tutorial, helped me a lot =D Thanks

    ReplyDelete
  6. Most of the blogs pretend themselves as most usable and updated blogs with new information but sometime truth might different. I want to share some facts related to this subject which will help people to enhance their skills.
    forex เบื้องต้น

    ReplyDelete
  7. I am regular to check every post of this blog as well as its other supportive and knowledgeable informative blog post. I appreciate efforts of owner to deliver such valuable information to people.
    Dell PowerEdge R530

    ReplyDelete
  8. Professionally written blogs are rare to find, however I appreciate all the points mentioned here. I also want to include some other writing skills which everyone must aware of.
    boekhouden voor beginners

    ReplyDelete
  9. Share great information about your blog , Blog really helpful for us . We read your blog , share most useful information in blog . Thanks for share your blog here .
    outplacementbureau amsterdam

    ReplyDelete
  10. I am grateful for this blog to distribute knowledge about this significant topic. Here I found different segments and now I am going to use these new instructions with new enthusiasm.
    ออกแบบ ฉลาก สินค้า

    ReplyDelete
  11. Wow! This is the perfect blog I am looking this type of blog its awesome blog here , share great information about this topic. This informative blog helps many readers with their decision-making regarding the situation. Great articles and will look forward for more!
    Forex Factory

    ReplyDelete
  12. Your information is really helpful for beginners thanks to share this. We are provide a drones Tanning and LiDAR operating course for more information contact us https://www.modus-ai.com/rental/

    ReplyDelete
  13. Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future...
    Elk Stack Online Training

    ReplyDelete
  14. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.

    Tableau online training

    ReplyDelete
  15. I know you feel more happy when you get things done and best of all those things are your most precious treasure.

    ReactJS Online Training

    ReplyDelete
  16. Can I just say what a relief to uncover an individual who actually understands what they're discussing online. You certainly understand how to bring a problem to light and make it important. A lot more people ought to read this and understand this side of the story. It's surprising you're not more popular given that you most certainly have the gift.
    cây treo đồ

    ReplyDelete
  17. Wooden blinds from Lowes, Walmart, Ikea, Target, or Home Depot are . The most effective method to: Install inside mount level wood blinds of the blinds shop. Chosen to supplant existing window blinds with new ones - genuine wood

    ReplyDelete
  18. Hello,
    for those having problems with spaces in path, try replacing this lines considering the different quotation marks ":
    set arduino_path = "C:\Program Files (x86)\Arduino\arduino.exe"
    ...
    cmd /c "$(arduino_path) --upload "$(full_current_path)">$(arduino_output) 2>&1"

    ReplyDelete
  19. some mod from Berbigou, hope you'll enjoy :

    //This Npp_Exec script compiles and uploads the current arduino sketch in Npp
    //By Josh Miele -- June 27, 2016
    //Modified by Berbigou -- April 18, 2020
    //The Blind Arduino Project
    //http://blarbl.blogspot.com

    set fichier = "$(full_current_path)"
    //Set where the output goes. Make sure you have write privileges
    set arduino_output = "D:\Temp\arduino messages.txt"
    //if present, close it
    npp_close $(arduino_output)
    npp_open $(arduino_output)
    //use Monitoring function (language sensitive...)
    NPP_MENUCOMMAND View||Monitoring (tail -f)
    //Let's view it
    NPP_MENUCOMMAND View||Move/Clone Current Document||Move to Other View
    //focus back to file
    npp_switch $(fichier)
    //Set location of arduino executable. (change it if necessary)
    set arduino_path = "C:\Program Files (x86)\Arduino\arduino.exe"
    npp_save //save current file before uploading
    //Compile and upload sketch in current NPP window and send stdOut and stdErr to arduino_output
    cmd /c "$(arduino_path) --upload "$(fichier)">$(arduino_output) 2>&1"
    npp_console 0 //hide the console

    ReplyDelete
  20. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. https://www.acte.in/software-testing-training-in-chennai

    ReplyDelete
  21. face-book is one of the most successful social media websites these days. If the right techniques are used, you can get a lot of fans who would want to know more about your company and the offered products. However, you need to be careful about two things. First of all, you should update the information posted on face book at regular intervals. Resurge Diet Supplement

    ReplyDelete
  22. Nice post. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated posts…

    AWS training in Chennai

    AWS Online Training in Chennai

    AWS training in Bangalore

    AWS training in Hyderabad

    AWS training in Coimbatore

    AWS training

    ReplyDelete
  23. Plantation shutters are enabled with slats that are prepared from real wood materials and faux wood mostly that can be used to tilt upon for getting fresh air and the needed sunlight while sliding the slats that enable to cool the room during summer and an opposite the reaction during winter from Australian Window Covering, Melbourne.

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. 3D Rendering India has been creating top-notch, accurate, and elegant 3D architectural visualizations and CGI rendering services From Kerala in Cochin and all around India.

    ReplyDelete
  27. Your time around the cluster of islets, with rich aquatic life it allows to explore water specious like a pearl, spotted fish, tiger prawns, crabs, prawns in the best backwater resorts in Kerala.

    ReplyDelete
  28. This comment has been removed by the author.

    ReplyDelete
  29. This comment has been removed by the author.

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete
  32. Voucherpro.co.uk helps you save money for your everyday online shopping. We bring all the latest deals and discount codes for everything and help you search your favorite discounts in no time. Moreover, voucherpro.co.uk gives you access to the leading online stores of the UK. You can enjoy shopping easily within your limited budget
    https://www.voucherpro.co.uk/mytabcat.com

    ReplyDelete
  33. I have been browsing online more than 2 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. footlocker discount code nhs

    ReplyDelete
  34. I have been browsing online more than 2 hours today,yet I never found any interesting article like yours. It is pretty worth enough for me. boden promo code 25

    ReplyDelete
  35. I am having some of Uk give me cosmetics discount code
    through you can enjoy this offers and can send gifts With Discount Coupon to any of your lover who is very angry with you.

    ReplyDelete
  36. How to assist with SEO? I’m trying to get my page shein coupon code uk to rank for some targeted keywords but I’m not seeing

    ReplyDelete
  37. Keep your cat safe with the Tabcat cat tracker. Tabcat does not use GPS but works by radiofrequency Tabcat discount code

    ReplyDelete
  38. Thanks for sharing this valuable article over here. You have shared such informative news about Arduino. Thanks Author.
    Arduino IOT Course in Hindi

    ReplyDelete
  39. Nice Blog !
    Our experts at QuickBooks Customer Service offer you effective service at a competitive price in this difficult and dangerous situation.

    ReplyDelete
  40. good efforts. thanks for sharing. i really appreciate your efforts. so please sharing such an amazing information. Loreal men expert

    ReplyDelete
  41. it is helpful for me. It is informative. I think you are the best blogger. so thanks for sharing informative article. Slick gorilla

    ReplyDelete
  42. I read your post and I found it amazing! thank! Reported calls

    ReplyDelete
  43. Very nice and informative article thanks for sharing [url=https://thelawyerworld.com/] the lawyer world [/url]

    ReplyDelete
  44. Your information was very useful to me. That's exactly what I've been looking for
    colourist logo

    ReplyDelete
  45. Yesterday, while I was at work, my cousin stole my apple iPad and tested to see if it can survive a 30 foot drop, just so she can be a YouTube sensation. My iPad is now destroyed and she has 83 views. I know this is totally off topic but I had to share it with someone!

    카지노사이트존
    무료야설
    오피헌터
    횟수 무제한 출장
    스포츠마사지

    ReplyDelete
  46. Il y a des dates limites intéressantes dans cet article, mais je ne sais pas si je les vois toutes à cœur. Il y a peut-être une certaine validité, mais je maintiendrai mon opinion jusqu'à ce que je l'examine plus avant. Bon article , merci et nous aimerions un supplément! Ajouter à FeedBurner comme il se doit


    https://www.totosafeguide.com

    ReplyDelete
  47. Usually, I never comment on blogs but your article is so impressive that I never stop myself to say something about it; You are doing a great job man, keep it up may be helpful for your users wyze discount code 2022

    ReplyDelete