Homepage Wiki Forum Buy

API DEMO Makefile

From GNUBLIN

This article explains how to integrate the Gnublin API in a project with Makefile.

Before you start, the cross-compile toolchain must be installed as described in C/C++ development environment installation.

After that, we need the following API files:

Let us first create a folder for the demo project

user@dev-pc:~$ mkdir ledblink

Browse to the folder

user@dev-pc:~$ cd ledblink

Download the file gnublin.cpp and gnublin.h

user@dev-pc:~$ wget https://raw.github.com/embeddedprojects/gnublin-api/master/gnublin.h
user@dev-pc:~$ wget https://raw.github.com/embeddedprojects/gnublin-api/master/gnublin.cpp

Once done, you now create a file in the folder with the name ledblink.cpp and copy the following code, or loads the file from the Internet:

user@dev-pc:~$ wget http://www.gnublin.org/downloads/ledblink.cpp

Contents of the file ledblink.cpp:

#include "gnublin.h"
 
int main(){
  gnublin_gpio gpio;
  gpio.pinMode(3, OUTPUT);    //GPIO3 als Ausgang festlegen
 
  while(1) {
    gpio.digitalWrite(3, HIGH);  //LED an
    sleep(1);                    // 1 Sekunde warten
    gpio.digitalWrite(3, LOW);   // LED aus
    sleep(1);                    // wieder 1 Sekunde warten
  }
}


Now we need the Makefile. Create it in the same folder or download it from the internet:

user@dev-pc:~$ wget http://www.gnublin.org/downloads/Makefile

Contents of the file Makefile:

objects = ledblink
 
all: gnublin.o $(objects)
 
gnublin.o: gnublin.cpp gnublin.h
	arm-linux-gnueabi-g++ -c gnublin.cpp 
 
$(objects): $(objects).cpp gnublin.o
	arm-linux-gnueabi-g++ -o $(objects) $(objects).cpp gnublin.o
 
clean: 
	rm -Rf *.o $(objects)

Now you can compile the program by typing the following command:

user@dev-pc:~$ make

Output:

arm-linux-gnueabi-g++ -c gnublin.cpp
arm-linux-gnueabi-g++ -o ledblink ledblink.cpp gnublin.o

Now you have an file called: ledblink.

If you have a network connection to the gnublin you can copy the binary with the instruction

user@dev-pc:~$ scp ledblink root@192.168.0.123:

into the root folder. That it works before you have to connect by terminal and create a password for the root user with:

root@gnublin:~# passwd

Now you can start the programm on the GNUBLIN with

root@gnublin:~# ./ledblink

Nun sollte die LED blinken. Wenn man das ledblink Programm wieder beenden möchte, einfach folgende Tastenkombination benutzen: Now the LED should blink. To terminate the program ledblink just press the following key combination:

ctrl + c 
In other languages