So-net無料ブログ作成

Arduinoで大気圧センサを使ってみる [Arduino]

大気圧センサを入手したので,Arduinoで動かしてみる.使用したのは,秋月電子の,「MPL115A2使用大気圧センサーモジュールキット(I2C) Ver2」.

ネットで調べると,Arduino用のライブラリが公開されていたので,ありがたく使わせてもらう.参照したのは,Arduinoで遊ぶページにある,「MPL115A2用ライブラリ」だ.

あとは,前回作った7セグLEDライブラリと組み合わせて,測定した大気圧を7セグLEDに表示してみる.

7セグLEDとの接続は前回と同じなので,大気圧センサとの接続部分のみ示そう.回路図はこんな感じ.
pressure_sensor_回路図.png

で,スケッチ.
#include <Wire.h>
#include <MPL115A2.h>
#include <MsTimer2.h>
#include <Led7segment.h>

const int anode_pins[] = {
    12, // A
    8,  // B
    5,  // C
    3,  // D
    2,  // E
    11, // F
    6,  // G
    4,  // DP
};

const int cathode_pins[] = {
    13, // DIG.1
    10, // DIG.2
    9,  // DIG.3
    7,  // DIG.4
};

const int ANODE_PINS_NUM   = sizeof(anode_pins)   / sizeof(anode_pins[0]);
const int CATHODE_PINS_NUM = sizeof(cathode_pins) / sizeof(cathode_pins[0]);

unsigned int display_buffer[CATHODE_PINS_NUM] = {0};

void write_1digit(const unsigned char bitmap)
{
    for (int i = 0; i < ANODE_PINS_NUM; i++) {
        digitalWrite(anode_pins[i], bitmap & (1 << i) ? HIGH : LOW);
    }
}

void clear()
{
    for (int i = 0; i < ANODE_PINS_NUM; i++) {
        digitalWrite(anode_pins[i], LOW);
    }
}

void write()
{
    for (int i = 0; i < CATHODE_PINS_NUM; i++) {
        digitalWrite(cathode_pins[i], LOW);
        write_1digit(display_buffer[i]);
        delayMicroseconds(100);
        clear();
        digitalWrite(cathode_pins[i], HIGH);
    }
}

void print_7seg(unsigned char *buff)
{
    noInterrupts();
    for (int i = 0; i < CATHODE_PINS_NUM; i++) {
        display_buffer[i] = buff[i];
    }
    interrupts();
}

void setup()
{
    for (int i = 0; i < ANODE_PINS_NUM; i++) {
        pinMode(anode_pins[i], OUTPUT);
    }

    for (int i = 0; i < CATHODE_PINS_NUM; i++) {
        pinMode(cathode_pins[i], OUTPUT);
        digitalWrite(cathode_pins[i], HIGH);
    }
    
    MsTimer2::set(1, write);
    MsTimer2::start();
    
    MPL115A2.begin();
}

void loop()
{
    unsigned char buff[CATHODE_PINS_NUM] = {0};
    const unsigned int numeric_digits = CATHODE_PINS_NUM;
    const unsigned int frac_digits = 3;

    Led7segment led;
    
    double pressure = 0.0;
    for (int i = 0; i < 10; i++) {
      pressure += MPL115A2.read();
      delay(100);
    }
    
    pressure /= 10.0;
    led.print(buff, pressure, numeric_digits, frac_digits);
    print_7seg(buff);
}


測定値のばらつきが多いようなので,10回測定して平均値を採用してる.
あと,本来は高度に応じて補正を入れて,海面更正気圧を求めるべきだが,ひとまず測定値そのままにしている.
こちらの使用環境ではおおよそ5気圧ほど低くなる計算(高度からの換算値)で,補正後の値を気象庁の気圧値(たとえば東京はこんな感じ)と比較してもおおよそ一致しているので,測定は正しく行えているようである.

で,実際の動作状況はこんなかんじ.
DSC_0214.jpg

大気圧測定ライブラリを利用すると,とても簡単に使える.作成者に感謝.
お試しあれ.

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

nice! 0

コメント 61

CrbnuttefsGF

guaranteed personal loans - http://personalnerloan.org/ quick cash loan <a href=http://personalnerloan.org/>easy personal loans</a> ’
by CrbnuttefsGF (2017-09-21 12:00) 

お名前(必須)

cialis without prescription in canada
<a href="http://cialisofkl.com/">generic cialis</a>
cost of cialis
<a href=http://cialisofkl.com/>buy cialis</a> ’
by お名前(必須) (2017-09-23 10:28) 

お名前(必須)

