Go Down

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

stanleyhuang

If you want to reference a custom library in your arduino project, you have two ways to do this:

1. copy the library files with folder to <codeblocks dir>\arduino\libraries, just like you do with standard arduino ide
2. copy the library files to project folder, and add the .cpp files to your project in codeblocks
My Arduino blog: http://arduinodev.com/blog

nav2go

Hello All,

I'm still trying to send out data from CodeBlocks (While running in Sim Debug mode) through the COM2 interface. It works but it is quite slow. I'm using the following code:

Code: [Select]
/* Send Data to RealTerm (on COM1)
*/
#include <Arduino.h>

uint8_t matrix[64];


void setup()
{
Serial.begin(9600,2); //open COM2
for (int i=0; i<64; i++){
       matrix[i]= 65; // "A"
}
}

void loop()
{
  Serial.write(matrix, 64); //always send the complete buffer of 64 bytes
}


Increasing the baud rate does not help. It there any way to improve this, I mean this is very slow.

Thanks a lot!
Peter

nav2go

Hello Stanely,

Just discovered that random() does not really produce random numbers. Also randomSeed() did not help. One of my sketches is relying on random numbers. Can you please have a look into it?

On my previous post about the COM port speed I really would like to know if this can be fixed some day. Basically if I do a Serial.begin(9600) and then have a Serial.println("Hallo!") in the loop, the sim window popping up writes the lines extreemly fast to the screen (as expected).

However, as I need the results not on a screen but elsewhere, I use Serial.begin(9600,1) where "1" stands for COM port 1,  it is very, very slow. Any comment here would be helpfull.

BTW, I was inspired by your very first post here where you wrtote:
Quote
For the hardware simulation, right now I have only implemented serial UART simulation with hardware serial port on PC. This is useful for debugging code dealing with any serial devices by connecting the device directly to PC via a USB-TTL adapter. I have managed to run a sketch based on TinyGPS with a USB GPS receiver.
For example, to use PC serial port COM5 to simulate Arduino's Serial1, you can do like this in the sketch:
Code:
Code: [Select]
Serial1.begin(115200, 5);This will open PC serial port COM5 and subsequential calls to Serial1 will act on the PC serial port.


Thanks
Peter

JustinGS

Hi'
I recently installed CodeBlocks Aurduino. For my first try I decided to upload the default project. It builds fine, but when I try to run it, I get an "error generating HEX file" message. All settings are still  "default"  I am using Revision 20130402

Bergie

I also get "Error generating hex file" trying to use Arduino builder.

The blink example compile and upload to my Uno, so I guess the environment is ok.

Using ArduinoBuilder.exe fails at 92% build. I did add the line #include <Arduino.h> to my project. Using the Arduino IDE my example work fine.
Here is my project code. It will be a simple test to compare battery discharge levels for my daughter's science project.

Quote

#include <Arduino.h>
//unsigned long int timer;
//unsigned long int timeOut;
//unsigned long timeNow;
int batteryStartVoltage;
int batteryCurrentVoltage;
int batterySteps = 20;

void setup() {
  pinMode(A0, INPUT);// put your setup code here, to run once:
  Serial.begin(9600);
  batteryStartVoltage = analogRead(A0);
  Serial.print("Start voltage: ");
  Serial.print(batteryStartVoltage);
  Serial.print("  Start time: ");
  Serial.println(millis());
  Serial.println("***************");
}

void loop() {
  // put your main code here, to run repeatedly:
//  timeNow = millis();
  batteryCurrentVoltage = analogRead(A0);

  if(batteryStartVoltage - batteryCurrentVoltage >= batterySteps) {
   Serial.print("Time:  ");
   Serial.print(millis());
   Serial.print("    Voltage: ");
   Serial.println(batteryCurrentVoltage);
  Serial.println("***************");
  batteryStartVoltage = batteryCurrentVoltage;
  }

}



Does anyone know how to use the Attiny45/85 hardware with codeblocks when using the Arduino as ISP? I am working on three projects that will end up on Attiny45.

Regards

moyanoa

Hi, I installed Codeblock on Mac (Mountain Lion) how do I install arduino? is there a manual?
&
How about the Arduino Simulator for Mac?

Thank you

Agustin.

ijm51000


I also get "Error generating hex file" trying to use Arduino builder.

