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.
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
as. Also set the path for
gmake. Clicking on the
Versions button should display the versions of the tools.
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.
Finally, switch to the
Other tab, and add
pde to the list of C++ file extensions, and save. That's the tools set up.
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.
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:
If you have different boards you'll have to figure out the correct
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
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.