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?

(SSD1306)M5NanoC6で温度を表示して遊ぶ。

Last updated at Posted at 2024-10-05

x 過去ログを見よ!!
x Arudinoで「新規タブ」の操作ができる人

参考

結果

o_coq489.jpg

プログラム

SSD1306_ADC_TMP1o2_M5NanoC6_1.ino



//SSD1306_ADC_TMP1o2_M5NanoC6_1


//ヘッダーファイル
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "nana_Grvove_Temperature1o2.h"
#include "nana_Grvove_ADC.h"


//定義
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


//初期化
void setup() {

  // I2Cアドレスは使用するディスプレイに合わせて変更する
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);

}//setup


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

  // 画面表示をクリア
  display.clearDisplay();

  // テキストサイズを設定
  display.setTextSize(3);
  // テキスト色を設定
  display.setTextColor(WHITE);
  // テキストの開始位置を設定
  display.setCursor(0, 10);

  //電圧を求める
  float Voltage; //電圧
  Voltage = nana_Grvove_ADC();
  //Voltage = 2.5; //debug

  //温度を求める
  float Temperature; //温度
  Temperature = nana_Grvove_Temperature1o2(Voltage);
  //Temperature= 46.0;   //46を設定 debug

  // 温度を表示
  display.println((int)Temperature);

  // 描画バッファの内容を画面に表示
  display.display();

  delay(1000); //1秒待つ

}//loop



nana_Grvove_ADC.h



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

//I2Cのアドレス
#define Addr 0x50

float nana_Grvove_ADC() {

  //内部アドレスの設定
  Wire.beginTransmission(Addr);
  Wire.write(0x00);
  Wire.endTransmission();
  delay(2);

  //データの読み込み
  Wire.requestFrom(Addr, 2);
  delay(1);
  int h, l;
  if (Wire.available() == 2) {
    h = Wire.read();
    l = Wire.read();
  }//endif
  delay(1);

  //値の変換
  int adc1 = ((h & 0x0F) << 8) + l;
  int vo = (adc1 * 6000) >> 12; // (adc1*(3/4096))*2

  return( ((float)vo) * 0.001 );
  
}



nana_Grvove_Temperature1o2.h



#include <math.h>

const int B = 4275;               // B value of the thermistor
const int R0 = 100000;            // R0 = 100k

float nana_Grvove_Temperature1o2(float Voltage){
    //入力は、電圧 出力は、温度
    //float R = 1023.0/a-1.0;
    //R = R0*R;
    float R,Current,Resistance; 
    Current = Voltage / 100000.0;   //電流を求める
    Resistance = 5.0 / Current;     //全体の抵抗を求める
    R = Resistance - 100000.0;      //全体の抵抗から検出抵抗を引く

    return( 1.0/(log(R/R0)/B+1/298.15)-273.15 ); // convert to temperature via datasheet

}



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?