ANSI C IDE for Arduino projects.

Hi,

I have just got an Arduino Mega2560 and my micro controller experience has been with PIC 18F252 chips that we use in the labs at uni which we program with C and chip specific library header files using the microchip MPLAB IDE.

I was just wondering if anyone knows of a similar IDE for arduino boards that use C in the same way rather than the Arduino version of what looks like a C/C++ variation? Mainly as I'm switching between the two different projects I can see using two different yet highly similar languages might become problematic.

Thanks in advance,

TSM

Atmel have a free IDE called AVR Studio, it's a full dev environment with debugger, simulator etc.

I believe people have used it with Arduino but don't know the details. Certainly I plan to try because I can't stand the Arduino IDE for much longer :)

I've also tried using AVRprojectIDE, NetBeans and Eclipse based on several tutes I found but can get none of them working. (probably a reflection on my intollerance for pissing around with new software packages)


Rob

a similar IDE for arduino boards that use C in the same way rather than the Arduino version of what looks like a C/C++ variation

The C used in Arduino is just plain old C. The makefile actually did some pre-processing on the Arduino source file (.pde) prior to compiling:

      echo '#include "WProgram.h"' > applet/$(TARGET).cpp
      echo 'void setup();' >> applet/$(TARGET).cpp
      echo 'void loop();' >> applet/$(TARGET).cpp
      cat main.pde >> applet/$(TARGET).cpp

So in theory, you could use pretty much any IDE that supports C programming. There are already plugins out there for Eclipse and NetBeans.

I had created a little NetBean plugin (Arduino Development Using NetBeans – Kerry D. Wong) a while ago and simplifies Arduino development using NetBeans, and I have been using it to develop my Arduino projects for quite a while :slight_smile:

Hi AlphaZeta,

So are you Kerry then? If so your Netbeans plugin was one of the options I tried, I've almost got it working, maybe you can help a bit with it as I'd love to drop the Arduino IDE.


Rob

Hey Graynomad,

Yep, that would be me... anyway, I'd be happy to help you if you could tell me which part was not working as intended.... Thanks!

Thanks, in the few minutes since I posted I've got my initial problems sorted (setup include files etc) so now I can create a project and enter code with no errors. (it's in a Vista platform)

I'll have to figure out the compile and upload now.

I gather I do that from a command line and not from within Netbeans.


Rob

You sound like you want to use WINAVR (AVR GCC)

http://winavr.sourceforge.net/

Smiley Micro's even shows you how to "ARDUINO-IZE" AVRGCC in a series of articles published in NUTS&VOLTS magazine.

I think I already am, I've been using AVRStudio for quite some time for ASM and C progs (for stand alone AVR projects) and seperately have also been using the Arduino IDE for Arduino stuff. I'm just sick of the Arduino IDE.

I also use Netbeans for java and php progs so I'm reasonably happy with that as well.

I suppose I would like a seperate IDE for Arduino because I'm developing stuff on Arduino and stand-alone at the same time that talk to each other, IIRC you can't run two instances of AVRstudio at once so if I use that I'd be constantly closing/opening the IDE.

If that is the case I'm better off with the Arduino code being developed on something else.

Let me know if my logic is faulty on any count.


Rob

I’ve made some progress, but I’ts been over 10 years since I played with make/grep etc so I’m a little rusty.

Anyway here’s where I’m at, a standard program template looks like this

#define __AVR_ATmega328P__

#include <binary.h>
#include <HardwareSerial.h>
#include <pins_arduino.h>
#include <WConstants.h>
#include <wiring.h>
#include <wiring_private.h>
#include <WProgram.h>
#include <EEPROM/EEPROM.h>


void setup()
{

}

void loop()
{
   
}

this produces the following errors

c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c: In function 'attachInterrupt':
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:91: error: 'EIMSK' undeclared (first use in this function)
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:91: error: (Each undeclared identifier is reported only once
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:91: error: for each function it appears in.)
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:91: error: 'INT0' undeclared (first use in this function)
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:95: error: 'INT1' undeclared (first use in this function)
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c: In function 'detachInterrupt':
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:135: error: 'EIMSK' undeclared (first use in this function)
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:135: error: 'INT0' undeclared (first use in this function)
c:/progra~1/arduino/arduino-0021/hardware/arduino/cores/arduino/WInterrupts.c:138: error: 'INT1' undeclared (first use in this function)

