I am messing with libgpio and I modified the example below to work with the Beaglebone.
http://www.claydowling.com/blog:blinking_lights_with_gpio
The difference with the Beaglebone is it uses 4 gpio controllers. Labeled gpioc0-gpioc3.
Each has 32 pins assigned.
I wanted to use blink.c to run the onboard LED's for some easy testing.
This meant I needed to use gpioc1, pin 21. By default libgpio's open_gpio function defaults to gpioc0.
I noticed Emmanuel's example includes the 'unit' controller.
So i used that and it works. There are Pins 21,22,23,24 available to manipulate. All on gpioc1.
http://www.claydowling.com/blog:blinking_lights_with_gpio
The difference with the Beaglebone is it uses 4 gpio controllers. Labeled gpioc0-gpioc3.
Each has 32 pins assigned.
I wanted to use blink.c to run the onboard LED's for some easy testing.
This meant I needed to use gpioc1, pin 21. By default libgpio's open_gpio function defaults to gpioc0.
I noticed Emmanuel's example includes the 'unit' controller.
So i used that and it works. There are Pins 21,22,23,24 available to manipulate. All on gpioc1.
Code:
#include <inttypes.h>
#include <libgpio.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
gpio_handle_t handle = -1;
int pin = 21;
int unit = 1;
int main(int argc, char **argv)
{
int low_time = 1;
int high_time = 1;
int ch;
while((ch = getopt(argc, argv, "h:l:")) != -1) {
switch(ch) {
case 'h':
high_time = strtol(optarg, NULL, 10);
break;
case 'l':
low_time = strtol(optarg, NULL, 10);
break;
case '?':
default:
fprintf(stderr, "%s [-l low_time -h high_time]\n",
argv[0]);
return EXIT_FAILURE;
}
}
handle = gpio_open(unit);
if (-1 == handle) {
perror("gpio");
return EXIT_FAILURE;
}
gpio_pin_output(handle, pin);
while(1) {
gpio_pin_high(handle, pin);
sleep(high_time);
gpio_pin_low(handle, pin);
sleep(low_time);
}
return EXIT_SUCCESS;
}