cialis daily dose
<a href="http://cialisovnas.com/">cialis generic</a>
cialis tablets
<a href=http://cialisovnas.com/>cialis</a>
by お名前(必須) (2017-09-23 20:00) 

VqvqKeyncEA

cialis daily 5mg
<a href="http://gawcialis.com/">generic cialis</a>
cialis price comparison
<a href=http://gawcialis.com/>cialis online</a> ’
by VqvqKeyncEA (2017-09-24 18:46) 

FfvgUsepleIM

generic cialis tadalafil
<a href="http://veucialis.com/">cialis online</a>
cialis plus
<a href=http://veucialis.com/>buy cialis</a> ’
by FfvgUsepleIM (2017-09-24 18:46) 

お名前(必須)

cialis generic tadalafil
<a href="http://cialiseimah.com/">cheap cialis</a>
cheap cialis tablets
<a href=http://cialiseimah.com/>generic cialis</a> ’
by お名前(必須) (2017-09-25 21:54) 

お名前(必須)

cialis side effects
<a href="http://cialisoakdm.com/">generic cialis</a>
tadalafil cialis from india
<a href=http://cialisoakdm.com/>buy cialis</a> ’
by お名前(必須) (2017-09-25 22:20) 

お名前(必須)

cialis for sale in canada
<a href="http://cialisjrncd.com/">cheap cialis</a>
buy cialis soft
<a href=http://cialisjrncd.com/>generic cialis</a> ’
by お名前(必須) (2017-09-25 22:30) 

お名前(必須)

price cialis
<a href="http://cialiseiand.com/">buy cialis</a>
purchase cialis
<a href=http://cialiseiand.com/>cialis online</a> ’
by お名前(必須) (2017-09-26 06:18) 

VtnoFeeRSY

cialis on line - https://jrucialis.com
cialis soft tab <a href=https://jrucialis.com>cheap cialis</a> ’
by VtnoFeeRSY (2017-09-26 23:40) 

KrtpbarcomDE

cialis tablets - http://haycialis.com/
generic soft tabs cialis <a href=http://haycialis.com/>cialis</a>
by KrtpbarcomDE (2017-09-26 23:40) 

お名前(必須)

cialis 5mg price - http://cialiskanr.com
cialis once a day pill <a href=http://cialiskanr.com>cialis</a>
by お名前(必須) (2017-09-27 10:00) 

お名前(必須)

cialis once a day pill - https://cialisonlin.com
what is cialis <a href=https://cialisonlin.com>cheap cialis</a> ’
by お名前(必須) (2017-09-27 10:29) 

お名前(必須)

easy online payday loans
<a href="https://personalvrdcg.org/">personal loan bad credit</a>
instant online payday loan
<a href=https://personalvrdcg.org/>personal loans online</a> ’
by お名前(必須) (2017-09-28 22:09) 

お名前(必須)

same day loans bad credit
<a href="https://paydayvynk.org/">pay day loan</a>
payday loans
<a href=https://paydayvynk.org/>payday advance</a> ’
by お名前(必須) (2017-09-28 23:32) 

お名前(必須)

ca payday loan laws
<a href="https://paydayrvjlo.com/">payday loans bad credit</a>
loan consolidation
<a href=https://paydayrvjlo.com/>fast payday loan</a> ’
by お名前(必須) (2017-09-29 00:01) 

お名前(必須)

best payday loans uk
<a href="https://personalloansntui.com">apply personal loan</a>
loan with bad credit
<a href=https://personalloansntui.com>bad credit personal loan</a> ’
by お名前(必須) (2017-09-30 18:26) 

お名前(必須)

bad credit home loans
<a href="https://leopaydayadvanceonlinefastpayday.org">cash advance</a>
personal installment loans
<a href=https://leopaydayadvanceonlinefastpayday.org>pay day loans</a> ’
by お名前(必須) (2017-09-30 19:50) 

お名前(必須)

payday loans america
<a href="https://paydaykmae.com">cash advance</a>
cant get a payday loan
<a href="https://paydaykmae.com">cash advance loans</a> ’
by お名前(必須) (2017-09-30 20:05) 

お名前(必須)

bad check to a mississippi payday loan
<a href="https://loansonlinevaec.org">fast payday loan</a>
payday loans no faxing no credit checks
<a href=https://loansonlinevaec.org>payday cash loan</a> ’
by お名前(必須) (2017-09-30 20:05) 

vwqefloanoYZ

axcess payday loans
<a href="https://installmentloanvelam.com">bad credit installment loans</a>
canadian payday advance
<a href=https://installmentloanvelam.com>get installment loan</a> ’
by vwqefloanoYZ (2017-10-01 09:49) 

FvrcJidilsHZ

