So-net無料ブログ作成

Intel XDK IoT Editionを使って温湿度センサを動かしてみる [edison]

前回,EdisonでArduino IDEから動かしてみた.
今回は,Intel XDK IoT Editionを使って温湿度センサを動かしてみる.

というわけで,まず,Intel XDK IoT Editionのインストール.
インストール手順とか,Intel XDK IoT Editionの使い方等は,詳しく書かれているサイトがいくつもあるので,そちらを参照下さいな.
たとえば...
Edisonを開封してからnode.jsでIOポート制御するまで - Qiita
Intel EdisonでIntel XDK for IoTを使う - Qiita
[Edison]Intel XDK IoT Edisonをつかってプログラムのビルドをしてみる | Developers.IO
あたりが参考になるかと.

で,温湿度センサを動かしてみる.温湿度センサは前回使った,AM2321だ.接続(回路図)等は前回から変わってない.

というわけで,早速コードを示そう.
適当なProjectを作って,package.jsonとmain.jsを以下のようにしてやる.

まず,package.json
{
  "name": "TemperatureHumiditySensor",
  "description": "",
  "version": "0.0.0",
  "main": "main.js",
  "engines": {
    "node": ">=0.10.0"
  },
  "dependencies": {
      "sleep": "*"
  }
}

次に,main.js
var mraa = require('mraa');
console.log('MRAA Version: ' + mraa.getVersion());

var sleep = require('sleep');

function crc16(buf, length)
{
    var crc = 0xFFFF;
    for (var j = 0; j < length; j++) {
        crc ^= buf[j];
        for (var i = 0; i < 8; i++) {
            if (crc & 0x01) {
                crc >>= 1;
                crc ^= 0xA001;
            }
            else {
                crc >>= 1;
            }
        }
    }
    return crc;
}

function Am2321(bus, address, bufsize) {
    this.x = new mraa.I2c(bus);
    this.x.address(address);
    this.buff = new Buffer(bufsize);
    
    this.wakeupSensor = function() {
        this.x.writeReg(0, 0);
    }
    
    this.sendCommand = function() {
        get_command = new Buffer([0x03, 0x00, 0x04]);
        this.x.write(get_command);
        sleep.usleep(1500);
    }
    
    this.receiveData = function() {
        this.buff = this.x.read(8);
    }
    
    this.checkCrc = function() {
        var crc = this.buff[6] + this.buff[7] * 256;
        return crc == crc16(this.buff, 6);
    }
    
    this.checkRecieveData = function() {
        return (this.buff[0] == 0x03) && (this.buff[1] == 0x04);
    }

    this.getHumidity = function() {
        var high = this.buff[2];
        var low  = this.buff[3];
        return (high * 256 + low) / 10;
    }

    this.getTemperature = function() {
        var temperature = 0;
        var high = this.buff[4];
        var low  = this.buff[5];

        if (high & 0x80) {
            temperature = -1 * (high & 0x7F) * 256 + low;
        }
        else {
            temperature = high * 256 + low;
        }
        return temperature / 10;
    }
}

var sensor = new Am2321(6, 0x5C, 8);
periodicActivity();

function periodicActivity()
{
    sensor.wakeupSensor();
    sensor.sendCommand();
    sensor.receiveData(); 

    if (sensor.checkCrc() == true) {
        if (sensor.checkRecieveData() == true) {
            var humidity = sensor.getHumidity();
            var temperature = sensor.getTemperature();
            console.log("%d %%, %d C", humidity, temperature);
        }
    }

    setTimeout(periodicActivity,5000);
}

そしたら,ビルドして,Edisonにアップロードして実行してやる.
そうすると,コンソールに温度と湿度が5秒おきに出力されるようになる.

AM2321はI2Cの通信シーケンスに癖があるのだが,とりあえず上記のコードで動作させることができるようだ.

MRAAライブラリがあるので,Arduinoで動かしたときと同じぐらい簡単.
お試しあれ.

タグ:XDK
nice!(0)  コメント(64)  トラックバック(0) 
共通テーマ:日記・雑感

nice! 0

コメント 64

CrbnuttefsGF

payday loan texas - http://personalnerloan.org/ get out of debt <a href=http://personalnerloan.org/>personal loans bad credit</a> ’
by CrbnuttefsGF (2017-09-21 03:38) 

お名前(必須)

payday loans bad credit
<a href="http://loansvtna.org/">pay day loans</a>
low cost payday loans
<a href=http://loansvtna.org/>pay day loan</a> ’
by お名前(必須) (2017-09-22 09:38) 

お名前(必須)

cialis 50mg
<a href="http://cialisofkl.com/">cialis online</a>
cialis canada free sample
<a href=http://cialisofkl.com/>cialis generic</a> ’
by お名前(必須) (2017-09-23 09:11) 

お名前(必須)

