1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(温度)M5NanoC6、MCP9700で遊ぶ。(MCP9700-E/TO)

Last updated at Posted at 2025-01-10

x 過去ログを見ょ!!!
x 3.1.1
x なぜか、M5NanoC6は、電圧の値が入力される

目的
MCP9700の電圧を測って500引いた値の温度を
内蔵シリアルからパソコンで表示する。
printfは、esp32 arduinoでは、使えるが
ここは、あえて、

無意味に
●軽量
●高速化
●見やすさ重視
(M5NanoC6にハードウェア除算ある為?積極的に割り算を使う)
(M5NanoC6には、浮動小数点演算装置は、なさそう
(ラインナップ上、コスト重視ため?、中学の情報の授業では、
浮動小数点演算装置の面積は、CPUより大きいとされている?
(ようは、同じ面積からCPUが2個以上とれるため)))

MCP9700は、温度のアナログ出力ICで内部にオペアンプと
基準電圧?を持ち、多少、補正された値が出力される
リニアティー(値の直線性は、良い)
2Vぐらいから5Vぐらいの電源で使える
mVに対して1℃当たり10mVで10で割った値で温度(整数)になる
オフセット(0℃の中心点)は、500mVで単に500を引けばよい

o_coq776.jpg

image_original (26).jpg

(画像は、使い回し)

プログラム





//mcp9700_1_M5NanoC6_1


//ヘッダー
#include <Arduino.h>


//初期化
void setup(void) {

  //シリアルの初期化
  Serial.begin(9600);
  Serial.println("");

  //シリアルの待ちが0.5*9
  for (int i = 0; i < 9; i++) {
    delay(500); //接続待ち
    Serial.print(".");
  }//for

  Serial.println("");

}//setup


//メインループ
void loop(void) {

  char data[16];//出力用文字列

  //MCP9700の電圧を読み取り500引く事で固定小数点1個
  int temperature = analogRead(1) - 500; // x10
  //Serial.println(temperature); //debug

  data[4] = 0;//終端記号
  data[3] = '0' + temperature % 10; //小数点の値
  temperature = temperature / 10;
  data[2] = '.'; //小数点の区切り
  data[1] = '0' + temperature % 10; //整数1桁目(1の位)
  temperature = temperature / 10;
  data[0] = '0' + temperature;      //整数2桁目(10の位)

  //MCP9700の温度を小数点1桁で表示 ex 23.4
  Serial.println(data); //debug

  delay(1000);//1秒待つ

}//loop




1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?