Go Down

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


Is there any way i can get a Library API for Code::Blocks instead of having to switch between my usual compiler and the stand alone Code::Blocks for arduino? Or a way to merge the stand alone with the official release?


thank you for your project. it's a pity there is no Linux version


Hello, I have some issues with latest CodeBlocks.

It doesn't build code that has been builded successfully in Arduino IDE.
Let me explain a bit my problem.
I have Anarduino MiniWireless and couple thermo sensors DS18B20 connected to it.
I'm trying compile and run default example "Multiple" from DallasTemperature Library.
I've added OneWire and DallasTemperature Library and it works with another code which uses only one termo sensor.
But I need more that one sensor so I decided check this "Multiple" example.

this is my code, a bit changed due to that fact that we need _define_ function before being used as it is explained on page 3 of this thread: http://forum.arduino.cc/index.php?topic=145397.30
Code: [Select]
#include <Arduino.h>

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 10 on the Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

//my changes start ---------------------------------------------
// function to print a device address
void printAddress(DeviceAddress deviceAddress);

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress);

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress);

// main function to print information about a device
void printData(DeviceAddress deviceAddress);
//my changes end ---------------------------------------------

void setup(void)
  // start serial port
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library

  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: ");
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  //outsideThermometer   = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };

  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then
  // use those addresses and manually assign them (see above) once you know
  // the devices on your bus (and assuming they don't change).
  // method 1: by index
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
  if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");

  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices,
  // or you have already retrieved all of them.  It might be a good idea to
  // check the CRC to make sure you didn't get garbage.  The order is
  // deterministic. You will always get the same devices in the same order
  // Must be called before search()
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
  // assigns the seconds address found to outsideThermometer
  //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");

  Serial.print("Device 1 Address: ");

  // set the resolution to 9 bit
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC);

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(outsideThermometer), DEC);


void loop(void)
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");

  // print the device information

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
  for (uint8_t i = 0; i < 8; i++)
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(" Temp F: ");

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
  Serial.print("Resolution: ");

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
  Serial.print("Device Address: ");
  Serial.print(" ");

 and in CodeBlocks I have these errors after I press Build button:

Code: [Select]
arduino\libraries\OneWire\OneWire.cpp|470|warning: only initialized variables can be placed into program memory area|
||=== Build: Arduino Duemilanove (328) in sensors (compiler: GNU AVR GCC Compiler) ===|
build\sensors.o||In function `global constructors keyed to oneWire':|
sensors.ino:(.text._GLOBAL__I_oneWire+0x16)||undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'|
build\sensors.o||In function `printTemperature(unsigned char*)':|
sensors.ino:(.text._Z16printTemperaturePh+0x12)||undefined reference to `DallasTemperature::getTempC(unsigned char*)'|
sensors.ino:(.text._Z16printTemperaturePh+0x44)||undefined reference to `DallasTemperature::toFahrenheit(float)'|
build\sensors.o||In function `loop':|
sensors.ino:(.text.loop+0x16)||undefined reference to `DallasTemperature::requestTemperatures()'|
build\sensors.o||In function `setup':|
sensors.ino:(.text.setup+0x20)||undefined reference to `DallasTemperature::begin()'|
sensors.ino:(.text.setup+0x40)||undefined reference to `DallasTemperature::getDeviceCount()'|
sensors.ino:(.text.setup+0x6e)||undefined reference to `DallasTemperature::isParasitePowerMode()'|
sensors.ino:(.text.setup+0x8e)||undefined reference to `DallasTemperature::getAddress(unsigned char*, unsigned char)'|
sensors.ino:(.text.setup+0xa2)||undefined reference to `DallasTemperature::getAddress(unsigned char*, unsigned char)'|
sensors.ino:(.text.setup+0xf8)||undefined reference to `DallasTemperature::setResolution(unsigned char*, unsigned char)'|
sensors.ino:(.text.setup+0x106)||undefined reference to `DallasTemperature::setResolution(unsigned char*, unsigned char)'|
sensors.ino:(.text.setup+0x11e)||undefined reference to `DallasTemperature::getResolution(unsigned char*)'|
sensors.ino:(.text.setup+0x14c)||undefined reference to `DallasTemperature::getResolution(unsigned char*)'|
||=== Build failed: 13 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

Please advice.


I've just fixed this issue.

I had to add .cpp and .h library files into my project folder AND - add these files into project in CodeBlocks.
After that everything goes ok.


What a wonderful program. :)

Working with simple sketch all good, but as I get more ambitious...

I see this error...