The blink example compile and upload to my Uno, so I guess the environment is ok.

Using ArduinoBuilder.exe fails at 92% build. I did add the line #include <Arduino.h> to my project. Using the Arduino IDE my example work fine.
Here is my project code. It will be a simple test to compare battery discharge levels for my daughter's science project.


I tried your code with code blocks and the arduino builder and both compiled and built the hex file.

Not sure on the tiny but these links may help

https://www.sparkfun.com/tutorials/200

http://hlt.media.mit.edu/?p=1695

All the best

Ian

nav2go

Hello Stanley et al,

I found a solution for the Serial data out which works for me. I included this Serial code from https://github.com/waynix/SPinGW. I now get Data out very fast from the Ardusim (within CodeBlocks) onto any serial port. The only little drawback is, that I have to do conditional compiles now (one for the Ardusim and one for the real Arduino) but I can work with this.

Maybe this code from github also works for you so you could include it in one of your next builds? It would really be nice to simply say Serial.begin(115200, 5); and get the speed as well.



Greetings
Peter

Hello Stanely,

Just discovered that random() does not really produce random numbers. Also randomSeed() did not help. One of my sketches is relying on random numbers. Can you please have a look into it?

On my previous post about the COM port speed I really would like to know if this can be fixed some day. Basically if I do a Serial.begin(9600) and then have a Serial.println("Hallo!") in the loop, the sim window popping up writes the lines extreemly fast to the screen (as expected).

However, as I need the results not on a screen but elsewhere, I use Serial.begin(9600,1) where "1" stands for COM port 1,  it is very, very slow. Any comment here would be helpfull.

BTW, I was inspired by your very first post here where you wrtote:
Quote
For the hardware simulation, right now I have only implemented serial UART simulation with hardware serial port on PC. This is useful for debugging code dealing with any serial devices by connecting the device directly to PC via a USB-TTL adapter. I have managed to run a sketch based on TinyGPS with a USB GPS receiver.
For example, to use PC serial port COM5 to simulate Arduino's Serial1, you can do like this in the sketch:
Code:
Code: [Select]
Serial1.begin(115200, 5);This will open PC serial port COM5 and subsequential calls to Serial1 will act on the PC serial port.


Thanks
Peter

stanleyhuang

Did you modified HardwareSerial.cpp to make this work?


Hello Stanley et al,

I found a solution for the Serial data out which works for me. I included this Serial code from https://github.com/waynix/SPinGW. I now get Data out very fast from the Ardusim (within CodeBlocks) onto any serial port. The only little drawback is, that I have to do conditional compiles now (one for the Ardusim and one for the real Arduino) but I can work with this.

Maybe this code from github also works for you so you could include it in one of your next builds? It would really be nice to simply say Serial.begin(115200, 5); and get the sp
My Arduino blog: http://arduinodev.com/blog

nav2go

No, I did not touch HardwareSerial.cpp. I simply included serialport.c and serialport.h (from that GitHub code) in my project.

Then in the "void setup()" portion of my sketch I say:

    h = openSerialPort("COM1",115200,one,off); //open COM1 at 115200baud

and in the "void loop()" portion of my sketch I say:

    writeToSerialPort(h,matrix,200); // burst out 200 bytes from matrix

NOTE: (1) obviously I need to change this back to  Serial.begin(115200);  Serial.write(matrix, 200); before uploading to the Arduino. (2) I had to modify serialport.c and serialport.h slightly to make it compile. For some reason it was complaining about the enum for the Baud Rate. So I simply removed it from.h and changed .c from:

    HANDLE openSerialPort(LPCSTR portname,enum Baudrate baudrate, enum Stopbits stopbits, enum Paritycheck parity)

to

    HANDLE openSerialPort(LPCSTR portname,double baudrate, enum Stopbits stopbits, enum Paritycheck parity)

Hope this helps
Greetings, Peter



Did you modified HardwareSerial.cpp to make this work?


Hello Stanley et al,

I found a solution for the Serial data out which works for me. I included this Serial code from https://github.com/waynix/SPinGW. I now get Data out very fast from the Ardusim (within CodeBlocks) onto any serial port. The only little drawback is, that I have to do conditional compiles now (one for the Ardusim and one for the real Arduino) but I can work with this.

Maybe this code from github also works for you so you could include it in one of your next builds? It would really be nice to simply say Serial.begin(115200, 5); and get the sp


