Is it better to move to AVR studio (or any other better alternative?) over the Arduino IDE. Feel like it's so simple and childish. I need to know the experts idea and choice..
Is it advisable to stay stick to Arduino IDE
arduinomicrocontroller
Related Solutions
AVR Studio uses the atmel compiler (IAR). What compiler does Eclipse use (I'm guessing gcc). There are differences in the extensions and in the standard libraries for different compilers.
I have created a little project with a custom build system (using Ruby) that makes this pretty easy without having to install the Arduino IDE. Basically, it uses a template Makefile, and a ruby script to make compiling the Arduino libraries extremely easy. You can see it at https://github.com/Earlz/make-wiring
However, I'm leaving the old answer here for information on rolling your own. It's quite cumbersome and annoying though:
Directions:
- Download a copy of the Arduino IDE source code
- Copy the contents of
hardware/arduino/cores/arduino
to a new directory I'll refer to as arduino_build - Copy the
pins_arduino.h
file from whichever Arduino variant is yours fromhardware/arduino/variants
(check boards.txt if you're not sure) to arduino_build - Add this makefile to arduino_build:
.
#BSD licensed, see http://lastyearswishes.com/static/Makefile for full license
HDRS = Arduino.h binary.h Client.h HardwareSerial.h IPAddress.h new.h pins_arduino.h Platform.h Printable.h Print.h \
Server.h Stream.h Udp.h USBAPI.h USBCore.h USBDesc.h WCharacter.h wiring_private.h WString.h
OBJS = WInterrupts.o wiring_analog.o wiring.o wiring_digital.o wiring_pulse.o wiring_shift.o CDC.o HardwareSerial.o \
HID.o IPAddress.o main.o new.o Print.o Stream.o Tone.o USBCore.o WMath.o WString.o
#may need to adjust -mmcu if you have an older atmega168
#may also need to adjust F_CPU if your clock isn't set to 16Mhz
CFLAGS = -I./ -std=gnu99 -DF_CPU=16000000UL -Os -mmcu=atmega328p
CPPFLAGS = -I./ -DF_CPU=16000000UL -Os -mmcu=atmega328p
CC=avr-gcc
CPP=avr-g++
AR=avr-ar
default: libarduino.a
libarduino.a: ${OBJS}
${AR} crs libarduino.a $(OBJS)
.c.o: ${HDRS}
${CC} ${CFLAGS} -c $*.c
.cpp.o: ${HDRS}
${CPP} ${CPPFLAGS} -c $*.cpp
clean:
rm -f ${OBJS} core a.out errs
install: libarduino.a
mkdir -p ${PREFIX}/lib
mkdir -p ${PREFIX}/include
cp *.h ${PREFIX}/include
cp *.a ${PREFIX}/lib
And then just run
make
make install PREFIX=/usr/arduino (or whatever)
And then to make use of the compiled libraries and such you can use a simple makefile like this:
default:
avr-g++ -L/usr/arduino/lib -I/usr/arduino/include -Wall -DF_CPU=16000000UL -Os -mmcu=atmega328p -o main.elf main.c -larduino
avr-objcopy -O ihex -R .eeprom main.elf out.hex
upload:
avrdude -c arduino -p m328p -b 57600 -P /dev/ttyUSB0 -U flash:w:out.hex
all: default upload
Also, if you try to compile the libraries in libraries/
you'll get a linker error if you don't do things in the right order. For instance, I had to do this to use SoftwareSerial:
avr-g++ -L/usr/arduino/lib -I/usr/arduino/include -Wall -DF_CPU=16000000UL -Os -mmcu=atmega328p -o main.elf main.c -lSoftwareSerial -larduino
The -larduino
must be the last library on the command line
Anyway, this was a pretty easy way to compile it for me. As future versions of the Ardunio come out, this makefile should be fairly future-proof, requiring just a few modifications to OBJS and HDRS. Also, this makefile should work with both BSD make and GNU make
See also a slightly modified version of this answer on my blog with an already compiled binary of the library (compiled using the "standard" pins_arduino.h).
** EDIT **
I found that adding the following compiler optimization flags to both the library building Makefile and each individual project Makefile greatly reduces the size of the final compiled binary. This makes the final binary size comparable to that of the IDE.
-Wl,--gc-sections -ffunction-sections -fdata-sections
.
So, for the library build makefile:
CFLAGS = -I./ -std=gnu99 -DF_CPU=16000000UL -Os -Wl,--gc-sections -ffunction-sections -fdata-sections -mmcu=atmega328p
CPPFLAGS = -I./ -DF_CPU=16000000UL -Os -Wl,--gc-sections -ffunction-sections -fdata-sections -mmcu=atmega328p
and, for each project makefile:
avr-g++ -L/usr/arduino/lib -I/usr/arduino/include -Wall -DF_CPU=16000000UL -Os -Wl,--gc-sections -ffunction-sections -fdata-sections -mmcu=atmega328p -o main.elf main.c -larduino
.
Related Topic
- Electronic – arduino – How to transition from using the Arduino IDE to plain avrdude/make
- Electronic – arduino – Programming an ATmega1284p with Arduino IDE and internal RC Oscillator
- Electronic – arduino – Adding the AVR Dragon’s HVPP to the Arduino IDE
- Electronic – arduino – How to graduate from Arduino to using a microcontroller directly
Best Answer
A huge advantage of using e.g. AVR Studio is the ability to use all the libraries made for ATmega168/328 before the dawn of Arduino. FFT libraries, libraries for using some obscure IC you have purchased, rudimentary digital filters, and many more can be found on AVRfreaks and hundreds of other hobby sites.
You can also write more efficient code if you learn how to utilize standard AVR libraries and study the microcontroller's datasheet (or tutorials). For simple applications, arduino code is easy to write and debug. However, sometimes you want to control the timing more efficiently.
AnalogRead()
needs 100µs to execute. That corresponds to 10ksps (thousands of samples per second). You can easily pump that to 70ksps if you access low-level code for the ATmega168/328. You can do all of that in the Arduino IDE, of course, but at some point your projects might become too complex, and you will want to write your own libraries with faster functions. AVR Studio might be more suited for that.Also, if you ever want to program any AVR chip other than those offered by Arduino, you will need a programmer and a different IDE. Small projects that use 1kB of code can be done on an ATtiny. You can buy a dozen of those for the price of a single ATmega328. Those chips are cheap and have most of Arduino's capabilities: I2C, SPI, ADC. You can even find libraries that add a USB HID interface! No serial drivers or anything!
Personally, I first write code in the Arduino IDE, without code optimization. If it works, that code can be easily transcribed into standard C++ libraries and made more efficient.