IDE - Code::Blocks Addon

This template may be useful to someone, who started to play with Arduino IDE but wants to change to Code::Blocks.

Set up for Windows (XP, Vista, Win7):

  1. First, create an ArduinoProject directory in the following Directory:
    (create the folder, "UserTemplates" if it doesn't exist
    • XP, Vista, Win7
      • %APPDATA%\codeblocks\UserTemplates
    • XP (same as above)
      • C:\Documents and Settings\<your login name>\Application Data\codeblocks\UserTemplates
    • Vista, Win7 (same as above)
      • C:\Users\<login>\AppData\Roaming\codeblocks\share\codeblocks\UserTemplates
  2. Next, in this directory create two empty files:
    • start.cpp
    • ArduinoProject.cbp
  3. Now copy into start.cpp the lines below:

** For Mac OS X, use path: ~Libary/Application Support/CodeBlocks
** Other platforms, use path: ~/.codeblocks
 

 

Code:

  1. /*
  2.  * Note we are not the original authors of the samples
  3.  */
  4. extern &quot;C&quot; void __cxa_pure_virtual(void); //for C++ defines
  5. void __cxa_pure_virtual(void) {};
  6. #include &lt;WProgram.h&gt;
  7.  
  8. void setup()
  9. {
  10.   Serial.begin(9600);
  11.   Serial.println(&quot;Hello from Arduino Code::Blocks template&quot;);
  12. }
  13.  
  14. void loop()
  15. {
  16.  
  17. }

 

Next, we copy into ArduinoProject.cbp the lines below:

Code:

 

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot; ?&gt;
  2. &lt;CodeBlocks_project_file&gt;
  3.   &lt;FileVersion major=&quot;1&quot; minor=&quot;6&quot; /&gt;
  4.   &lt;Project&gt;
  5.     &lt;Option title=&quot;ArduinoProject&quot; /&gt;
  6.     &lt;Option pch_mode=&quot;2&quot; /&gt;
  7.     &lt;Option compiler=&quot;avrgcc&quot; /&gt;
  8.     &lt;Build&gt;
  9.       &lt;Target title=&quot;Debug&quot;&gt;
  10.         &lt;Option output=&quot;bin\Debug\ArduinoProject.elf&quot; prefix_auto=&quot;1&quot; extension_auto=&quot;0&quot; /&gt;
  11.         &lt;Option object_output=&quot;obj\Debug\&quot; /&gt;
  12.         &lt;Option type=&quot;1&quot; /&gt;
  13.         &lt;Option compiler=&quot;avrgcc&quot; /&gt;
  14.       &lt;/Target&gt;
  15.       &lt;Target title=&quot;Release&quot;&gt;
  16.         &lt;Option output=&quot;bin\Release\ArduinoProject.elf&quot; prefix_auto=&quot;1&quot; extension_auto=&quot;0&quot; /&gt;
  17.         &lt;Option object_output=&quot;obj\Release\&quot; /&gt;
  18.         &lt;Option type=&quot;1&quot; /&gt;
  19.         &lt;Option compiler=&quot;avrgcc&quot; /&gt;
  20.         &lt;ExtraCommands&gt;
  21.           &lt;Add after=&quot;avr-size --mcu=atmega328p --format=avr $(TARGET_OUTPUT_FILE)&quot; /&gt;
  22.           &lt;Add after=&quot;avr-objcopy -O ihex -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).hex&quot; /&gt;
  23.           &lt;Add after=&quot;avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex&quot; /&gt;
  24.           &lt;Add after=&#39;cmd /c &amp;quot;avr-objdump -h -S $(TARGET_OUTPUT_FILE) &amp;gt; $(TARGET_OUTPUT_FILE).lss&amp;quot;&#39; /&gt;
  25.           &lt;Add after=&quot;C:\prog\arduino-1.0\hardware\tools\avr\bin\avrdude.exe -CC:\prog\arduino-1.0\hardware\tools\avr\etc\avrdude.conf -v -v -v -v -pm328p -cstk500v1 -P\\.\COM4 -b 57600 &nbsp;-D -Uflash:w:${PROJECT_DIR}/${TARGET_OUTPUT_DIR}/${TARGET_OUTPUT_BASENAME}.elf.hex:a&quot; /&gt;
  26.           &lt;Mode after=&quot;always&quot; /&gt;
  27.         &lt;/ExtraCommands&gt;
  28.       &lt;/Target&gt;
  29.     &lt;/Build&gt;
  30.     &lt;Compiler&gt;
  31.       &lt;Add option=&quot;-Os&quot; /&gt;
  32.       &lt;Add option=&quot;-Wall&quot; /&gt;
  33.       &lt;Add option=&quot;-mmcu=atmega328p&quot; /&gt;
  34.       &lt;Add option=&quot;-DF_CPU=16000000L&quot; /&gt;
  35.     &lt;/Compiler&gt;
  36.     &lt;Linker&gt;
  37.       &lt;Add option=&quot;-mmcu=atmega328p&quot; /&gt;
  38.       &lt;Add option=&quot;-Wl,-Map=$(TARGET_OUTPUT_FILE).map,--cref&quot; /&gt;
  39.       &lt;Add library=&quot;C:\prog\arduino-1.0\libArduinoCoreAT328p\core.a&quot; /&gt;
  40.     &lt;/Linker&gt;
  41.     &lt;ExtraCommands&gt;
  42.       &lt;Add after=&quot;avr-size --mcu=atmega328p --format=avr $(TARGET_OUTPUT_FILE)&quot; /&gt;
  43.       &lt;Add after=&quot;avr-objcopy -O ihex -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).hex&quot; /&gt;
  44.       &lt;Add after=&quot;avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex&quot; /&gt;
  45.       &lt;Add after=&#39;cmd /c &amp;quot;avr-objdump -h -S $(TARGET_OUTPUT_FILE) &amp;gt; $(TARGET_OUTPUT_FILE).lss&amp;quot;&#39; /&gt;
  46.     &lt;/ExtraCommands&gt;
  47.     &lt;Unit filename=&quot;start.cpp&quot;&gt;
  48.       &lt;Option compilerVar=&quot;CC&quot; /&gt;
  49.     &lt;/Unit&gt;
  50.     &lt;Extensions&gt;
  51.       &lt;code_completion /&gt;
  52.       &lt;debugger /&gt;
  53.     &lt;/Extensions&gt;
  54.   &lt;/Project&gt;
  55. &lt;/CodeBlocks_project_file&gt;

 

 

Now lets edit ArduinoProject.cbp file:

 

  • Replace C:\prog\arduino-1.0\ with your Arduino install directory
  • Replace C:\prog\arduino-1.0\libArduinoCoreAT328p\ with the directory where your Arduino IDE made the core.a file
  • Replace COM4 to the port of your arduino bord

Usage:

 

  1. Run Code::Blocks
  2. File menu->New->From template , choose User templates on the left and ArduinoProject on the right. When finished,
  3. Build menu->Select target ->Release
  4. Build menu->Build
  5. After building, it starts to upload your program onto the arduino board.

Run Arduino IDE and click on Serial Monitor.  If you see in Serial Monitor the text:

Code:

  1. Hello from Arduino Code::Blocks template

DONE!