(Taken from http://mattzz.no-ip.org/wiki/bin/view/Projects/ArduinoAndNetbeans)
Synopsis: This is about setting up a Netbeans environment for Arduino programming. No plugins, no external Makefiles required.
The Arduino environment is great for getting started without requiring any knowledge about compiler, linker and all the stuff 'under the hood'. For that reason the Arduino IDE is kept somewhat simple and lacks features that are essential when 'quick hacking' or 'rapid prototyping' turn into software development.
There are approaches that are using custom Makefiles that have to be adapted and copied in your Netbeans project directory. One good example is Kerry Wongs Makefile and Netbeans Plugin. It works but lacks basic dependency checking. I did not like the fact that the core lib files were compiled every time (same with the Arduino IDE, btw).
So I wanted to see if Netbeans can be configured for Arduino software development using just the means that are provided by Netbeans.
This was done on Mac OS X 10.7 using Arduino 1.0 and Netbeans 7.0.1. It should work as well on any other system.
It looks really complicated but it isn't. ;-)
There are a couple of options here:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin
)
sudo port install avr-binutils avr-gcc avr-libc avrdude
Beware: As of today the mac ports gcc version is rather old (4.0.2)
I went with the CrossPack package for Mac OS X.
Make sure your cross compiler binaries are in the $PATH
.
The nice thing about Arduino is that it comes with a nice core library and a truckload of additional libraries and examples for SPI, LCD, SD cards, OneWire protocol etc. We need these files. I copied them to /usr/local/arduino1.0 because in case of an update of the arduino software my stuff will stil compile.
If you are using Arduino Mega ADK copy pins_arduino.h from /usr/local/arduino1.0/variants/mega/ otherwise your app will compile and upload, but the pins will be different
Netbeans needs to know what compiler toolchains to use for which project and where to find it:
Windows
Add each lib folder, and the utility folders of Ethernet, SD, Wire, to the following
Code Assistance C and C++ Compiler Includes for C and C++ (time consuming but you only have to do it once)
Add your toolchain and make.exe /bin paths to the PATH environmental variable;
for me this was
C:\Downloads\arduino-1.0\hardware\tools\avr\bin; C:\Downloads\arduino-1.0\hardware\tools\avr\utils\bin;
We want to create a static core lib library that we can link our projects against later:
Now we have to adjust some compiler settings for this project.
Breaking down the compiler options that we are going to use:
-Os
: Optimizing size
-Wall
: Print all warnings
-ffunction-sections -fdata-sections
: Arduino IDE does this, so I copied it: "Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file."
-mmcu=atmega328p -DF_CPU=16000000L
: Type and speed of the microcontroller
-DARDUINO=100
: Arduino specific define, software revision of the libs.
-fno-exceptions
: (g++ only!): Disables exception handling
This is done in the project properties:
-Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100
-Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100
Now we are ready to compile the corelib:
You should find a nice corelib under dist/Debug/Arduino-MacOSX/libarduino_corelib.a in your Netbeans project directory.
We are going to create a simple main.cpp that toggles the onboard LED connected to port 13.
#include <Arduino.h> /* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ int main(void) { init(); setup(); for (;;) loop(); return 0; // must NEVER be reached } void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second }
-Os -Wl,--gc-sections -mmcu=atmega328p
If everything went well you will find a file dist/Debug/Arduino-MacOSX/blink build/Debug/Arduino-MacOSX/main.o
Great, so what are we supposed to do with that? We have to convert the file to hex format and upload it to our device. One final tweak and we are done.
We are going to use Netbeans' generated makefiles. They provide several hooks that we can use.
avr-objcopy -O ihex ${CND_ARTIFACT_PATH_${CONF}} ${CND_ARTIFACT_PATH_${CONF}}.hex avr-size --mcu=atmega328 -C ${CND_ARTIFACT_PATH_${CONF}}
upload: .build-post avrdude -C/usr/local/CrossPack-AVR/etc/avrdude.conf -patmega328p -carduino -P/dev/tty.usbmodem1d11 -b115200 -D -F -V -Uflash:w:${CND_ARTIFACT_PATH_${CONF}}.hex:i
So a part of your makefile should look like:
[...] .build-post: .build-impl # Add your post 'build' code here... avr-objcopy -O ihex ${CND_ARTIFACT_PATH_${CONF}} ${CND_ARTIFACT_PATH_${CONF}}.hex avr-size --mcu=atmega328 -C ${CND_ARTIFACT_PATH_${CONF}} upload: .build-post avrdude -C/usr/local/CrossPack-AVR/etc/avrdude.conf -patmega328p -carduino -P/dev/tty.usbmodem1d11 -b115200 -D -F -V - Uflash:w:${CND_ARTIFACT_PATH_${CONF}}.hex:i #clean [...]
If everything went well you will see your Arduino board blinking.
Windows
You need to slightly modify the above commands; -C to the path of avrdude.conf -P to the COM port of your Arduino
Mine look like this;
avr-objcopy -O ihex ${CND_ARTIFACT_PATH_${CONF}} ${CND_ARTIFACT_PATH_${CONF}}.hex avr-size --mcu=atmega328 -C ${CND_ARTIFACT_PATH_${CONF}}
upload: .build-post
avrdude -C C:\Downloads\arduino-1.0\hardware\tools\avr\etc\avrdude.conf -p atmega328p -c arduino -P COM20 -b115200 -D -F -V - Uflash:w:${CND_ARTIFACT_PATH_${CONF}}.hex:i
The good news is: Once you have set up coding project for Arduino you can just copy it (right-click project) and go from there.
port install screen
. Best console ever!
screen /dev/tty.usbmodem1d11
Happy hacking!
In summary, all works well on a Mac, but you may need to go through your settings fixing the standard bits and pieces in project settings and the makefile. Pete
Windows additions by josephdouce