[[FrontPage]]

#contents

2013/05/25からのアクセス回数 &counter;

Arduino in Actionの7章に出てくる例題を試してみました。

** LCDに出力 [#b021bad1]
電子工作では必ずでてくるLCD出力ですが、私は後閑さんの本で紹介されている
大型のLCDを使い回しています。((半固定抵抗をLCDに付けているので便利です))

&ref(Bread7_1.png);


図7.1の回路を見ながら結線します。ブレッドボード上にLCD接続用の回路を
組んでおくと便利です。

&ref(Fig7_1.png);


*** 動作確認 [#c9146160]
テスト用のスケッチは、以下の通りです。

#pre{{
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Arduino in");
  lcd.setCursor(0,1);
  lcd.print("Action Rocks!");
}

void loop() {
}
}}


** One Wire温度計 [#yc425f23]
何とか
[[One Wire LCD>Arduino/Sparkfunのライブラリーで使えるOne Wire LCD]]
ができたので、7.3節の Werial LCD weather stationを作ってみます。

OneWireの温度センサーのDS18B20は、秋月で300円で購入しました。

Arduinoでこのセンサーを使えるように
[[Dallas Temperature Control Library>http://milesburton.com/Dallas_Temperature_Control_Library]]
と
[[OneWire Library>http://www.pjrc.com/teensy/td_libs_OneWire.html]] 
を使用します。

*** 回路 [#lf06d82b]
回路は、図7.4の通りに作成します。R1は、4.7KΩを使用します。

&ref(Fig7_4.png);

DS18B20のピンと番号の対応は、以下の様になっています。

&ref(DS18B20_pin.png);


*** スケッチと動作確認 [#f6e0303c]
スケッチは、以下の通りです。

#pre{{
#include <serLCD.h>
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 8

serLCD myLcd(12);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void){
  Serial.begin(9600);
  sensors.begin();
  myLcd.clear();
}

void displayTemperature(int sensorIndex) {
  myLcd.clear();
  float tempInCel = sensors.getTempCByIndex(sensorIndex);
  myLcd.setCursor(1,1);
  myLcd.print("C: ");
  myLcd.print(tempInCel, 1);
  myLcd.setCursor(2,1);
  myLcd.print("F: ");
  float tempInFar = DallasTemperature::toFahrenheit(tempInCel);
  myLcd.print(tempInFar, 1);
}

void loop(void) {
  sensors.requestTemperatures();
  displayTemperature(0);
  delay(2000);
}
}}

ブレッドボードで動作確認をしました。

&ref(Bread7_4.png);

** コメント [#lc885b54]
#vote(おもしろかった[1],そうでもない[0],わかりずらい[0])

皆様のご意見、ご希望をお待ちしております。
#comment_kcaptcha

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
SmartDoc