Homepage Wiki Forum Buy

First example

From GNUBLIN

Contents

Now it is time for your first demo application on GNUBLIN.

Lpc3131 boot sd.JPG


Toggle a LED

You can find a red LED on every GNUBLIN board (except Gnublin DIP) which you can switch on and off by controlling the level of the GPIO3 Pin.

The following demo application demonstrates how to switch the red LED on and off.

The first step is to change into the directory /sys/class/gpio with the following command:

root@gnublin:~# cd /sys/class/gpio

You can initialize the GPIO3 Pin with the following command:

root@gnublin:/sys/class/gpio# echo 3 > export

Now switch into the newly created directory gpio3 with the following command:

root@gnublin:/sys/class/gpio# cd gpio3/

With the following command you can change the direction of the pin and set it as an output:

root@gnublin:/sys/class/gpio/gpio3# echo out > direction

Now you can change the value of the pin to 1 (high) or 0 (low) to switch the LED on or off.

The following command switches the LED on

root@gnublin:/sys/class/gpio/gpio3# echo 1 > value

and this command turns the LED off again

root@gnublin:/sys/class/gpio/gpio3# echo 0 > value


Gnublin tools

Because nobody wants to do all these steps again and again for each GPIO pin we wrote a small program called gnublin-gpio

First of all you should learn about how to control and execute the program with the right parameters. Therefore you can type the following command and study the output:

root@gnublin:~# gnublin-gpio -h This script grants access to the GNUBLIN gpio pins. It also works withpca9555 portexpander. -h Show this help -j Convert output to json format -p Select gpio Pin (default=14) <value> between 1 and 20 -i configure pin as input -o configure pin as output and set a value 1=high,0=low -f free the gpio Pin Example: Set GPIO14 Pin as input, read value and print it in json format: gnublin-gpio -i -p 14 -j set GPIO11 Pin as output with a high value gnublin-gpio -o 1 -p 11 set GPIO11 Pin as output with a low value gnublin-gpio -o 0 -p 11

Most parameters should be self explanatory. The following lines are describing how to turn the red LED from the previous example on and off:

Turn the LED on:

root@gnublin:~# gnublin-gpio -o 1 -p 3

Turn the LED off:

root@gnublin:~# gnublin-gpio -o 0 -p 3


You can control many different modules and devices with this knowledge. You can find further information how to go on with your GNUBLIN board on one of the following sites:

There also exists a module overwiev:


You can also go on with selecting a programming language and start with some examples in this language:

In other languages