Edison作業日誌(2日目)
nodejsでLチカできるまでの環境構築を行いました
参考:NodeJS blink on an Intel Edison with mini breakout board | The Surface
とりあえずこのおっさんが言うにはnodejsやC++、pythonで低レイヤーをいじいじするにはIntel’s mraa libraryというのが必要らしい。
mraa libraryをいれる
参考:Edison開発方法(最新FWバージョン) — Edison-Note 1.3 documentation
ここの3番までを行います。
めんどくさい場合はこっちだけでもいいかも
1 2 3 |
echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf opkg update opkg install libmraa0 |
参考:intel-iot-devkit/mraa
これでnodejsで低レイヤーが簡単にいじいじできるぞい(ぞい)
Lチカしてみる
サンプル:mraa/Blink-IO.js at master · intel-iot-devkit/mraa
このサンプルでLチカはすぐにできたので、適当にサンプルをいじって4つのLEDが交互に点滅するプログラムを書きました。
むっちゃ適当。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
var m = require('mraa'); //require mraa console.log('MRAA Version: ' + m.getVersion()); //write the mraa version to the console var myLed0 = new m.Gpio(10); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2) var myLed1 = new m.Gpio(11); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2) var myLed2 = new m.Gpio(12); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2) var myLed3 = new m.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2) myLed0.dir(m.DIR_OUT); //set the gpio direction to output myLed1.dir(m.DIR_OUT); //set the gpio direction to output myLed2.dir(m.DIR_OUT); //set the gpio direction to output myLed3.dir(m.DIR_OUT); //set the gpio direction to output var ledState0 = true; //Boolean to hold the state of Led var ledState1 = true; //Boolean to hold the state of Led var ledState2 = true; //Boolean to hold the state of Led var ledState3 = true; //Boolean to hold the state of Led var counter = 0; setInterval(function() { switch (counter % 4) { case 0: ledState0 = !ledState0; //invert the ledState myLed0.write(ledState0?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low) break; case 1: ledState1 = !ledState1; //invert the ledState myLed1.write(ledState1?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low) break; case 2: ledState2 = !ledState2; //invert the ledState myLed2.write(ledState2?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low) break; case 3: ledState3 = !ledState3; //invert the ledState myLed3.write(ledState3?1:0); //if ledState is true then write a '1' (high) otherwise write a '0' (low) break; } counter++; },1000); |
動作結果これ。
メモ
- edisonにログインする
1 |
ssh root@[IP address of edison] |
- edisonにファイル転送
1 |
scp hogehoge.js root@[IP address of edison] |
- edisonでJsファイル実行
1 |
node hogehoge.js |
最近のコメント