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

More than 1 year has passed since last update.

温度計を作る(STM32G071)(ILI9341)(S-5851A)

Last updated at Posted at 2024-01-23

温度計を作る(STM32G071)(ILI9341)(S-5851A)

目的
液晶のテスト

配線

3.3V - 3.3V
SCL - SCL
SDA - SDA
GND - GND

o_cop889.jpg

o_cop890.jpg

ili9341_s5851_071_1.ino


//ili9341_s5851_071_1

//インクルド
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

//センサーのアドレス
#define S5851A 0x48

//定義
char t_0001[][6] =
{
".0000", //0
".0625", //1
".1250", //2
".1875", //3
".2500", //4
".3125", //5
".3750", //6
".4375", //7
".5000", //8
".5625", //9
".6250", //10
".6875", //11
".7500", //12
".8125", //13
".8750", //14
".9375" //15
};

//設定
#define TFT_RST 54 //A1
#define TFT_DC 3
#define TFT_CS 4

//液晶の定義
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);


//初期化
void setup() {

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

  //I2Cの初期化
  Wire.begin();

  //液晶の初期化
  tft.begin();

  //画面のクリア
  tft.fillScreen(ILI9341_BLACK);
  
}//setup


//無限ループ
void loop(void) {


  //温度の読み込み
  char s1[2] = {0,0}; //センサーの値
  int ii=0;

  //0番目のレジスター 温度
  Wire.beginTransmission(S5851A);
  Wire.write(0);
  Wire.endTransmission();
  delay(1);
  //1
  Wire.requestFrom(S5851A, 2);
  s1[0]=99;s1[1]=0xc0;
  while(Wire.available())  {    // 要求より短いデータが来る可能性あり
    s1[ii++] = (int)Wire.read();       // 1バイトを受信
  }//while
  delay(1);


  //センサーの値を温度に変換
  //s1[0]=21;s1[1]=0x80;
  int d1 = s1[0];
  int d0001 = (s1[1]>>4)&0x0f;
  

  //温度の表示

  //クリア
  tft.fillRect( 0 ,0 , 24*6 , 24 , ILI9341_BLACK);

  //表示位置を0,0にする
  tft.setCursor(0, 0);

  //テキストの表示
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(3);
  tft.print(" ");
  tft.print(d1);
  //tft.print(".");
  tft.print(t_0001[d0001]);
  tft.print(" ");

  delay(1000); //1秒待つ

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?