Compiling: TSL230R_Light_Sensor.ino
Linking console executable: build\TSL230R_Light_Sensor_mini328.elf
Assembler messages:
Fatal error: redefinition of mcu type `atmega328p' to `atmega8'
Process terminated with status 1 (0 minute(s), 2 second(s))
0 error(s), 2 warning(s) (0 minute(s), 2 second(s))

All the labels and code invocations seem to make sense... I checked all I could see and "atmega328p" was being assigned to $MCU

Any ideas?




First up, thanks to Stanley Huang for a great Arduino IDE!

All looks very good except for when adding (some) libraries.

I'm electing to use the following approach: copy the library files with folder to <codeblocks dir>\arduino\libraries and add path to build options atmeg 1280 Search Directories. This works for EEPROM, TM1638 and some other libraries.

Then I added jeelib-master library. Downloaded and put source files to <codeblocks dir>\arduino\libraries\jeelib-master (double checked all source files are present).

Added jeelib-master to mega 1280 build options Search Directories:

Below is a test project showing the issue: linker cannot fine object code for class Sleepy but compiler header files are found. The only Referenced library linked is: [EEPROM] but [jeelib-master] is being ignored although it's definitely in the Search Directories. I have observed a similar occurrence in another complex project using many lib's and only one lib is failing to be recognised by the linker - header files are always found OK.
Note, I do not want to add libraries to my project source.

Any help to resolve this small issue would be much appreciated!!

Build Log:
Running target pre-build steps
A:\Portables In Use\CB-Arduino\ArduinoUploader "A:\Portables In Use\CB-Arduino\PROJECTS\LowPowerTest\." mega1280 - 16 0 "A:\Portables In Use\CB-Arduino\PROJECTS\LowPowerTest\build\/lib_mega1280_16.a" "A:\Portables In Use\CB-Arduino\PROJECTS\LowPowerTest\build\/core_mega1280_16.a"
Arduino Compiler & Uploader Version 0.8.9
(C)2013 Developed by Stanley Huang <stanleyhuangyc@gmail.com>, distributed under GPL license
Build Target: Arduino Mega 1280 (MCU: atmega1280)
Referenced libraries: [EEPROM]
Compiling library [EEPROM]...
avr-g++ -c -O2 -s -pipe -fno-exceptions -ffunction-sections -fdata-sections -MMD -DARDUINO=105 -DF_CPU=16000000L -mmcu=atmega1280 -Iarduino/hardware/arduino/cores/arduino -Iarduino/hardware/arduino/variants/mega -Iarduino/libraries/EEPROM "arduino/libraries/EEPROM/EEPROM.cpp" -o "C:\Users\Steven\AppData\Local\Temp/EEPROM.cpp.o"

-------------- Build: Arduino Mega 1280 in LowPowerTest (compiler: GNU AVR GCC Compiler)---------------

Compiling: LowPowerTest.ino
Linking console executable: build\LowPowerTest_mega1280.elf
build\LowPowerTest.o: In function `loop':
LowPowerTest.ino:(.text.loop+0x26): undefined reference to `Sleepy::loseSomeTime(unsigned int)'
LowPowerTest.ino:(.text.loop+0x38): undefined reference to `Sleepy::loseSomeTime(unsigned int)'
build\LowPowerTest.o: In function `__vector_12':
LowPowerTest.ino:(.text.__vector_12+0x26): undefined reference to `Sleepy::watchdogEvent()'
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 0 warning(s) (0 minute(s), 1 second(s))

Win7 x64, Code::Blocks 13.12, Target build: mega1280

Source Code:
#include <Arduino.h>
#include <JeeLib.h> // Low power functions library
#include <EEPROM.h>

int led_pin = 13;   // Pin 13 has an LED connected on most Arduino boards:

ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup the watchdog

void setup()
   // initialize the digital pin as an output.
  pinMode(led_pin, OUTPUT);

void loop()
  // Turn the LED on and sleep for 5 seconds
  byte tweak = EEPROM.read(0); // test eeprom lib is included ok

  Serial.println("Low Power Test!");
  digitalWrite(led_pin, HIGH);
  // Turn the LED off and sleep for 5 seconds
  digitalWrite(led_pin, LOW);


How to configure cppCheck (plugin) to check .ini files in a project


Arduino Mega suddenly became unstable. Arduino builder show only 261 byte of SRAM for local variables. I try few previous (stable) version of my code, but situation is the same, low SRAM and unstable execution. After migrateing my code to Arduino IDE I have 963 byte of SRAM for local variables and stable execution.
Any idea what's wrong?


One of the reason is strange behavior of SRAM size. One can remove some variabla, but SRAM size is the same.
I solve that problem with PSTR() in Udp.write, which I'm using for debugging purpose, so I get huge amount of SRAM.

Go Up