Guide to setting up Arduino development environment with CodeBlocks on a Linux box


After maintaining CodeBlocks Arduino Edition, which is an out-of-box distribution for Windows only, for several months, I finally got everything to work on Linux. Thanks to Ubuntu that makes life a lot easier on Linux, I have the chance to get this done in one day. I put all my addons and tweaks on CodeBlocks IDE into a single downloadable package, so it’s easy for everyone to get this done from scratch. Here is a guide showing all the steps for setting up a productive Arduino development environment with CodeBlocks on a Linux box.

1. Install necessary packages

The packages we need to install are:

  • Code::Blocks (the open-source IDE, why on earth do they like two commas in between)
  • G++ (C++ compiler for host machine, used for building simulation target)
  • GCC AVR (C/C++ compiler for AVR)
  • GCC C library for AVR
  • AVRDUDE (the AVR download/upload utility)
  • CuteCom (a serial terminal program)

Yes, you don’t need to install Arduino IDE package. Hoping this won’t piss off the Arduino IDE developers. You can use Ubuntu’s Software Center to search and install all these packages, or you can simply pull in all these packages with one command line:

# sudo apt-get install codeblocks g++ gcc-avr avr-libc avrdude cutecom

After a confirmation prompt, these packages will be fetched and installed like a charm.

 

2. Get and extract the Arduino addon files for CodeBlocks

There are two ways to get the package which I put all my addon and tweaks in, either by downloading the release file or checking out latest files from subversion. You need to put all the files in ~/.codeblocks which is the user data directory of CodeBlocks.

# mkdir ~/.codeblocks

# cd ~/.codeblocks

# wget https://downloads.sourceforge.net/project/arduinodev/codeblocks-arduino-addons-20120606.tar.bz2

# tar jxvf codeblocks-arduino-addons-20120606.tar.bz2

As an alternative to the aboves, you can check out the latest code directly into .codeblocks directory if you have subversion installed.

# svn checkout svn://svn.code.sf.net/p/arduinodev/code/trunk/cbaddons ~/.codeblocks

3. Modify the CodeBlocks project wizard configuration script

This has to be done by an text editor. The file to be modified is located at:

/usr/share/codeblocks/templates/wizard/config.script

You need to sudo to modify this file. Insert following line in the range of function RegisterWizards().

RegisterWizard(wizProject, _T("arduino"), _T("Arduino Project"), _T("Embedded Systems"));

4. Done

Yes it’s done. Now launch CodeBlocks, click Create Project and you will see Arduino Project marked in red. You can then create a ready-to-build Arduino project by proceeding with the project wizard.

If you have any problems, please post them in this forum and let me know.

