Skip to content

Instantly share code, notes, and snippets.

@mokjpn
Last active February 18, 2016 23:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokjpn/6b0d15c374eadc32734f to your computer and use it in GitHub Desktop.
Save mokjpn/6b0d15c374eadc32734f to your computer and use it in GitHub Desktop.
Read Temperature from GROVE analog Temperature Module.
# GROVEシステムの温度センサモジュールから温度を読み込んでkonashi経由で表示
- [GROVEシステムの温度センサモジュール](http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor) から温度を読み込んで表示します.
[GROVE拡張ボード](http://yukaishop.base.ec/items/219896) のA0ポートに温度センサモジュールを接続して実行してください.
.content {
margin: 10px;
}
#values {
display: none;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=2, minimum-scale=1, maximum-scale=1, user-scalable=no">
<!-- ratchet css -->
<link rel="stylesheet" href="http://jsrun.it/assets/h/F/P/P/hFPPa">
</head>
<body>
<header class="bar-title">
<h1 class="title">konashi.js: Read Temperature</h1>
</header>
<div class="content">
<ul id="values" class="list inset">
<li>Temperature: <span id="temperature"></span> ℃</li>
<li>Resistance: <span id="resistance"></span> Ω</li>
<li>a: <span id="a"></span> </li>
<li>data: <span id="data"></span> mV</li>
</ul>
</div>
<!-- for konashijs -->
<script src="http://konashi.ux-xu.com/kjs/konashi-bridge.min.js"></script>
<!-- for this sample -->
<!-- zepto -->
<script src="http://jsrun.it/assets/1/M/0/f/1M0fl"></script>
<!-- touch.js -->
<script src="http://jsrun.it/assets/g/s/1/M/gs1MI"></script>
<!-- ratchet.js -->
<script src="http://jsrun.it/assets/g/3/W/u/g3WuF"></script>
</body>
</html>
// forked from kotobuki's "Analog IO" http://jsdo.it/kotobuki/mCc7
// forked from kotobuki's "Digital IO" http://jsdo.it/kotobuki/lbRn
// forked from monakaz's "LEDをコントロールしちゃおう☆" http://jsdo.it/monakaz/w1gz
$(function() {
var intervalId;
// 接続が完了したら以下の処理を行う
k.on("ready", function() {
// アナログIOの状態を表示
$("#values").show();
intervalId = window.setInterval(function() {
//k.grove.analogReadRequest(k.grove.A0);
k.analogReadRequest(k.AIO0);
}, 100);
});
k.updateAnalogValueAio0(function(data) {
var a, B, R1, resistance, temperature;
a = data;
B = 3975; // サーミスタのB係数はGroveのWikiにあるArduino用のサンプルプログラムより
// resistance = 10000; テスト用
R1 = 9880; // Grove Temperatureモジュール上のR1(実測値)
// resistance = R1 * a / (1300 - a) ; // Konashiアナログ入力の基準電圧 1.3V とR1 より,サーミスタの抵抗値を計算.
// でもArduinoではアナログ入力は基準電圧に対する相対値だけど,Konashiでは絶対値であるし,Grove拡張ボードないでアナログ入力からさらに抵抗をかませてあるので,念のため計算してみた
var Vcc, Vport, R3, R4, R34;
Vcc = 3000 ; // Grove拡張ボードのアナログ端子のVccは3V
Vport = a;
R3 = 5100; // Grove拡張ボードでA00入力とKonashi CN15の2番ピンの間にある抵抗
R4 = 3900; // Grove拡張ボードでKonashi CN15の2番ピンからGNDの間にある抵抗
R34 = R3+R4; // 式を簡単にするため
resistance = ( Vcc - Vport - Vport*R3/R34) / (Vport*R3/(R1*R34) + Vport/R1 + Vport/R34);
temperature = 1 / (Math.log(resistance / 10000) / B + 1 / 298.15) - 273.15; // サーミスタの抵抗値から温度へ変換(GroveのWikiにあるArduino用のサンプルプログラムより)
$("#data").html(data);
$("#a").html(a);
$("#resistance").html(resistance);
$("#temperature").html(temperature);
});
// konashiボードの検索を開始
k.find();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment