Mike McCauley (mikem@open.com.au) hat eine C Library für GPIO und SPI für den Raspberry Pi entwickelt, die den Zugriff auf die GPIO Pins an der 26-poligen Stiftleiste des Raspberry Pi zur Ansteuerung externer Peripherie erlaubt.
Installation:
# wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.6.tar.gz # tar zxvf bcm2835-1.0.tar.gz # cd bcm2835-1.0 # ./configure make # sudo make check # sudo make install
Programmbeispiel zur Nutzung der Library (weitere sind im Paket enthalten):
// blink.c // // Example program for bcm2835 library // Blinks a pin on an off every 0.5 secs // // After installing bcm2835, you can build this // with something like: // gcc -o blink blink.c -l bcm2835 // sudo ./blink // // Or you can test it before installing with: // gcc -o blink -I ../../src ../../src/bcm2835.c blink.c // sudo ./blink // // Author: Mike McCauley (mikem@open.com.au) // Copyright (C) 2011 Mike McCauley // $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $ #include <bcm2835.h> // Blinks on RPi pin GPIO 11 #define PIN RPI_GPIO_P1_11 int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) return 1; // Set the pin to be an output bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP); // Blink while (1) { // Turn it on bcm2835_gpio_write(PIN, HIGH); // wait a bit delay(500); // turn it off bcm2835_gpio_write(PIN, LOW); // wait a bit delay(500); } return 0; }
Unter http://www.open.com.au/mikem/bcm2835/ ist nun Version 1.9 der BCM2835 Library verfügbar. Die C-Beispiele wurden auf diese Version angepasst.