Please forgive me if I use wrong terminology. I'm used to Java, so the jump to C/C++ is a bit disorienting.
After using nice Java IDEs such as IntelliJ with a bunch of features, the IDE Arduino comes with simply doesn't cut it. So I decided to set up Eclipse to work with my Arduino UNO. Because there isn't a whole lot of documentation for doing so, this is now my third thread requesting help about various things :P.
So here's what I'm trying to figure out now: how can I get functions from other source files to work like they do in the Arduino IDE? For example, in the Arduino IDE you would enter Serial.begin(XXXXX); to begin Serial communications. I suppose with Eclipse you would have to include a file and do some other stuff I'm clueless about.
I'm almost positive that the answer is really simple- I know it is in Java, at least. But for me, C/C++ is another story.
Anyways, please help me figure out my new annoying problem. Anything you can do to help is much appreciated
You could use notepad++ on windows or kdevelop on linux.
These work very well and you can use them as external editor and compile with the arduino IDE.
I tried eclipse and it did not work for me.
As a serial monitor you can use the IDE as well or use an external program like putty or equivalent.
The Serial functionality is available without the neccesity to include al library.
Not in eclipse. If I just go ahead and call Serial.begin(9600) in eclipse, it tells me Symbol 'Serial' could not be resolved and Method 'begin' could not be resolved Also when using Eclipse, you don't structure a sketch the way you do in the Arduino IDE. You just make a main() method with an infinite loop that never returns, and the first thing you must do in the main method is call init().
No offence, but if you're a person that doesn't use Eclipse then you probably can't be of much help :\
Also, I know about Notepad++ and the likes. I use it for a bunch of stuff. But the reason I really want to use Eclipse is because it's so much faster and more powerful, it compiles your code in real-time so you know the moment you finish typing that you've made a mistake, it can be used for more than just programming Arduino, and it's quite customizable.
You need the arduino library. Don't worry, it's small. Probably the easiest way to get it into a prototype eclipse project is to create a new project folder called something like "arduino" then copy the arduino library source code into that folder. You can find the library source code here:
that's the thing... when I set up Eclipse and Arduino, I made a static library full of all the files contained in the hardware\arduino\cores\arduino except for main.cpp. Then when I make a new project and make a new file called "main.c", I get everything working. Then I tried using parts of Arduino's API that had something appended before the method name (I don't know the terminology for that. i.e. a normal method in Arduino's API would be digitalWrite(), a method in Arduino's API that had something appended before the method name would be Serial.begin()) and it didn't work; it gave me the errors as above. I am structuring my sketches correctly and including "WProgram.h"
That's why I can't understand why it's happening :\
If you are sure that you are including all of the proper source files, including all of the AVR core files, it should compile. The question is, is there an eclipse cross-compiler for AVR8? Can eclipse support STK500?
What is it that is wrong with the IDE? Why not edit your code elsewhere and then paste it into arduino, or just use AVRDUDE?
cogeary01:
I am structuring my sketches correctly and including "WProgram.h"
Try <WProgram.h> instead. And make sure you have defined a search path to the Arduino headers. It takes some fiddling the first time through, but Eclipse works very well for Arduino coding!
Jim
EDIT: Following is the (entire) blinker.cpp source for a simple Eclipse arduino project. I link it with 3 static libraries: my own static library that contains cLCD, then with the standard arduino-0022 library, and finally with the standard arduino-0022 core. My arduino core library contains main.cpp, FWIW.
#include <WProgram.h>
#include <Wire.h>
#include <cLCD.h>
#define CYCLE 1 // Hz
#define TIME 1000
#define LED 13
cLCD lcd;
int ontime, offtime;
long unsigned ms;
int i;
void setup() {
Wire.begin();
lcd.begin( 16, 2 );
lcd.backlight();
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(LED, OUTPUT);
ms = millis();
i = 10;
}
void loop() {
ontime = ( 10 * i / CYCLE );
offtime = ( 10 * (100 - i ) ) / CYCLE;
while( ( millis() - ms ) <= TIME ) { // run for TIME / 1000 seconds at this level
digitalWrite(LED, HIGH); // set the LED on
lcd.setCursor(0,0);
lcd.print("ON ");
delay(ontime);
digitalWrite(LED, LOW); // set the LED off
lcd.setCursor(0,0);
lcd.print("OFF");
delay(offtime);
}
if( ( i += 10 ) > 100 ) i = 10;
ms += TIME;
}
extern "C" void __cxa_pure_virtual()
{
cli();
for (;;);
}
After messing around with Eclipse for I don't know how long, I finally got it.
It's kind of a messy workaround, but it works. What I did was copy all of arduino-0022\hardware\arduino\cores\arduino into my project, add another .c file which works around the "undefined reference to __cxa_pure_virtual" error. Then I can create a sketch in the Arduino IDE, then create a .cpp file in Eclipse which is a link to the project file, and then I can upload to the arduino via the arduino IDE for easy access to a Serial Console.
Thank you all for trying to help me. I'm glad I got this worked out.
I'm glad you got it worked out. But just FYI, you do not necessarily have to add all of the Arduino source to each of your projects. Instead, if you wish you can make a static library for the Arduino core, and another static library for the Arduino application libraries. Once you have these static libraries, then you can just add them to the linker config section of your project settings.
Either way is fine, but the static library approach avoids the need to recompile all of the Arduino source for every project. It also keeps you from having to add all of those files to each new project.