- 追加された行はこのように表示されます。
- 削除された行は
このように表示されます。
!! MCP9700 メモ
! 温度センサー ( -20~~+50 )
http://akizukidenshi.com/catalog/g/gI-03286/
! Pinアサイン
,1,2,3
,Vcc,out,GND
! メモ
温度が合わないので
out に 0.1uF でGND へ
https://os.mbed.com/users/strysd/notebook/analog_input_from_mcp9700_via_njm2732d/
を参考にテーブルで計算
1度C 10mV (3.3v/4095(12bit)で計算すると 12.409.. (273/22) になる
なので変換式は 5*(sv-620)/62.0 :: sv はAD変換値
// 実測では 5*(sv-630)/62.0 あたり??
// 10*(sv-630)/123.0 がなるけれど上の式がらくかな
,Celsius degree ,Vout from MCP9700,12bit_3v3_4095max,実測
,50 ,1000mV , 1240,1244
,40 ,900mV , 1116,1120
,30 ,800mV , 992,998
,20 ,700mV , 868,873
,10 ,600mV , 744,750
,0 ,500mV , 620,630
,-10 ,400mV
,-20 ,300mV
,-30 ,200mV
,-40 ,100mV
! サンプル(STM32F103C arduino ide)
#include <stdio.h>
int sensorPin = 2; // Select the input pin for the potentiometer
int sensorValue = 0; // Variable to store the value coming from the sensor
void setup() {
// Declare the sensorPin as INPUT_ANALOG:
pinMode(sensorPin, INPUT_ANALOG);
// Declare the LED's pin as an OUTPUT. (32 is a built-in
// constant which is the pin number of the built-in LED. On the
// Maple, it is 13.)
pinMode(32, OUTPUT);
//
Serial.begin(9600);
}
int sv;
float lsb = 3.3 / 4095 ;
void loop() {
sv=0;
// Read the value from the sensor:
int i;
for ( i = 0 ; i < 10 ; i++) {
sensorValue = analogRead(sensorPin);
sv = sv + sensorValue ;
delay(200);
}
sv = sv / i ;
//
// Turn the LED pin on:
digitalWrite(32, HIGH);
// Stop the program for <sensorValue> milliseconds:
// Serial.println(sv);
// ( ((sv/i)-620)/(273/22)); // 計算の簡易化;;
// Serial.print(",");
Serial.println( (22*(sv-620)/273.0),3);
// Serial.println( (((sv*lsb/i)-0.50)*100) ,3); // サンプル温度 小数点以下3桁
// Turn the LED pin off:
digitalWrite(32, LOW);
// Stop the program for for <sensorValue> milliseconds:
// delay(500);
}