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?

STM32F767と温度センサーMCP9700で温度をシリアル出力 (Arduino)

Last updated at Posted at 2025-01-12

参考

o_coq777.jpg

x 過去ログを見ょ!!!
x 負の数は、かんがえない!!!
x 例題の為に完全性は、求めない!!!
x MCP9700は、MCP9700T-E/TTのこと

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

無意味に
●軽量
●高速化
●見やすさ重視
(f767にハードウェア除算ある為?積極的に割り算を使う)

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

Screenshot from 2025-01-13 06-46-37.jpg

image_original.jpg

プログラム



//ser_mcp9700_stm32f767_1


//インクルド
#include <Arduino.h>


//初期化
void setup() {

  //シリアルポートの初期化
  Serial.begin(9600);

}  //setup


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

  //温度センサーから電圧を入力する(3.3Vを4096に分解した値)
  analogReadResolution(12);  //センサーの分解度4096
  int s = analogRead(A0);    //センサーの値


  //電圧を温度に変換 ex 20.0 -> 200 温度の十倍を出力
  s = (s * 3300) >> 12;       // s = s * 3300 / 4096 電圧こと
  int temperature = s - 500;  //0℃にするため500引く


  //温度を文字列に変換する
  char data[16];                     //出力用文字列
  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);


  //1秒の待ち
  delay(1000);

}  //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?