Bergie

Thanks for checking out my code IJM. Is there any specific settings you use? I did not change anything from the download.

Perhaps my code must be in a specific file structure or location? (A previous version of C++ IDE did not like spaces in the file paths, but so far I did not have that problem with C::B or Arduino.) I use the same "Sketches" folder as my Arduino and the "standard" files in the same Arduino "Sketches" folder does generate the hex file and I can upload it directly with Arduino builder, even without the specific #include <Arduino.h> line. If you can genererate the hex, then obviously I am doing something wrong.

Regarding porting to the Attiny, I am already using the Arduino as an ISP sucessfully. I did not make myself clear. Apologies for that. What I like to know if it is possible to set C::B in a similar way to program the Attiny. The builder does have an option "ArduinoISP" but I don't have a clue what to do from there, except I get the same "cannot generate hex" problem selecting it. I want to use a specific Attiny library and use the Attiny at 8MHz internal oscillator. I don't have any AVR experience, but my guess is it will be in that fashion through the AVR interface? My current workaround is to write in C::B, save as .ino, re-open Arduino, load code, upload code. In this case I find it easier to just use the Arduino IDE, but it has become blazingly slow to compile.

Regards

megamanX

Hello Stanley,

May I ask you if we can use scanf() and main() with CodeBlocks for Arduino ?

I want to use my keypad (4 rows and 3 columns ) to put values on variable .

The problem with the loop() is I can't properly create a menu like this :


MENU :
---------      

1. Modification des consignes
2. Réglage manuelle des ventilateurs
      

Température actuelle :       15.00 °C
Humidité actuelle :       60.00 %RH

Température (CONSIGNE) :    20.00°C
Humidité (CONSIGNE) :       50.00%RH
      
T° extérieure) :               19.00°C
Humidité (extérieure) :       55.00%RH
      

Votre choix : _
      


If I choose 1 we have this :

MODIFICATIONS DES CONSIGNES :
-------------------------------------

1. Température
      
2. Humidité
      

Votre choix : _




Thank you  to answer me  :).


EDIT : Once I finished to put valus for temprature ,and put "1"  I return to my MENU

MODIFICATIONS DES CONSIGNES :
-------------------------------------

1. Température
      
2. Humidité
      

Votre choix : 1

Nouvelle consigne pour la température (° C): 30.00


Voulez-vous retourner au MENU ?
Votre choix ( 1.(oui) / 2.(non) ):    1



MENU :
---------      

1. Modification des consignes
2. Réglage manuelle des ventilateurs
      

Température actuelle :       15.00 °C
Humidité actuelle :       60.00 %RH

Température (CONSIGNE) :    30.00°C
Humidité (CONSIGNE) :       50.00%RH
      
T° extérieure) :               19.00°C
Humidité (extérieure) :       55.00%RH
      

Votre choix : _

stanleyhuang

You can use printf to output data to serial but not for scanf yet.
Also you can program from main() but you will need to create an AVR project instead of an Arduino project in the IDE.


May I ask you if we can use scanf() and main() with CodeBlocks for Arduino ?

I want to use my keypad (4 rows and 3 columns ) to put values on variable .

The problem with the loop() is I can't properly create a menu like this
My Arduino blog: http://arduinodev.com/blog

stanleyhuang

A new revision is released. It has followng changes:


  • Improved Arduino Builder integration with CodeBlocks (no need to close the uploader window after uploading)

  • Updated several Arduino libraries (OBD, MPU6050, MultiLCD)

  • Compile with -O2 (faster code) instead of -Os when target MCU has 64KB or larger program memory

My Arduino blog: http://arduinodev.com/blog

KirAsh4

I downloaded the most recent release, 20130428 and tried compiling a sketch.  When comparing compiled sizes, it seems CodeBlocks is creating slightly larger files.  When I compile in the Arduino IDE, I get
Code: [Select]
Binary sketch size: 6,724 bytes (of a 32,256 byte maximum)

And when I compile the same exact code in CodeBlocks, it says
Code: [Select]
avrdude.exe: writing flash (7660 bytes):

The HEX files are also larger,  With the Arduino IDE the HEX file is 18,934 bytes whereas with CodeBlocks it's 21,573 bytes.

Looks like there's some more optimization to be done.

Go Up