Arduino UNOをNode-Redで制御(LED ON/OFF) †Windows10からArduino UNOのLED(L 13Pin)をオン オフするまで ソフトの設定手順 †ArduinoIDEをインストール †DL先https://www.arduino.cc/en/Main/DonateからIDEを以下の手順で取得してインストールする Node.jsのインストール †node-v9(node-v9.11.2-x64.msi)をインストール(Node.jsをインストール) [v10はnode-red-contrib-gpioを追加時にエラーするため使用しない] Python2.xをインストール †以下のコマンドでwindows-build-toolsをインストールとPython2.xもインストールされる~windows-build-toolsも必要なようだ。またPython3.xはNode-Redで動作未確認 管理者のPoweshell内で PS C:\WINDOWS\system32> npm install --global --production windows-build-tools (略) ---------- Visual Studio Build Tools ---------- Successfully installed Visual Studio Build Tools. ------------------- Python -------------------- Successfully installed Python 2.7 Now configuring the Visual Studio Build Tools and Python... All done! インストールされた内容 Node-Redのインストール †npmでnode-redをインストール 管理者のPoweshell内で PS C:\WINDOWS\system32> npm install -g --unsafe-perm node-red C:\Users\user\AppData\Roaming\npm\node-red -> C:\Users\user\AppData\Roaming\npm\node_modules\node-red\red.js C:\Users\user\AppData\Roaming\npm\node-red-pi -> C:\Users\user\AppData\Roaming\npm\node_modules\node-red\bin\node-red-pi + node-red@0.20.8 updated 5 packages in 52.937 Node-Redを起動 †PS C:\WINDOWS\system32> node-red 20 Sep 09:43:02 - [info] Welcome to Node-RED =================== 20 Sep 09:43:02 - [info] Node-RED version: v0.20.8 20 Sep 09:43:02 - [info] Node.js version: v9.11.2 ←Node.jsのバージョン 20 Sep 09:43:02 - [info] Windows_NT 10.0.17134 x64 LE 20 Sep 09:43:06 - [info] Loading palette nodes (略) --------------------------------------------------------------------- Your flow credentials file is encrypted using a system-generated key. If the system-generated key is lost for any reason, your credentials file will not be recoverable, you will have to delete it and re-enter your credentials. You should set your own key using the 'credentialSecret' option in your settings file. Node-RED will then re-encrypt your credentials file using your chosen key the next time you deploy a change. --------------------------------------------------------------------- 20 Sep 11:05:44 - [info] Starting flows 20 Sep 11:05:44 - [info] Started flows 20 Sep 11:05:44 - [info] Server now running at http://127.0.0.1:1880/ Node-Redにアクセス †Chormeでhttp://127.0.0.1:1880にアクセス node-red-contrib-gpioを追加 †パレットの追加で「firmata」で検索してnode-red-contrib-gpioノードを追加 Node-Red起動の管理者のPoweshell内のメッセージ 20 Sep 09:44:16 - [info] モジュールnode-red-contrib-gpio, バージョン: 0.14.0 をインストールします 20 Sep 09:45:03 - [info] モジュール node-red-contrib-gpio をインストールしました 20 Sep 09:45:03 - [info] 追加したノード: 20 Sep 09:45:03 - [info] - node-red-contrib-gpio:gpio in 20 Sep 09:45:03 - [info] - node-red-contrib-gpio:gpio out 20 Sep 09:45:03 - [info] - node-red-contrib-gpio:node-led 20 Sep 09:45:03 - [info] - node-red-contrib-gpio:nodebot 20 Sep 09:45:03 - [info] - node-red-contrib-gpio:johnny5 自宅仮想マシンでは上記の方法で追加できたが、ノートPC(Windows10 Home)では追加時エラーしたので以下のように管理者のPoweshellで追加した node-red停止後コマンドを使用 PS C:\WINDOWS\system32> npm install -g node-red-contrib-gpio > serialport@6.0.5 install C:\Users\user\AppData\Roaming\npm\node_modules\node-red-contrib-gpio\node_modules\firmata\node_modules\serialport > prebuild-install || node-gyp rebuild > serialport@6.2.2 install C:\Users\user\AppData\Roaming\npm\node_modules\node- red-contrib-gpio\node_modules\serialport > prebuild-install || node-gyp rebuild + node-red-contrib-gpio@0.14.0 added 285 packages in 32.636s 以下のノードが追加する Arduinoノード(node-red-node-arduino)を追加 †パレットの追加で「firmata」で検索してnode-red-node-arduinoノードを追加 Node-Red起動の管理者のPoweshell内のメッセージ 20 Sep 09:59:57 - [info] モジュールnode-red-node-arduino, バージョン: 0.2.2 をインストールします 20 Sep 10:00:05 - [info] モジュール node-red-node-arduino をインストールしました 20 Sep 10:00:05 - [info] 追加したノード: 20 Sep 10:00:05 - [info] - node-red-node-arduino:arduino in 20 Sep 10:00:05 - [info] - node-red-node-arduino:arduino out 20 Sep 10:00:05 - [info] - node-red-node-arduino:arduino-board ノートPC(Windows10 Home)でコマンド使用時 PS C:\WINDOWS\system32> npm install -g node-red-node-arduino > @serialport/bindings@2.0.8 install C:\Users\user\AppData\Roaming\npm\node_modules\node-red-node-arduino\node_modules\@serialport\bindings > prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild + node-red-node-arduino@0.2.2 added 76 packages in 13.512s 以下のノードが追加する ArduinoIDEの起動後スケッチ追加 †追加スケッチは「StandardFirmata」 ファイル→スケッチ例→Firmata→StandardFrimsata USBにArduino UNOを接続 StandardFrimsataを検証("レ")し、Arduinoに書き込み("⇒") LED ON/OFF 確認 †Node-Redで以下のようなパーツを配置(injection,debug,arduino) injectionノード arduinoノード 接続 injectionノードの「1」の左の■をクリックするとボード上の「L」のLEDが点灯、injectionノードの「0」の左の■をクリックするとボード上の「L」のLEDが消灯する。 その他のコマンド †Pythonバージョン確認 コマンドプロンプトを再起動 C:\Windows\system32>python -V Python 2.7.15 npmバージョン確認 C:\WINDOWS\system32>npm -v 5.6.0 no-rednoアンインストール PS C:\WINDOWS\system32> npm -g uninstall node-red npm パッケージ確認 C:\WINDOWS\system32>npm -g list C:\Users\user\AppData\Roaming\npm +-- node-red@0.20.8 | +-- @node-red/editor-api@0.20.8 | | +-- @node-red/editor-client@0.20.8 | | +-- @node-red/util@0.20.8 deduped | | +-- bcrypt@3.0.6 deduped | | +-- bcryptjs@2.4.3 deduped | | +-- body-parser@1.19.0 参考 † |