Gestion des pins GPIO en C.

1) Création du répertoire de travail :

pi@raspberrypi ~ $ mkdir GPIO
pi@raspberrypi ~ $ cd GPIO/

2) Téléchargement de la librairie :

pi@raspberrypi ~/GPIO $ wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.25.tar.gz
pi@raspberrypi ~/GPIO $ tar xvfz bcm2835-1.25.tar.gz
pi@raspberrypi ~/GPIO $ cd bcm2835-1.25/

3) Configuration de la compilation :

pi@raspberrypi ~/GPIO/bcm2835-1.25 $ ./configure

4) Compilation :

pi@raspberrypi ~/GPIO/bcm2835-1.25 $ make

5) Vérification de la compilation :

pi@raspberrypi ~/GPIO/bcm2835-1.25 $ sudo make check

6) Installation :

pi@raspberrypi ~/GPIO/bcm2835-1.25 $ sudo make install
pi@raspberrypi ~/GPIO/bcm2835-1.25 $ sudo /sbin/ldconfig
pi@raspberrypi ~/GPIO/bcm2835-1.25 $ cd ..

7) Programme d'exemple : Ouvrir :

blink.c

Ajouter :

#include <bcm2835.h>
#define PIN RPI_GPIO_P1_11
int main(int argc, char **argv) {
    if (!bcm2835_init())
        return 1;
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
    while (1) {
        bcm2835_gpio_write(PIN, HIGH);
        bcm2835_delay(500);
        bcm2835_gpio_write(PIN, LOW);
        bcm2835_delay(500);
    }
    bcm2835_close();
    return 0;
}

8) Compilation de l'exemple :

pi@raspberrypi ~/GPIO $ gcc -o blink blink.c -l bcm2835

9) Vérification :

pi@raspberrypi ~/GPIO $ ls -l blink*
-rwxr-xr-x 1 pi pi 36039 juil. 10 23:22 blink
-rw-r--r-- 1 pi pi   323 juil. 10 23:22 blink.c

10) Lancer l'exemple :

pi@raspberrypi ~/GPIO $ sudo ./blink

11) Lien : http://www.airspayce.com/mikem/bcm2835/index.html