buy brand cialis
<a href="http://cialisovnas.com/">cialis</a>
cialis generico
<a href=http://cialisovnas.com/>buy cialis</a> ’
by お名前(必須) (2017-09-23 18:38) 

FfvgUsepleIM

brand name only cialis
<a href="http://veucialis.com/">buy cialis</a>
cheap liquid cialis
<a href=http://veucialis.com/>buy cialis</a> ’
by FfvgUsepleIM (2017-09-24 17:41) 

VqvqKeyncEA

next day brand cialis only online
<a href="http://gawcialis.com/">cialis online</a>
brand cialis
<a href=http://gawcialis.com/>cialis online</a> ’
by VqvqKeyncEA (2017-09-24 17:41) 

お名前(必須)

cialis use in women
<a href="http://cialiseimah.com/">cialis</a>
2.5mg cialis
<a href=http://cialiseimah.com/>generic cialis</a> ’
by お名前(必須) (2017-09-25 20:32) 

お名前(必須)

buy cialis online without a prescription
<a href="http://cialisoakdm.com/">cialis online</a>
cialis sample
<a href=http://cialisoakdm.com/>cheap cialis</a> ’
by お名前(必須) (2017-09-25 20:58) 

お名前(必須)

cialis soft
<a href="http://cialisjrncd.com/">cialis online</a>
buying cialis
<a href=http://cialisjrncd.com/>cialis online</a> ’
by お名前(必須) (2017-09-25 21:01) 

VtnoFeeRSY

cheap cialis australia - https://jrucialis.com
cialis dosage daily <a href=https://jrucialis.com>cheap cialis</a> ’
by VtnoFeeRSY (2017-09-26 22:32) 

KrtpbarcomDE

buy cialis uk - http://haycialis.com/
cialis 40 mg <a href=http://haycialis.com/>generic cialis</a> ’
by KrtpbarcomDE (2017-09-26 22:32) 

お名前(必須)

cialis 5mg online - http://cialiskanr.com
buy cialis from canada <a href=http://cialiskanr.com>buy cialis</a> ’
by お名前(必須) (2017-09-27 08:35) 

お名前(必須)

cialis generic tadalafil - https://cialisonlin.com
cialis long term effects <a href=https://cialisonlin.com>cheap cialis</a> ’
by お名前(必須) (2017-09-27 08:38) 

お名前(必須)

is cialis over the counter
<a href="http://cialiseimah.com/">cialis online</a>
10 mg cialis
<a href=http://cialiseimah.com/>generic cialis</a> ’
by お名前(必須) (2017-09-27 15:44) 

お名前(必須)

cash today
<a href="https://cashrvyn.com/">cash advance america</a>
fast payday loan
<a href="https://cashrvyn.com/">cash advance</a> ’
by お名前(必須) (2017-09-28 22:43) 

お名前(必須)

loan debt consolidation
<a href="https://paydayrvjlo.com/">same day payday loan</a>
poor credit loans
<a href=https://paydayrvjlo.com/>payday loans</a> ’
by お名前(必須) (2017-09-28 22:44) 

お名前(必須)

same day personal loans
<a href="https://personalvrdcg.org/">personal loan online</a>
payday loan lenders no teletrack
<a href=https://personalvrdcg.org/>apply personal loan</a> ’
by お名前(必須) (2017-09-29 00:31) 

お名前(必須)

loan payday
<a href="https://paydayvynk.org/">online loans</a>
unsecured personal loans bad credit
<a href=https://paydayvynk.org/>loans online</a> ’
by お名前(必須) (2017-09-29 01:21) 

LmazJidilsOU

debt relief companies
<a href="https://paydayrvyaf.com/">cash advance definition</a>
small loans bad credit
<a href=https://paydayrvyaf.com/>cash advance loans</a> ’
by LmazJidilsOU (2017-09-29 02:19) 

PamefloanoYJ

bad credit loans online
<a href="https://installmentsvfacr.com/">bad credit installment loans</a>
a quick payday loan
<a href=https://installmentsvfacr.com/>installment loan</a> ’
by PamefloanoYJ (2017-09-29 07:49) 

お名前(必須)

myaffiliateprogram
<a href="https://paydaaexc.com/">payday loans</a>
get a payday loan
<a href=https://paydaaexc.com/>payday loans no credit check</a> ’
by お名前(必須) (2017-09-29 11:08) 

お名前(必須)

home loans for bad credit
<a href="https://loansbtxsa.org/">cash advance</a>
same day loans
<a href=https://loansbtxsa.org/>online payday loan</a> ’
by お名前(必須) (2017-09-29 12:17) 

お名前(必須)

guaranteed bad credit personal loans
<a href="https://cashshybn.com/">cash advance lenders</a>
bad payday loans
<a href=https://cashshybn.com/>cash advance online</a> ’
by お名前(必須) (2017-09-29 15:37) 