So I go seraching for the INT0, INT1 and EIMSK definitions (that’s where grep comes into it) and find it in iom328p.h.

I add the include and add a path

C:\Program Files\Arduino\arduino-0021\hardware\tools\avr\avr\include\avr

but no go. So then I add some of my own definitions, the code now looks like this

#define __AVR_ATmega328P__

#define EIMSK _SFR_IO8(0x1D)
#define INT0 0
#define INT1 1

#include <iom328p.h>
#include <binary.h>
#include <HardwareSerial.h>
#include <pins_arduino.h>
#include <WConstants.h>
#include <wiring.h>
#include <wiring_private.h>
#include <WProgram.h>
#include <EEPROM/EEPROM.h>


void setup()
{

}

void loop()
{
   
}

but the errors are still the same.

Then my computer crashed and it’s taken few hours to get it going again.

As it happens these errors are exactly the same ones I had with AVRprojIDE the other day.

I’ve also had to mod the makefile a bit because it was written for linux.

Anyway I’ll get back to it later tonight, meanwhile any ideas are welcome.

@TSM: I hope we’re not highjacking your thread but I think it’s relevant and you may benefit from it. I would also recommend looking at this thread

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254027990


Rob

Try replacing this…

#include <iom328p.h>

…with this…

#include <avr/io.h>

No go, same errors.

While adding my own defines isn’t the way to do it I thought I though it should at least make a difference.

By removing WInterrupts.c from “modules” in the makefile the build works, because of course it’s not trying to compile the offending code.

So I added

#include “C:\Program Files\Arduino\arduino-0021\hardware\tools\avr\avr\include\avr\iom328p.h”

to WInterrupts.c and got

“Attempt to include more than one <avr/ioXXX.h> file.”

which implies that one is already included and that file doesn’t have the right definitions.

Looking into WInterrupts.c I see it’s already including io.h and in io.h I see

#elif defined (AVR_ATmega328P)

include <avr/iom328p.h>

so the

#define AVR_ATmega328P

at the top of the sample code should cause the right ioxxx file to be included.


Rob

Some progess.

The makefile (or something) is pointing to the Atmel version of iom328p.h, this file does not include definitions for
INT0 etc as you would expect because that’s an Arduino thing.

I need to get the <> to point to the Arduino folder I think, and that may be in the netbeans setup.


Rob

I added

define EIMSK _SFR_IO8(0x1D)

define INT0 0

define INT1 1

to the Atmel version of iom328p.h and got a clean build.

So the bottom line is that the project/makefile/whatever was pointing to the wrong location for include files, ie Atmel not Arduino.

Now I have a set of .o files the problem has gone away so I can't reproduce it to get a definitive answer. If I can find the .o files and delete them I'll have another go.

Why bother, because I'd like this experience to be documented for those wanting to use Netbeans.


Rob

Looks like it’s working, if so I’ll post details later, if not more questions :slight_smile:


Rob

Hi @Graynomad, if you are using the NetBean plugin, you shouldn't need to go to command line to invoke the compiler. If you add an "upload" target as the article suggested, you should be able to compile and upload from within the IDE.

OK just done that and it works except I’m back to the errors I had before.

Last night I got a full build working (command line) including upload to the chip but I just did a build/clean and that’s broken things again.

I’ll be driving most of today but should get back onto it tonight.


Rob

I've pretty much got this working, still no proper write up but here's a makefile that works.

http://www.robgray.com/temp/makefile

One annoying thing is that some definitions are not found. eg

Serial.begin(9600);

has a squiggly line under "begin" and an "Unable to resolve identifier begin" error. Despite that the code compiles just file.


Rob

#define AVR_ATmega328P

Don’t do that. The appropriate macro is set by avr-gcc based on your -mmcu flag. Just make sure you’ve got -mmcu=atmega328p in CFLAGS. You might also need -DF_CPU=16000000 if you’re using any library timing functions. That will solve your issue including <avr/io.h>.

I've added the -mmcu flag (makefile updated), F_CPU is already there.


Rob

Well Arduino on Netbeans on Windows is 98% a goer. The 2% is the annoying wiggles under things that are in fact OK.

I can live with that for the moment but it's a bit of a pain. Presumably some keyword file somewhere or failure to properly parse include files.

I may write this up but on the other hand I've got a life (and a few projects) to get on with :).


Rob