loan consolidation
<a href="https://cashadvanceamericasev.org">payday loans online direct lenders only</a>
payday loans no faxing
<a href=https://cashadvanceamericasev.org>cash advance credit card</a> ’
by FvrcJidilsHZ (2017-10-01 10:56) 

お名前(必須)

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

お名前(必須)

buy cialis online doctor - http://cialisovnnc.com/
cialis use in women <a href=http://cialisovnnc.com/>cialis buy</a> ’
by お名前(必須) (2017-10-02 03:52) 

お名前(必須)

cialis canada price - http://cialisofkl.com/
generic cialis price <a href=http://cialisofkl.com/>cialis 20mg</a> ’
by お名前(必須) (2017-10-02 05:18) 

お名前(必須)

mail order cialis - http://cialisivndh.com
cialis soft tabs uk <a href=http://cialisivndh.com>generic cialis</a> ’
by お名前(必須) (2017-10-02 07:48) 

お名前(必須)

best payday loan lender
<a href="https://paydayllae.com/">best payday loans</a>
loans personal loans
<a href=https://paydayllae.com/>best payday loans</a> ’
by お名前(必須) (2017-10-03 23:03) 

お名前(必須)

applying for a payday loan
<a href="https://cashadmme.com/">payday loan lenders</a>
best payday loans
<a href=https://cashadmme.com/>payday day loans</a> ’
by お名前(必須) (2017-10-04 01:52) 

お名前(必須)

500 payday loans
<a href="https://cashnowemr.com">cash advance</a>
loan cash
<a href=https://cashnowemr.com>bad credit payday loans</a> ’
by お名前(必須) (2017-10-04 04:07) 

JtnbJidilsRF

apply for payday loan
<a href="https://paydayloamec.com/">loans online</a>
100 approval bad credit payday loans
<a href=https://paydayloamec.com/>cash advance online</a> ’
by JtnbJidilsRF (2017-10-04 13:52) 

お名前(必須)

easy get payday loans - https://paydayllae.com/
advance cash payday loan <a href=https://paydayllae.com/>3 month payday loans</a> ’
by お名前(必須) (2017-10-05 06:53) 

お名前(必須)

guaranteed loan approval online - https://cashadmme.com/
cash loans online no credit check <a href=https://cashadmme.com/>payday day loans</a> ’
by お名前(必須) (2017-10-05 09:34) 

お名前(必須)

personal loans no credit - https://cashnowemr.com
small loans for bad credit <a href=https://cashnowemr.com>get payday loan</a> ’
by お名前(必須) (2017-10-05 11:39) 

お名前(必須)

buy cialis without prescription - https://buybuybuycialis.com/
cialis over the counter <a href=https://buybuybuycialis.com/>cialis online</a> ’
by お名前(必須) (2017-10-06 20:59) 

お名前(必須)

cialis in canada - https://cheapcheapcialis.com/
cialis tablets side effects <a href=https://cheapcheapcialis.com/>cheap cialis</a> ’
by お名前(必須) (2017-10-06 22:23) 

お名前(必須)

loans poor credit
<a href="https://paydayloawdcr.com/">payday loans no credit check</a>
debt help
<a href="https://paydayloawdcr.com/">payday loans</a> ’
by お名前(必須) (2017-10-08 06:13) 

お名前(必須)

generic brand for cialis
<a href="https://onlineonlinecialis.com/">generic cialis</a>
cheap cialis india
<a href=https://onlineonlinecialis.com/>generic cialis</a> ’
by お名前(必須) (2017-10-08 06:13) 

お名前(必須)

best personal loans bad credit
<a href="https://paydayloansrvhj.com/">payday loans online</a>
bad credit payday loan lenders
<a href=https://paydayloansrvhj.com/>payday loans near me</a> ’
by お名前(必須) (2017-10-08 09:07) 

お名前(必須)

consolidate debt
<a href="https://cashcevth.com">instant payday loans</a>
cash loans online no credit check
<a href=https://cashcevth.com>payday loans</a> ’
by お名前(必須) (2017-10-08 11:19) 

お名前(必須)

payday loans bad credit
<a href="https://cashecbya.com/">payday loans online</a>
bad credit loans for military payday loans for mil
<a href=https://cashecbya.com/>best payday loans</a> ’
by お名前(必須) (2017-10-09 08:49) 

お名前(必須)

generic cialis fast shipping - http://buycialis-menedpil.com/
compare generic cialis prices <a href="http://buycialis-menedpil.com/">cheap cialis online</a> ’
by お名前(必須) (2017-10-11 04:03) 

お名前(必須)

