Go Down

Topic: CodeBlocks Arduino IDE - real C++ IDE for Arduino development (rev.20130827) (Read 69287 times) previous topic - next topic

nav2go

Hello There,

getting a bit deeper into it but now I'm stuck at an issue I'm sure it's some compiler (preprocessor) setting I'm missing. If I compile/build below code (I've added a function 'test' at the end of the code), it gives me the error message:

error: 'test' was not declared in this scope

Hmmm.... if I put the function above 'void setup()', so in the delcaration section, it works fine. Well, most of my code has functions at the end and I thought compilers could recognize this. Is there some settings I can change?

Here is the code which is producing the error. It's the example which comes up if I generate a Project for Arduino. I only added that function 'test'

thanks
Peter

Code: [Select]
#include <Arduino.h>

/*
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

int x;


void setup()
{
Serial.begin(9600);

// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);

Serial.println("Hello world!");
}

void loop()
{

delay(1000);              // wait for a second
digitalWrite(13, HIGH);   // set the LED on
delay(1000);              // wait for a second
digitalWrite(13, LOW);    // set the LED off

test(x);
}

void test(int i) {
    //do stuff
}

Graynomad

Quote
Well, most of my code has functions at the end and I thought compilers could recognize this.

No they don't, you cannot use a variable or a function before it's been defined. The Arduino IDE protects you from this by scanning the code and including the definitions at the top of the file somewhere.

It seems that this environment doesn't do that for you.

You have to either move the functions or provide the definitions like so.

Code: [Select]
#include <Arduino.h>

/*
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

int x;
void test(int i);  <============== test defined before being used

void setup()
{
Serial.begin(9600);

// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);

Serial.println("Hello world!");
}

void loop()
{

delay(1000);              // wait for a second
digitalWrite(13, HIGH);   // set the LED on
delay(1000);              // wait for a second
digitalWrite(13, LOW);    // set the LED off

test(x);
}

void test(int i) {
    //do stuff
}


This may seem like a pain but it's standard practice probably everywhere but in the Arduino IDE.
______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

nav2go

Hello Bob,

I got it, thank you so much. This is working.

Greetings
Peter

nav2go

Hello There,

is it possible to run an Arduino sketch in C:B and route the output to Processing? I know how to do this when code runs on a real Arduino connected via USB. This would be great because I finally could test all my stuff on my Laptop before uploading it to Arduino.

If this is possible, any chance that some one could post a simple sketch and the matching Processing code?

Solution: Well, I'm sure there are multiple ways of doing this, if there is a better one, please let me know. I realized that there are off corse no physical devices connected to the USB ports as both tools (C:B and Processing) run on the same PC, yet they shall exchange data. So, I did install a COM port emulator called "Virtual Serial Port Driver". The settings I had to make where intuitive with an easy GUI. I set up COM1 and COM2 with an virtual Cross over cable between.

Now, in my processing sketch I open COM1 like this:

myPort = new Serial(this, Serial.list()[0], 115200); --- where "(0)" = COM1, "[1]" = would be COM2 and so on...

In my Arduino sketch in C:B I open COM2 like this:

Serial.begin(115200,2);

Thats it, running both sketches, they now can exchange data.


Thanks
Peter

Virtronics

Looks good and seems to run well. Not sure how to single step or see the variable values except by doing a Serial.print. Any chance of being able to look at two outputs at the same time such as LCD and Serial.

Also, we have just released v0.98D of Simulator for Arduino on our new website here
www.virtronics.com.au

Just released revision 20130401 with improvement in the project wizard and other UI expereiences.
My Arduino blog: http://arduinodev.com/blog

Simulator can do single step as the code is just compiled into native program, regardless in the very limitated implementation of simulation of arduino APIs. Currently the only things can be simluated is serial output and digital pins output.
What do you mean by being able to look at two outputs?


Looks good and seems to run well. Not sure how to single step or see the variable values except by doing a Serial.print. Any chance of being able to look at two outputs at the same time such as LCD and Serial.
My Arduino blog: http://arduinodev.com/blog

I guess this should have nothing to do with the type of IDE. Any sketch can be compiled and uploaded via Arduino IDE can be done the same way (maybe some slight mod is needed) in CodeBlocks.


Hello There,

is it possible to run an Arduino sketch in C:B and route the output to Processing? I know how to do this when code runs on a real Arduino connected via USB. This would be great because I finally could test all my stuff on my Laptop before uploading it to Arduino.
My Arduino blog: http://arduinodev.com/blog

Correct. As this is a real C++ IDE, it requires the code to comply with the rules of C++. Arduino IDE automatically scan the code and generate the function declaration at the beginning of the code while I haven't yet implemented this. Anyway, I think it's always a good habit to declare a function before using or write the function before calling code. ;-)


Quote
Well, most of my code has functions at the end and I thought compilers could recognize this.

No they don't, you cannot use a variable or a function before it's been defined. The Arduino IDE protects you from this by scanning the code and including the definitions at the top of the file somewhere.

It seems that this environment doesn't do that for you.

You have to either move the functions or provide the definitions like so.
My Arduino blog: http://arduinodev.com/blog


nav2go

Quote
See my original question, I found a solution which worked for me. I guess my question was not clear, here is what I'm trying to do:

[Arduino uno] --> USB --> [ PC [running Processing[running Processing sketch]]]
This is a setup I'm using to display Arduino results vis Processing, works great.

What I was asking was to do the same without Arduino Hardware in the following way on one PC:
[PC [Running C:B [running ARduino sketch]] ---> COM1 --> COM2 --> [running Processing[running Processing sketch]]]
As I explained in my original post, I found a way how to do this.



I guess this should have nothing to do with the type of IDE. Any sketch can be compiled and uploaded via Arduino IDE can now be done the same in CodeBlocks.



Hello There,

is it possible to run an Arduino sketch in C:B and route the output to Processing? I know how to do this when code runs on a real Arduino connected via USB. This would be great because I finally could test all my stuff on my Laptop before uploading it to Arduino.





Hi, newbie here, sorry about my lack of knowledge

Why is code::blocks reporting warnings on files like malloc.c, print.cpp & tone.cpp when I'm trying to build the default 'blink' sketch?

I use Revision 20130401 on a Windows 7 x64 box and a mega1280. Standard arduino ide works without problems.

Thanks for making this! I'm looking forward to using it!.

regards,

Bert


Arduino IDE does not display those warning but I believe they still exist.
My Arduino blog: http://arduinodev.com/blog

Jantje

Arduino compiles with "-w" (no warnings) while it is generally accepted in software development world to go for -Wall (show all warnings).
There are good reasons for Arduino to use -w (such as do not confuse people with strange warnings). However if you go to a more robust development environment like CodeBlock, Eclipse, visual studio and others you are very likely to compile "out of the box" with -Wall.
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Hi,

has anybody a tutorial how to add the JeeLib to a project in Codeblocks?

I downloaded v12.11 of Codeblocks today.

* Created a new Arduino 8 Bit project
* Copied the source code of the RF12Demo from JeeLibs into the new project file
* Copied the JeeLib-library tree to the new projects folder as a subfolder.
* Hit compile
* Received Errors:
Code: [Select]
||=== RF12Demo, Arduino Uno ===|
C:\Users\Andre\Downloads\CodeBlocks\arduino\hardware\arduino\cores\arduino\malloc.c|67|warning: initialization makes pointer from integer without a cast|
C:\Users\Andre\Downloads\CodeBlocks\arduino\hardware\arduino\cores\arduino\Print.cpp||In member function 'size_t Print::print(const __FlashStringHelper*)':|
C:\Users\Andre\Downloads\CodeBlocks\arduino\hardware\arduino\cores\arduino\Print.cpp|44|warning: '__progmem__' attribute ignored|
C:\Users\Andre\Downloads\CodeBlocks\arduino\hardware\arduino\cores\arduino\Tone.cpp|119|warning: only initialized variables can be placed into program memory area|
RF12Demo.ino|529|warning: only initialized variables can be placed into program memory area|
RF12Demo.ino|547|warning: only initialized variables can be placed into program memory area|
build\RF12Demo.o||In function `showHelp()':|
RF12Demo.ino:(.text._ZL8showHelpv+0x2a)||undefined reference to `rf12_config(unsigned char)'|
build\RF12Demo.o||In function `ookPulse(int, int)':|
RF12Demo.ino:(.text._ZL8ookPulseii+0xe)||undefined reference to `rf12_onOff(unsigned char)'|
RF12Demo.ino:(.text._ZL8ookPulseii+0x1e)||undefined reference to `rf12_onOff(unsigned char)'|
build\RF12Demo.o||In function `saveConfig()':|
RF12Demo.ino:(.text._ZL10saveConfigv+0x148)||undefined reference to `rf12_config(unsigned char)'|
build\RF12Demo.o||In function `loop':|
RF12Demo.ino:(.text.loop+0x21c)||undefined reference to `rf12_initialize(unsigned char, unsigned char, unsigned char)'|
RF12Demo.ino:(.text.loop+0x2aa)||undefined reference to `rf12_initialize(unsigned char, unsigned char, unsigned char)'|
RF12Demo.ino:(.text.loop+0x362)||undefined reference to `rf12_config(unsigned char)'|
RF12Demo.ino:(.text.loop+0x896)||undefined reference to `rf12_sleep(char)'|
RF12Demo.ino:(.text.loop+0x89c)||undefined reference to `Sleepy::powerDown()'|
RF12Demo.ino:(.text.loop+0x8dc)||undefined reference to `rf12_recvDone()'|
RF12Demo.ino:(.text.loop+0x8e8)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0x8ec)||undefined reference to `rf12_crc'|
RF12Demo.ino:(.text.loop+0x8f0)||undefined reference to `rf12_crc'|
RF12Demo.ino:(.text.loop+0x93a)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0x956)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0x978)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0x97a)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0x99e)||undefined reference to `rf12_crc'|
RF12Demo.ino:(.text.loop+0x9a2)||undefined reference to `rf12_crc'|
RF12Demo.ino:(.text.loop+0x9c0)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0xa56)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0xa58)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0xa72)||undefined reference to `rf12_buf'|
RF12Demo.ino:(.text.loop+0xa7a)||undefined reference to `rf12_buf'|
build\RF12Demo.o||In function `loop':|
RF12Demo.ino:(.text.loop+0xaae)||undefined reference to `rf12_sendStart(unsigned char, void const*, unsigned char)'|
RF12Demo.ino:(.text.loop+0xac0)||undefined reference to `rf12_canSend()'|
RF12Demo.ino:(.text.loop+0xb1a)||undefined reference to `rf12_sendStart(unsigned char, void const*, unsigned char)'|
build\RF12Demo.o||In function `setup':|
RF12Demo.ino:(.text.setup+0x3a)||undefined reference to `rf12_config(unsigned char)'|
||=== Build finished: 28 errors, 5 warnings (0 minutes, 5 seconds) ===|


As it was stated above copying a library to the project folder should be enough as "." should be part of the search path.

I also did try to add the "jeelib" folder explicitly to the search paths. I have no idea, whether I have added it everywhere and in the right places. Far too many menus. The errors did change, but I did not get it to work, though.

Has anybody some more input on what to do and where to look at?

Noob alert...

TIA
Andre

Go Up