お名前(必須)

payday loan for
<a href="https://paydaykmae.com">cash advance loans</a>
and payday loans online
<a href="https://paydaykmae.com">cash advance loans</a> ’
by お名前(必須) (2017-09-30 18:47) 

お名前(必須)

debt consolidation companies
<a href="https://loansonlinevaec.org">fast payday loan</a>
1st payday loan free
<a href=https://loansonlinevaec.org>payday loans online</a> ’
by お名前(必須) (2017-09-30 18:47) 

お名前(必須)

bad check to payday loan
<a href="https://personalloansntui.com">online personal loans</a>
no fax payday loans online
<a href=https://personalloansntui.com>best personal loans</a> ’
by お名前(必須) (2017-09-30 20:51) 

お名前(必須)

easy loans bad credit
<a href="https://nowpayday1.com">3 month payday loans</a>
money loans
<a href=https://nowpayday1.com>payday loans online</a> ’
by お名前(必須) (2017-10-01 07:29) 

お名前(必須)

online payday loans
<a href="https://badcreditnyrc.org">online loan</a>
bad credit loans that are not payday loans
<a href=https://badcreditnyrc.org>online payday loans</a> ’
by お名前(必須) (2017-10-01 08:43) 

お名前(必須)

ameriloan payday loans
<a href="https://cashadvanceamericavatn.org">cash advance usa</a>
bank loans
<a href=https://cashadvanceamericavatn.org>cash advance lenders</a> ’
by お名前(必須) (2017-10-01 11:48) 

お名前(必須)

buy cialis generic online - http://cialisovnnc.com/
buy cialis online doctor <a href=http://cialisovnnc.com/>cialis</a>
by お名前(必須) (2017-10-02 06:18) 

お名前(必須)

cialis daily cost - http://cialisofkl.com/
cheap cialis canada <a href=http://cialisofkl.com/>cheap cialis</a> ’
by お名前(必須) (2017-10-02 06:42) 

お名前(必須)

cialis for sale nyc - http://cialisoanzb.com
how much does cialis cost <a href=http://cialisoanzb.com>cialis price</a> ’
by お名前(必須) (2017-10-03 11:12) 

お名前(必須)

bad credit absolutely no faxing payday loan
<a href="https://paydayllae.com/">payday loans online same day</a>
installment payday loans
<a href=https://paydayllae.com/>best online payday loans</a> ’
by お名前(必須) (2017-10-03 21:44) 

JtnbJidilsRF

debt help
<a href="https://paydayloamec.com/">cash advance online</a>
bad credit loans
<a href=https://paydayloamec.com/>payday loans</a> ’
by JtnbJidilsRF (2017-10-04 01:18) 

お名前(必須)

fast cash personal loans
<a href="https://paydayloanswwe.com/">payday day loans</a>
personal bad credit loans
<a href=https://paydayloanswwe.com/>payday loan</a> ’
by お名前(必須) (2017-10-04 10:03) 

お名前(必須)

personal loans
<a href="https://cashnowemr.com">best payday loans</a>
payday loans online
<a href=https://cashnowemr.com>online payday loans</a> ’
by お名前(必須) (2017-10-04 11:47) 

お名前(必須)

online payday loan - https://paydayllae.com/
apr payday loans <a href=https://paydayllae.com/>best payday loans</a> ’
by お名前(必須) (2017-10-05 05:37) 

FnrxmoiptAR

payday loans no faxing - https://paydayloamec.com/
personal installment loans <a href=https://paydayloamec.com/>loans online</a> ’
by FnrxmoiptAR (2017-10-05 09:17) 

お名前(必須)

payday loan no credit check - https://cashadmme.com/
bc payday loan <a href=https://cashadmme.com/>same day payday loan</a> ’
by お名前(必須) (2017-10-05 11:16) 

お名前(必須)

loans bad credit - https://paydayloanswwe.com/
can payday loans garnish your wages <a href=https://paydayloanswwe.com/>best payday loans</a> ’
by お名前(必須) (2017-10-05 18:10) 

お名前(必須)

payday loan business - https://cashnowemr.com
online payday loan companies <a href=https://cashnowemr.com>payday loan lenders</a> ’
by お名前(必須) (2017-10-05 19:14) 

FnveemoiptJU

canadian payday loans - https://paydaybdrfs.com/
best payday loan company <a href=https://paydaybdrfs.com/>pay day loans</a> ’
by FnveemoiptJU (2017-10-07 01:09) 

VtvzvdFeeRVW

is cialis safe for women - https://genonlinecialis.com
cialis 2.5mg price <a href=https://genonlinecialis.com>generic cialis</a> ’
by VtvzvdFeeRVW (2017-10-07 06:53) 

お名前(必須)

