2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

I2C温度センサー PJ85775P で遊ぶ。(表引きバージョン)小数点

Last updated at Posted at 2025-07-01

いろいろ注意

  • 過去ログを見よ

結果

o_coq907.jpg

o_coq908.jpg

image_original - 2025-06-24T150752.744.jpg

o_coq904.jpg

プログラム



//I2C_PJ85775P_TEST4_UNO_1
//2 byte Read


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


//定義
#define I2C_ADD 0x4F

char tmp_t[] = {
"-9.5-9.0-8.5-8.0-7.5-7.0-6.5-6.0-5.5-5.0"
"-4.5-4.0-3.5-3.0-2.5-2.0-1.5-1.0-0.500.0"
"00.501.001.502.002.503.003.504.004.505.0"
"05.506.006.507.007.508.008.509.009.510.0"
"10.511.011.512.012.513.013.514.014.515.0"
"15.516.016.517.017.518.018.519.019.520.0"
"20.521.021.522.022.523.023.524.024.525.0"
"25.526.026.527.027.528.028.529.029.530.0"
"30.531.031.532.032.533.033.534.034.535.0"
"35.536.036.537.037.538.038.539.039.540.0"
"40.541.041.542.042.543.043.544.044.545.0"
"45.546.046.547.047.548.048.549.049.550.0"
"50.551.051.552.052.553.053.554.0"
};


//初期化
void setup() {

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

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


//サブアドレス指定で2バイト読み込み
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);

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

  //読み込みデータの出力 debug
  //Serial.println( re  , HEX); //debug

  //4ビットシフトして有効12ビットを取り出す。
  re = (re >> 4) & 0x0fff;

  //符号あり温度変数に変換する
  int tmp = re - ((re & 0x800) << 1);
  //Serial.println( tmp  , HEX); //debug
  //Serial.println( tmp ); //debug

  //さらに3ビット削る 符号の処理がめんどくさいので単に割る
  tmp = tmp / 8;
  //Serial.println( tmp );
  //Serial.println( tmp * 5 );

  //表引きで温度を表示する
  int a = (tmp + 19) & 0x7f;
  Serial.print(tmp_t[a*4+0]);
  Serial.print(tmp_t[a*4+1]);
  Serial.print(tmp_t[a*4+2]);
  Serial.print(tmp_t[a*4+3]);
  Serial.println();

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

} //loop



2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?