Beaglebone Black上的GPIO [英] GPIO on Beaglebone Black
问题描述
我目前遇到了Beaglebone黑色的GPIO引脚问题.
我正在寻找一种从C中的GPIO引脚p8_4读取值的正确方法.如果我正确理解的话,我尝试使用一个库,该库从引入设备树之前一直使用一种不支持的旧方法./p>
我试图找到解决问题的其他方法,但似乎找不到.有没有人能让我在C语言中走上正轨?
这是C代码:
#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;
}
请确保进行正确的错误检查.
关注Derek Molloy在Beaglebone上的网站他的网站
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
这篇关于Beaglebone Black上的GPIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!