consolidate debt - https://cashecbya.com/
instant personal loans <a href=https://cashecbya.com/>same day payday loans</a> ’
by お名前(必須) (2017-10-07 10:38) 

お名前(必須)

quick payday loan no
<a href="https://paydayloawdcr.com/">payday loans near me</a>
debt solutions
<a href="https://paydayloawdcr.com/">fast payday loans</a> ’
by お名前(必須) (2017-10-08 05:01) 

お名前(必須)

cialis 20mg generic
<a href="https://onlineonlinecialis.com/">generic cialis</a>
cialis tadalafil 5mg
<a href=https://onlineonlinecialis.com/>buy cialis</a> ’
by お名前(必須) (2017-10-08 05:01) 

お名前(必須)

cialis low cost
<a href="https://buybuybuycialis.com/">generic cialis</a>
cialis wholesale
<a href=https://buybuybuycialis.com/>cialis</a>
by お名前(必須) (2017-10-08 07:04) 

お名前(必須)

canada cialis
<a href="https://cheapcheapcialis.com/">buy cialis</a>
cialis free
<a href=https://cheapcheapcialis.com/>generic cialis</a> ’
by お名前(必須) (2017-10-08 07:46) 

JtnvbJidilsIY

loanmax title loan
<a href="https://paydaybdrfs.com/">payday loans online</a>
debt relief
<a href=https://paydaybdrfs.com/>pay day loans</a> ’
by JtnvbJidilsIY (2017-10-08 08:48) 

お名前(必須)

bankruptcy payday loans
<a href="https://paydayloansrvhj.com/">same day payday loan</a>
student loan forgiveness
<a href=https://paydayloansrvhj.com/>same day payday loans</a> ’
by お名前(必須) (2017-10-08 10:54) 

お名前(必須)

cialis soft tabs uk - http://buycialis-menedpil.com/
cialis mexican pharmacy <a href="http://buycialis-menedpil.com/">cialis pills</a> ’
by お名前(必須) (2017-10-11 02:43) 

お名前(必須)

cialis 5mg daily - http://cialisonline-pricepil.com/
tadalafil cialis from india <a href=http://cialisonline-pricepil.com/>buy cialis</a> ’
by お名前(必須) (2017-10-11 08:26) 

AqrhdAccurlDI

generic cialis india - http://genericcialis-viaed.com/
does cialis work for women <a href=http://genericcialis-viaed.com/>buy cialis</a> ’
by AqrhdAccurlDI (2017-10-11 12:44) 

お名前(必須)

herbal cialis - http://cialisonline-vipmej.com/
cialis order <a href=http://cialisonline-vipmej.com/>cialis</a>
by お名前(必須) (2017-10-11 14:18) 

お名前(必須)

cialis daily side effects - http://onlinecialis-cialisvip.com
cialis everyday <a href=http://onlinecialis-cialisvip.com>buying cialis</a> ’
by お名前(必須) (2017-10-11 17:14) 

お名前(必須)

a fast payday loan - https://paydayobns.com/
bad credit <a href="https://paydayobns.com/">payday loans online</a> ’
by お名前(必須) (2017-10-17 23:44) 

お名前(必須)

bad credit payday loan quick - https://paydayceinf.org/
cash advance credit card <a href=https://paydayceinf.org/>same day payday loan</a> ’
by お名前(必須) (2017-10-17 23:44) 

KmrcnmoiptDE

same day payday loans - https://paydaycnrs.net/
fast cash payday loan <a href=https://paydaycnrs.net/>payday loans</a> ’
by KmrcnmoiptDE (2017-10-18 05:04) 

SecvvelenueZO

american online marketing payday loan - https://loansczne.com/
online loans bad credit <a href=https://loansczne.com/>payday loans bad credit</a> ’
by SecvvelenueZO (2017-10-18 10:58) 

お名前(必須)

cash loan no credit check - https://loanscerj.com/
bad credit faxless payday loans <a href=https://loanscerj.com/>same day payday loan</a> ’
by お名前(必須) (2017-10-18 14:04) 

お名前(必須)

online loan - https://loanenav.net/
bad credit payday loans uk <a href=https://loanenav.net/>online payday loans no credit check</a> ’
by お名前(必須) (2017-10-18 15:00) 

お名前(必須)

payday loans online same day - https://loans24rjn.com/
loan small business <a href=https://loans24rjn.com/>cash advance online</a> ’
by お名前(必須) (2017-10-18 15:56) 

お名前(必須)

cash credit card
<a href="https://loansnerc.org/">instant payday loans</a>
auto loans bad credit
<a href=https://loansnerc.org/>payday loans</a> ’
by お名前(必須) (2017-10-20 07:46) 

お名前(必須)

cialis dosage - http://pillsme.com/
cialis 5mg <a href="http://pillsme.com/">cialis online</a> ’
by お名前(必須) (2017-10-20 23:38) 

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。