LoginSignup
0
0

STM32G031とMCP9701で温度をPA2ハードウェアシリアルに出力

Last updated at Posted at 2022-06-02

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

x 動作確認済み2022/6/3 18:46

x あまり正確では、ない

目的
秋月で売っている安価なMCP9701(約25円)を使って温度を出力する。

構成
MCP9701-E/TO I-03199

説明
MCP9701は、
0℃の時、400mV
1℃あたり19.5mV
精度は、±4℃
電線が引き出しやすい位置のPA4をアナログ入力にする
計算には、容量削減の為に浮動小数点となるべく割り算は、使わない
MCP9700は、ファミリー、オフセット500mV、10mV/1℃ 今回は、使わない

19.5は、1℃あたりの電圧
3300は、ADCの電圧
400は、0℃

3300/19.5=169.2
400/19.5=20.5

(4096*1692)/4096=1692

o_con516.jpg



//S_SER_9701_V2_031_2


#include <Arduino.h>
#include <HardwareSerial.h>

//10の割り算 0から1028までは、正しい。主に0から999
#define DIV10(n) ((n*205)>>11)


//初期化
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(A3);   // PA11 PIN5 031

  //電圧を温度に変換 ex 20.0 -> 200 温度の十倍を出力
  s = ((s * 1692) >> 12) - 205;

  //温度の表示
  Serial.print( DIV10(s) );            // 小数点以上
  Serial.print(".");
  Serial.print( s - (DIV10(s) * 10) ); // 小数点以下
  Serial.println();

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