I'm currently stuck on a problem with GPIO pins with the Beaglebone black.
I am looking for a proper way to read the values from GPIO pin p8_4 in C. I tried to use a library which used an old not supported way from the time before device tree's where introduced, if I understand this correctly.
I tried to find other solutions to my problem but I can't seem to find one. Is there anyone who can get me on the right track in C?
Here is a C code:
#include <stdio.h>
int main()
{
FILE *io,*iodir,*ioval;
io = fopen("/sys/class/gpio/export", "w");
fseek(io,0,SEEK_SET);
fprintf(io,"%d",39);
fflush(io);
iodir = fopen("/sys/class/gpio/gpio39/direction", "w");
fseek(iodir,0,SEEK_SET);
fprintf(iodir,"out");
fflush(iodir);
ioval = fopen("/sys/class/gpio/gpio39/value", "w");
fseek(ioval,0,SEEK_SET);
while(1)
{
fprintf(ioval,"%d",1);
fflush(ioval);
sleep(1);
fprintf(ioval,"%d",0);
fflush(ioval);
sleep(1);
}
fclose(io);
fclose(iodir);
fclose(ioval);
return 0;
}
Be sure to do proper error checking.
Follow Derek Molloy's website on Beaglebone His site