erlang下 BeagleBone的GPIO控制实验、以及自带led点亮方法

发现erlang控制gpio也是很容易的。

做了个实验

一、控制BeagleBone自带led灯

1、获取led路径下led名字列表

-define(LED_SYSFS_DIR, "/sys/class/leds/").
list() ->
    case file:list_dir(?LED_SYSFS_DIR) of
	{ok, LedNames} ->
	    {ok, LedNames};
	{error, enoent} ->
	    {ok, []}
    end.
2、发送命令

BrightnessFile = ?LED_SYSFS_DIR ++ Name ++ "/" ++ "brightness",
{ok, Brightness} = file:open(BrightnessFile, [read, write]),
file:pwrite(Brightness, 0, integer_to_list(1)),
timer:sleep(10000),
file:pwrite(Brightness, 0, integer_to_list(0)),
file:close(Brightness).

二、控制BeagleBone的GPIO点亮led

1、找出需要测试的引脚,我以GPIO3_21实验。

{ok, D} = file:open("export",[read,write]).      
** exception error: no match of right hand side value {error,eacces}
17> pwd().
/sys/class/gpio
ok
18> {ok, D} = file:open("export",[read,write]).
** exception error: no match of right hand side value {error,eacces}
19> {ok, D} = file:open("export",[write]).     
{ok,<0.81.0>}
20> file:pwrite(D, 0,117).                     
{error,einval}
21> file:pwrite(D, 0,"117").
ok
22> {ok, E} = file:open("gpio117/direction",[read,write]).
{ok,<0.85.0>}
23> file:close(D).
ok
24> file:pwrite(E, 0,"out").                              
ok
25> file:close(E).          
ok
26> {ok, F} = file:open("gpio117/value",[read,write]).    
{ok,<0.90.0>}
27> file:pwrite(F,0 ,"1").                            
ok
28> 
28> 
28> file:pwrite(F,0 ,"1").
ok
29> file:pwrite(F,0 ,"0").

此处需要对引脚进行确认gpio

/sys/class/gpio中可以看见export文件

GPIOn_x 所对应的编号为32 * n + x  此处GPIO3_21

细节请参考

http://blog.sina.com.cn/s/blog_9e16dc4d01012x7z.html

阅读更多
个人分类: erlang BeagleBone erlang
上一篇mac sublime 3 erlang环境安装 ctags 安装
下一篇erlang udp即时通讯服务器开发浅谈(一)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