Configuring NetBeans to use as an Arduino IDE

As I've said in an earlier post, I very quickly found the Arduino IDE to be way too primitive for serious use, so I decided to switch to using NetBeans as an alternative. First step was to create a Makefile, once I had that done I needed to configure NetBeans to use the avg-gcc toolchain, which was pretty straightforward. Ideally I'd just be able export the relevant settings from NetBeans and provide a file you could download and install, but unfortunately NetBeans doesn't provide a way to do this for individual compilers, just all of them at once :-(

First step is to set up a new compiler configuration, Tools -> Options -> C/C++ -> Add. Set the base directory to wherever you have avr-gcc installed, in my case this is under /opt/arduino/hardware/tools/gcc-avr/avr/bin. Set the compiler family to GNU and save.

step 1

Then in the Build Tools tab, set the paths for the C compiler, the C++ compiler and for the assembler, i.e. the full paths to the AVR versions of gcc, c++ and as. Also set the path for gmake. Clicking on the Versions button should display the versions of the tools.

step 2

Switch to the Code Assistance tab, and for both the C and C++ compilers, click the Reset Settings button. This should fill in the default values, the include directories should be set to locations under your avr-gcc install tree. You also need to manually add the directory containing the source of the Arduino libraries to each compiler configuration, in my case this is /opt/arduino/hardware/cores/arduino, and them move it to the top of the include lists.

step 3       step 4

Finally, switch to the Other tab, and add pde to the list of C++ file extensions, and save. That's the tools set up.

step 5

The next steps apply when you are creating a new project and defining its properties. Obviously you need to choose the avr-gcc toolchain to compile the project, and provide a Makefile to build it with - don't use the standard NetBeans one, it won't work.

The Code Assistance sections for both the C and C++ compilers need setting up to refer to any additional library directories you are using, and if you want code completion to work properly you also need to define the requisite preprocessor macros. Do this by setting up a new Configuration for each board type you use, and within that define the macros. I have duemilanove and mega boards, so my settings are:




step 6

If you have different boards you'll have to figure out the correct __AVR_ATXXX__ and F_CPU #defines. First find boards.txt in your Arduino install tree and find the section for your board. The f_cpu value is what you need for F_CPU, the other setting is a little more fiddly to find. Get the mcu value, then look that up in the second table on this page to find the corresponding macro that needs to be defined.

As the generated code needs to be run on the Arduino, the normal Run settings don't actually make much sense, but we can re-purpose them for our needs. In the Make section, set the Build Result value to the path of your gmake executable, then in the Run section, set the command-line argument to upload. By doing this, when you run the project with F6, NetBeans will run the upload Makefile target which will build the project and upload it to the board. If you want to build, upload and run the serial monitor, set the argument to upload_monitor instead,.

step 7       step 8

With all that in place you should be able to use NetBeans as your IDE for developing for the Arduino, including all the nice features such as cross-referencing and code completion. The setup of projects is a little fiddly, so my suggestion is to set up an empty template project that you can copy and then change all the project name references in - I use TEMPLATE as the project name so I can use a little script to clone the project then rename and batch-edit the files with the correct project name.

Categories : Tech, AVR

Re: Configuring NetBeans to use as an Arduino IDE

 This is fantastic and helped me alot. Thanks!!

Re: Configuring NetBeans to use as an Arduino IDE

It's interesting. Could you please post screen shots of netbeans configuration? Thanks a lot! :)

Re: Configuring NetBeans to use as an Arduino IDE

Good idea - I've annotated the post with screenshots of each step.

Re: Configuring NetBeans to use as an Arduino IDE

Verry interesting!

How about making all this go automaticaly? 
Join in the development effort!

Re: Configuring NetBeans to use as an Arduino IDE

You are welcome to take my stuff if it is of use to you, but unfortunately I don't have the time to work on what looks to be an interesting project. Good luck, and if you are looking for beta testers, drop me a line :-)

Re: Configuring NetBeans to use as an Arduino IDE

If you want to add files to you project you have to edit your makefile right? Or is it done automatically?

Thanks for this post!

Re: Configuring NetBeans to use as an Arduino IDE

No, you don't need to edit the Makefile, additional files are picked up automatically.