MCP9701 温度チップを使用しています。MCP9701 は、Edison Arduino ブレークアウト ボードのピン A0、5v、およびグランドに接続されています。
出力温度は次のとおりです。
c: 25.4 f: 77.8
私の部屋の温度計は 71.8 を示し、Edison は私の部屋の温度を 77.8 と計算しています。私の部屋の温度は間違いなく77.8ではありません。
温度を 200.7 に変更してみsetBit(10)
ました。setBit(12)
また、setBit を 8 に変更した結果、-8 temp になりました。NodeJSを使用して適切な温度計算を取得するにはどうすればよいですか?
NodeJS コード:
var m = require('mraa');
var a0 = new m.Aio(0);
a0.setBit(10);
console.log("reading analog input>>>");
function CompareForSort(a,b) {
if (a == b)
return 0;
if (a < b)
return -1;
else
return 1;
}
function MedianRead(n, tempType) {
var myarr = [];
for(i=0; i<n; i++){
var v_out;
var temp;
v_out = a0.read();
v_out*=.0048;
v_out*=1000;
temp=0.0512 * v_out -20.5128;
var tempinf = temp * (9 / 5) + 32;
switch(tempType) {
case 'c':
myarr[i] = temp;
break;
case 'f':
myarr[i] = tempinf;
break;
default:
myarr[i] = temp;
}
}
myarr.sort(CompareForSort);
myarr.splice(n-2,2);
myarr.splice(0,2);
m=myarr.length;
var sum=myarr.reduce(function(a,b) {
return a+b;
});
var temp = sum/m;
var tempFixed = temp.toFixed(1);
console.log("Temp: " + temp + " Fixed Temp: " + tempFixed);
console.log(tempFixed);
}
setInterval(function() {
MedianRead(200, 'f');
}, 3000);