AliOS-Things icon indicating copy to clipboard operation
AliOS-Things copied to clipboard

developerkit JS疑问

Open edenleung opened this issue 8 years ago • 4 comments

Describe the bug 使用be-cli 编译生成bin /AliOS-Things/framework/tinyengine/samples/app/flowled

异常: 硬件只有led3亮, led1, led2均不亮.

经单独调试, 发现硬件上的led3灯,要使用GPIO的led5参数, 不清楚什么问题。 board_config.json

{
	"GPIO":[
		{
		"id":"led5",
		"port":63,
		"dir":0,
		"pull":1
		}
	]
}

index.js

var led_handle = GPIO.open('led5');
setInterval(function(){
  GPIO.write(led_handle, 1);
  GPIO.write(led_handle, 0);
}, 1000);

environment

  1. branch(version):
  2. Desktop OS(windows linux or macOS):
  3. example:

Expected behavior

Screenshots

Additional context

edenleung avatar Sep 02 '18 02:09 edenleung

你好,这是因为sample里面的例子使用的develoerkit老的板子(该板子上有5个LED灯)。 对于您手头上的develoerkit只有三个LED灯,如果需要控制LED灯,需要关注LED灯对应的具体GPIO引脚。即board_config.json中的配置。 方法:1) 通过原理图找到LED灯的具体引脚,即PB6,PE3,PD15。 2)然后通过board/developerkit/hal/hal_gpio_stm32l4.h找到管脚的对应GPIO。(以developerkit为例,PB6=GPIO22 , PE3=GPIO67 ,PD15=GPIO63)。 3)在board_config.json中增加配置,如:

{
	"GPIO":[
		{
		"id":"led1",
		"port":22,
		"dir":0,
		"pull":1
		},
              {
		"id":"led2",
		"port":67,
		"dir":0,
		"pull":1
		},
              {
		"id":"led3",
		"port":63,
		"dir":0,
		"pull":1
		}
	]
}

4: 最后在js文件中通过GPIO.write()去控制即可。

wuzhun1001 avatar Sep 04 '18 07:09 wuzhun1001

@wuzhun1001
其实board_config.json中的id属性是不是自定义命名的? 只要使用GPIO.open('idXXX')系统会找到对应的id值是吧?

edenleung avatar Sep 04 '18 07:09 edenleung

是的,id只是一个命名,主要是port,port对了就会控制底层的硬件。

wuzhun1001 avatar Sep 04 '18 07:09 wuzhun1001

明白,谢谢 :)

edenleung avatar Sep 04 '18 07:09 edenleung