11 Responses to Guide to setting up Arduino development environment with CodeBlocks on a Linux box

  1. Pingback: CodeBlocks Arduino Edition – out-of-box Arduino IDE for more demanding developers | Develop with Arduino

  2. Pingback: Написание скетчей в Code:Blocks IDE | Хороший блог про Arduino

  3. Hello,

    I’d use a shield, comes with a library. I extracted to / home / me / .codeblocks / arduino / libraries but I can not import the class, how do you do?

    cordially

    • The simplest way is to add the library cpp file to your project and place the library files in the same directory of your sketch.

  4. Thank you. Another question, if i’ve not selected “Send when build” at the begining of the project, how can i upload my sketch ? (is there a button ?)

    • i’m not able to build anything, i’ve followed your instructions on Ubuntu 12.04.

      In Simulator Debug mode :

      ||=== Demo, Simulator – Debug ===|
      /home/vincent/.codeblocks/ardusim/include/util/delay.h|90|attention : #warning “Compiler optimizations disabled; functions from won’t work as designed” [-Wcpp]|
      /usr/include/x86_64-linux-gnu/sys/types.h|198|erreur: conflicting declaration ‘typedef long int int64_t’|
      /home/vincent/.codeblocks/ardusim/arduino/cores/stdint.h|33|erreur: ‘int64_t’ has a previous declaration as ‘typedef long long int int64_t’|
      /usr/include/unistd.h|268|erreur: conflicting declaration ‘typedef __intptr_t intptr_t’|
      /home/vincent/.codeblocks/ardusim/arduino/cores/stdint.h|66|erreur: ‘intptr_t’ has a previous declaration as ‘typedef int intptr_t’|
      ||=== Build finished: 5 errors, 0 warnings ===|
      /home/vincent/.codeblocks/ardusim/include/util/delay.h|90|attention : #warning “Compiler optimizations disabled; functions from won’t work as designed” [-Wcpp]|
      /usr/include/x86_64-linux-gnu/sys/types.h|198|erreur: conflicting declaration ‘typedef long int int64_t’|
      /home/vincent/.codeblocks/ardusim/arduino/cores/stdint.h|33|erreur: ‘int64_t’ has a previous declaration as ‘typedef long long int int64_t’|
      /usr/include/unistd.h|268|erreur: conflicting declaration ‘typedef __intptr_t intptr_t’|
      /home/vincent/.codeblocks/ardusim/arduino/cores/stdint.h|66|erreur: ‘intptr_t’ has a previous declaration as ‘typedef int intptr_t’|
      ||=== Build finished: 10 errors, 0 warnings ===|

      When i do “Build and run” on the “Arduino Uno” target, i have no error (only warnings) but the console say :

      RegisRegisterWizard(wizProject, _T(“arduino”), _T(“Arduino Project”), _T(“Embedded Systems”));terWizard(wizProject, _T(“arduino”), _T(“Arduino Project”), _T(“Embedded Systems”));/media/Donnees/Divers/Projets/Arduino/Code/Demo/bin/Release/Demo.elf: 1: /media/Donnees/Divers/Projets/Arduino/Code/Demo/bin/Release/Demo.elf: Syntax error: “(” unexpected

      Process returned 2 (0×2) execution time : 0.006 s
      Press ENTER to continue.

      And no program could be upload on my board =(

      Are you using http://inotool.org/ ?

    • To upload the compiled HEX, click on tools menu and choose USB Upload. You may need to set upload port in build options’ “Custom Variables” page.

      • For “Arduino Uno”, the key “UPLOAD_PORT” is set to “/dev/ttyUSB0″. How can i check if it is the right ?

        With this parameters, i get:
        [some things]
        Script/function ‘edit_startup_script.script’ registered under menu ‘&Settings/-Edit startup script’
        Opening /media/Donnees/Divers/Projets/Arduino/Code/Demo/Demo.cbp
        done
        Launching tool ‘USB Upload (Flash)’: /usr/bin/avrdude -C /etc/avrdude.conf -V -p -carduino -P -b -D -Uflash:w:/media/Donnees/Divers/Projets/Arduino/Code/Demo//Demo.elf.hex:i (in /media/Donnees/Divers/Projets/Arduino/Code/Demo)
        stderr>
        stderr> avrdude: no programmer has been specified on the command line or the config file
        stderr> Specify a programmer using the -c option and try again
        stderr>
        stderr>
        stdout>
        Tool execution terminated with status 1

        • From the command line, I see upload port is not specified. Normally it should be followed after -P.

  5. Hello Stanley,

    Nice work. But i just follow all your recommandations on ‘how to seting up IDECode::blocks for aduino’, make all internal settings for my 2560, and try to build and run … and got strange errors with the blinking led sample :

    …/bin/Release/Arduino tests.elf: Syntax Error: “(” unexpected

    Process returned 2 (0×2) execution time : 0.011 s
    Press ENTER to continue.

    and console say :

    Launching tool ‘USB Upload (Flash)’: /usr/bin/avrdude -C /etc/avrdude.conf -V -patmega2560 -carduino -P/dev/ttyACM0 -b57600 -D -Uflash:w:/home/trasher/Bureau/Arduino Docs/Code/Projet Tests divers/Arduino Tests//bin/Release/Arduino Tests.elf.hex:i (in /home/regis/Bureau/Arduino Docs/Code/Projet Tests divers/Arduino Tests)
    stderr> avrdude: stk500_recv(): programmer is not responding
    stderr>
    stderr> avrdude done. Thank you.
    stderr>
    stderr>
    stdout>
    Tool execution terminated with status 1

    8<——————————————————————————–

    /dev/ttyACM0 is the USB port grab from my working fine standard Arduino IDE.

    Any workarround will be well comming ! Because it's just so borring to code in this cheap arduino IDE, no ?

    Best Regards

    Trasher

  6. I do some modifications … put a translation file, restart, configure. And now it work … The code upload and run well, still with the error message about the ‘unexpected “(“‘.

    No more message from avrdude.

    What about the unexpected “(” ?

    Trasher