Node.js GPIO 用 pi-gpio 模組終於成功了

查那麼多資料 終於找到一個正確解答了

使用pi-gpio控制树莓派GPIO

跑不起來 跟他說的一樣
到 /home/pi/quick2wire-gpio-admin
打开之前clone下来的quick2wire-gpio-admin/src/gpio-admin.c文件,将第30行左右的

1
int size = snprintf(path, PATH_MAX, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);

修改为

1
int size = snprintf(path, PATH_MAX, "/sys/class/gpio/gpio%u/%s", pin, filename);
改完 在這目錄 
make
sudo make install
******************************
/home/pi/node_modules/pi-gpio
改pi-gpio.js

var gpioAdmin = "gpio-admin",
sysFsPathOld = "/sys/devices/virtual/gpio", // pre 3.18.x kernel
sysFsPathNew = "/sys/class/gpio", // post 3.18.x kernel

sysFsPath;

var gpioAdmin = "gpio-admin",
sysFsPathOld = "/sys/class/gpio", // pre 3.18.x kernel
sysFsPathNew = "/sys/class/gpio", // post 3.18.x kernel

sysFsPath;
**************************************************
var gpio = require("pi-gpio");

gpio.open(40, "output", function(err) {     // Open pin 16 for output
    gpio.write(40, 1, function() {          // Set pin 16 high (1)
        gpio.close(40);                     // Close pin 16
    });
});

終於亮了

原來 npm install pi-gpio
發現都是裝在
/home/pi/node_modules

git clone git://github.com/quick2wire/quick2wire-gpio-admin.git
cd quick2wire-gpio-admin
make
sudo make install
sudo adduser $USER gpio

做這動作 才會有  quick2wire-gpio-admin 這目錄

沒事 怎麼會改路徑呢?
















留言

熱門文章