Homepage Wiki Forum Buy




Code::Blocks is a popular development environment for C/C++ development. The development environment is available for Windows and Linux and Mac OS. This article explains how to integrate the Gnublin API in a project with Code::Blocks.

Installation and configuration

Here it is shown how to set up Code::Blocks on Linux and configure it as a cross development environment for the GNUBLIN.

The installation and configuration is tested under Ubuntu 12.04.


Code::Blocks can be installed with apt-get:

user@dev-pc:~# sudo apt-get install codeblocks

Now you can start Code::Blocks in the Aplicationmenue or in the shell.

user@dev-pc:~# codeblocks


To use Code::Blocks as cross development environment you need to install the C/C++ development environment.

Now you have to configure the compiler under Settings >> Compiler and debugger ...:


First you have to copy an existing compiler profile by clicking on Copy . Name the new one "GNUBLIN GCC Compiler".


In the new profile under the tab Toolchain executables you have to enter the compiler path and the accordingly compiler. The compiler path is: /usr/bin

The compilers are entered as shown in the following picture:


After clicking on OK the compiler is configured.

Create a project

To create a project the following steps are necessary:

  1. File >> New >> Project...
  2. In the new window choose Console application and click on go
  3. Choose the C/C++ project
  4. Name the project e.g. blink and enter the path to the project.
  5. Now you have to choose the compiler, here we need the one we created in the steps before: GNUBLIN GCC Compiler.
  6. With clicking on finish the project will be created.

Now you can start writing your program.

Integrate the GNUBLIN API

First of all you need to download the API-Files from the API-Site.

At creating the project, in step Please select the language you wand to use. you need to select C++, because the API is writen in C++.

The downloaded files gnublin.h and gnublin.cpp must be located in the project path. Ater that, the files have to be included to the project: Klick with the right mouse button on the project in the left management column and select Add files....


The next query is confirmed with OK.


Now you can use the GNUBLIN API.

If you have integrated the API the auto-completion supports you immediately and provides information on the necessary parameters.




Create an example program

We write here the classic LED Flashing program that can flash the red LED on the GNUBLIN. The LED is connected to the GPIO 3.

#include "gnublin.h"
int main(){
  gnublin_gpio gpio;
  gpio.pinMode(3, OUTPUT);    //set GPIO 3 as Output
  while(1) {
    gpio.digitalWrite(3, HIGH);  //LED on
    sleep(1);                    //wait 1 second
    gpio.digitalWrite(3,LOW);    //LED off
    sleep(1);                    //wait 1 second

To compile the program, click on the yellow gear.


If in Build Log no errors appear everything worked out and we can load our program on the GNUBLIN and run.

root@gnublin:~# ./blink

Hint: The program can be terminated by pressing ctrl+c.

Send the program to the GNUBLIN

If you have compiled the program with Code::Blocks, it is located in the project directory under bin/Debug/ or under bin/Release.

Now you can copy it in the desired path on the SD-card. If the GNUBLIN is connectet to the PC with a network interface, you can copy the program by using scp:

user@dev-pc:~/MeinProjekt/bin/Release/# scp blink root@
In other languages