LoginSignup
0
0

STM32G031と温度センサーMCP9701で温度をシリアル出力(浮動小数点使用)

Last updated at Posted at 2022-07-02

x MCP9701-E/TO 販売コード 103199

x PA2をGPIOにがわかる人むけ

目的
安価に温度を測る。

センター 400mV
ステップ 19.5mV 1℃

1 ADC
2 VDD
3 GND
4 Serial

8 SWD
7 SWD
6 未使用-未接続
5 未使用-未接続

o_con552.jpg



//SER_MCP9701_float_031_1

#include <Arduino.h>

//初期化処理
void setup()
{

  delay(3000); //not delete

  //シリアルの初期化
  Serial.setTx(PA2_ALT1);
  Serial.setHalfDuplex();
  Serial.begin(9600);

} //setup

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

  //センサーの値を読み込む
  analogReadResolution(12); // ADC 12bit mode
  int s = analogRead(A9);   // PB7  PIN1 031 センサーの読み取り値

  //センサーのADC値を電圧に変換
  float v = s * ( 3.3 / 4096.0 );

  //センサーの電圧を温度に変換
  float t = (v - 0.4) * (1.0 / 0.0195);

  //温度の表示
  Serial.println(t);

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

} //loop



0
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
0
0