cialis canada no prescription - http://cialisonline-pricepil.com/
order cialis professional <a href=http://cialisonline-pricepil.com/>purchase cialis</a> ’
by お名前(必須) (2017-10-11 06:51) 

お名前(必須)

cialis 5 mg daily - http://onlinecialis-cialisvip.com
buy cialis mexico <a href=http://onlinecialis-cialisvip.com>purchase cialis</a> ’
by お名前(必須) (2017-10-11 09:37) 

AqrhdAccurlDI

cialis doses - http://genericcialis-viaed.com/
cialis.com free offer <a href=http://genericcialis-viaed.com/>cheap cialis</a> ’
by AqrhdAccurlDI (2017-10-11 18:51) 

お名前(必須)

buy cialis from canada
<a href="http://buycialis-menedpil.com/">buy cialis</a>
cialis for sale online
<a href="http://buycialis-menedpil.com/">generic cialis</a> ’
by お名前(必須) (2017-10-12 06:59) 

お名前(必須)

cialis online prescription
<a href="http://cialisonline-pricepil.com/">generic cialis</a>
buy cialis online doctor
<a href=http://cialisonline-pricepil.com/>cialis online</a> ’
by お名前(必須) (2017-10-12 09:20) 

お名前(必須)

cialis overdose
<a href="http://onlinecialis-cialisvip.com">cialis</a>
cialis generico
<a href=http://onlinecialis-cialisvip.com>cheap cialis</a> ’
by お名前(必須) (2017-10-12 12:07) 

お名前(必須)

1000 faxless payday loan - https://paydayobns.com/
1000 online payday loan <a href="https://paydayobns.com/">payday loans online</a> ’
by お名前(必須) (2017-10-18 00:54) 

お名前(必須)

cash call payday loans - https://paydayceinf.org/
payday loan cash advance <a href=https://paydayceinf.org/>payday loans online</a> ’
by お名前(必須) (2017-10-18 00:54) 

お名前(必須)

guaranteed loan approval online - https://loans7foal.com/
cash advance payday loan <a href=https://loans7foal.com/>cash advance usa</a> ’
by お名前(必須) (2017-10-18 01:57) 

お名前(必須)

bad credit cash fast payday loan loans - https://loanscerj.com/
no credit check online payday loans <a href=https://loanscerj.com/>payday loans</a> ’
by お名前(必須) (2017-10-18 03:00) 

お名前(必須)

1000 payday loan - https://loans24rjn.com/
fast cash loans <a href=https://loans24rjn.com/>payday loans online same day</a> ’
by お名前(必須) (2017-10-18 14:35) 

お名前(必須)

easy online payday loans - https://loansnzyr.com/
best payday loans <a href=https://loansnzyr.com/>payday loan</a> ’
by お名前(必須) (2017-10-18 17:32) 

お名前(必須)

bad credit no fax payday loan
<a href="https://paydayobns.com/">same day payday loan</a>
payday loan company in
<a href="https://paydayobns.com/">bad credit payday loans</a> ’
by お名前(必須) (2017-10-19 06:03) 

お名前(必須)

national debt relief
<a href="https://paydayceinf.org/">loans payday</a>
poor credit loans
<a href=https://paydayceinf.org/>payday loans</a> ’
by お名前(必須) (2017-10-19 06:03) 

お名前(必須)

speedy cash
<a href="https://loans7foal.com/">online payday loans</a>
cash loan advance
<a href=https://loans7foal.com/>payday loans online</a> ’
by お名前(必須) (2017-10-19 14:38) 

お名前(必須)

loan calculators
<a href="https://loansnerc.org/">payday loans online</a>
apple fast cash payday loan
<a href=https://loansnerc.org/>loans payday</a> ’
by お名前(必須) (2017-10-20 07:56) 

お名前(必須)

fast online payday loans
<a href="https://loanenav.net/">loans payday</a>
cash now
<a href=https://loanenav.net/>online payday loan</a> ’
by お名前(必須) (2017-10-20 18:21) 

お名前(必須)

cialis original - http://doverpharma.com/
cialis price comparison <a href=http://doverpharma.com/>Cialis online prescription</a> ’
by お名前(必須) (2017-10-20 23:17) 

お名前(必須)

cialis soft tabs cheap - http://pillsme.com/
buy cialis online without prescription <a href="http://pillsme.com/">cialis online</a> ’
by お名前(必須) (2017-10-21 00:49) 

お名前(必須)

generic cialis tadalafil - http://509pharma.com
cialis best price <a href=http://509pharma.com>CIALIS 20MG</a> ’
by お名前(必須) (2017-10-21 05:56) 

コメントを書く

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

トラックバック 0

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