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?

Arduino UNO 3,I2C温度センサー PJ85775P で遊ぶ。(単精度浮動小数点)

0
Last updated at Posted at 2026-05-30

Screenshot From 2026-05-30 20-12-19.png



//I2C_PJ85775P_TEST_float1_UNO3_1
//2 byte Read


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


//定義
#define I2C_ADD 0x4F  //PJ85775P I2C Address


//初期化
void setup() {

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

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

}  //setup


//サブアドレス指定で2バイト読み込み in The sub address
unsigned short Read2(int sub_add) {

  //サブアドレスの書き込み
  Wire.beginTransmission(I2C_ADD);  // transmit to device I2C_ADD
  Wire.write(sub_add);              // sends one byte
  Wire.endTransmission();           // stop transmitting

  //2バイト読み込み
  Wire.requestFrom(I2C_ADD, 2);                          // request 2 bytes from slave device I2C_ADD
  unsigned short re = (Wire.read() << 8) | Wire.read();  // receive 2 byte as character

  return (re);

}  //Read2


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

  //データの読み込み
  unsigned short re = Read2(0); //READ TMP DATA

  //re = 0xE700;   //-25
  //re = 0x1900;   //25
  //re = 0;
  //re = 0xfff0;   //-0.0625
  //re = 0xffc0;   //-0.250
  //re = 0xff00;   //-1.00
  //re = 0x1940;   //25.25 // >>4 = 404

  //re = 0xFFF0;
  //re = 0x7FF0;
  //re = 0x8000;
  // //Serial.printf("re = %d\n",re/16); //ESP32,STM32
  //Serial.print("re = ");Serial.println(re/16);

  //温度を表示する
  long a = (re >> 4) & 0xFFF;         //4ビットシフトして有効12ビットを取り出す。
  if (a > 0x7FF) { a = a - 0x1000; }  //符号の処理 0x7FF(2047)より大きい、0x1000(4096)引く
  a = a * 625;                        // a * (1 / 16 * 10000)  // 0.0625

  float tmp = a;  //オートキャストして代入
  tmp = tmp / 10000.0f;

  //表示
  //Serial.printf("%f\n", tmp); //ESP32,STM32
  Serial.println(tmp);

  //1秒待つ
  delay(1000);  // Wait 1 seconds for next

}  //loop



github

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?