oyatsu8さん、
コマンド呼び出しではなく、rpi-gpio というようなライブラリを使うのはどうでしょうか?
(追記)実行例: npmのインストール~rpi-gpioインストール~サンプルコード実行
環境: RaspberryPi3B, Raspbian:2018-06-27-raspbian-stretch.img、Raspbian付属のnode.js(v4.8.2)
pi@raspberrypi:~ $ cat /proc/cpuinfo | grep Revision
Revision : a02082
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l GNU/Linux
pi@raspberrypi:~ $
pi@raspberrypi:~ $ node -v
v4.8.2
pi@raspberrypi:~ $ npm i rpi-gpio
-bash: npm: command not found
pi@raspberrypi:~ $ sudo apt-get update && sudo apt-get -qq -y install npm # npmをインストール
Extracting templates from packages: 100%
Selecting previously unselected package libc-ares2:armhf.
(Reading database ... 136942 files and directories currently installed.)
Preparing to unpack .../libc-ares2_1.14.0-1~bpo9+1_armhf.deb ...
.
.
Setting up node-gyp (3.4.0-1) ...
Setting up npm (1.4.21+ds-2) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
pi@raspberrypi:~ $
pi@raspberrypi:~ $ npm i rpi-gpio
(node:4821) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
/
> epoll@0.1.22 install /home/pi/node_modules/rpi-gpio/node_modules/epoll
> node-gyp rebuild
make: Entering directory '/home/pi/node_modules/rpi-gpio/node_modules/epoll/build'
CXX(target) Release/obj.target/epoll/src/epoll.o
SOLINK_MODULE(target) Release/obj.target/epoll.node
COPY Release/epoll.node
make: Leaving directory '/home/pi/node_modules/rpi-gpio/node_modules/epoll/build'
rpi-gpio@1.0.0 node_modules/rpi-gpio
├── async@1.5.2
├── debug@2.6.9 (ms@2.0.0)
├── promise@7.1.1 (asap@2.0.6)
└── epoll@0.1.22 (bindings@1.2.1, nan@2.6.2)
pi@raspberrypi:~ $
pi@raspberrypi:~ $ cat example.js # サンプルコード
var gpio = require('rpi-gpio');
gpio.setup(7, gpio.DIR_IN, readInput);
function readInput(err) {
if (err) throw err;
gpio.read(7, function(err, value) {
if (err) throw err;
console.log('The value is ' + value);
});
}
pi@raspberrypi:~ $ node example.js
The value is true
^C
pi@raspberrypi:~ $
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/22 07:07
2018/07/22 08:06
2018/07/22 08:21
2018/07/22 08:35
2018/07/22 08:47 編集
2018/07/22 09:02
2018/07/22 09:03
2018/07/22 09:04