C/C++ library for Beaglebone Black GPIO

Bob Mottram 53d4ca427f pwm initialisation 4 years ago
img aec7d94a6b Headers image 4 years ago
man af32d06217 pwm outputs 4 years ago
src 53d4ca427f pwm initialisation 4 years ago
LICENSE 2c312a462d Add license 4 years ago
Makefile 6d80b7d180 Initial commit 4 years ago
README.md af32d06217 pwm outputs 4 years ago

README.md

libbbb

C/C++ library functions for handling the I/O of the Beaglebone Black.

Installation

git clone https://github.com/bashrc/libbbb
cd libbbb
make
sudo make install

Examples

You can compile any of the following examples with the command:

gcc -Wall -std=gnu99 -pedantic -O3 -o example *.c -I/usr/local/include/libbbb -lbbb

And of course to get access to the I/O run the resulting programs as root or with sudo.

Set an output

Sets pin 12 on header P9 (GPIO 60) to high then low state.

#include "bbb.h"

int main(int argc, char *argv[])
{
    digital_output(P9, 12, 1);
    sleep(1);
    digital_output(P9, 12, 0);
    return 0;
}

Set a Pulse Width Modulated output

Four pins can be used as Pulse Width Modulated (PWM) outputs: P9/14, P9/16, P8/19 and P8/13. These can be used to control the intensity of LEDs, the speed of motors or the position of servos. Their values can be in the range 0-1000.

#include "bbb.h"

int main(int argc, char *argv[])
{
    pwm_output(P8, 13, 1000);
    sleep(2);
    pwm_output(P8, 13, 100);
    return 0;
}

Get the state of an input

Gets the state of pin 12 on header P9 (GPIO 60).

#include "bbb.h"

int main(int argc, char *argv[])
{
    printf("Pin state: %d\n", digital_input(P9, 12));
    return 0;
}

Get the state of an analog input

Gets the state of analog input 0.

#include "bbb.h"

int main(int argc, char *argv[])
{
    int value=0;
    if (enable_analog_inputs() != 0) return 1;
    if (analog_input(0, &value) == 0)
        printf("Analog input 0: %d\n", value);
    return 0;
}

Show the current state of all inputs

Shows an ASCII diagram with the state of digital inputs on both headers.

#include "bbb.h"

int main(int argc, char *argv[])
{
    show_gpio();
    return 0;
}