// D6T-8L-09 8ch 非接触温度センサ プログラム // GND, VCC(5V), SDA(8), SCL(7) // D6T-8L-09のデータ長は19byte // PTAT センサ内部の参照温度データ 2byte // P0 ~ P7 8ch分の温度データ 8x2byte // PEC(Packet error check code) 2byte : プログラム内では未使用 // --------------------------------------- // PTAT 16bit符号付き整数 LOW, HIGHの並び // P0 ~ P7 8ch分の温度データ 8x2byte LOW, HIGHの並び #include #include #define D6T8L09_ADRS 0x0A #define D6T8L09_CMD 0x4C #define D6T8L09_MAX 19 // PTAT(2) + P0-P7(16) + STOP(1) #define D6T8L09_DATA 16 // P0-P7(16) void D6T8L09_OutputData( void ); int rbuf[ D6T8L09_MAX ]; float tdata[ D6T8L09_DATA ]; float tPTAT; char msg[128]; void setup() { Wire.begin(); Serial.begin( 9600 ); } void loop() { int i, count; Wire.beginTransmission( D6T8L09_ADRS ); Wire.write( D6T8L09_CMD ); Wire.endTransmission(); count = Wire.requestFrom( D6T8L09_ADRS, D6T8L09_MAX ); if ( count >= 0 ) { for ( i = 0; i < D6T8L09_MAX; i++ ) { rbuf[ i ] = Wire.read(); } Wire.endTransmission(); tPTAT = ( rbuf[ 0 ] + (rbuf[ 1 ]*256) ) * 0.1; for ( i = 0; i < D6T8L09_DATA; i++) { tdata[ i ] = ( rbuf[ (i*2)+2 ] + ( rbuf[(i*2)+3]*256 ) ) * 0.1 - tPTAT; } D6T8L09_OutputData(); } delay(5000); } void D6T8L09_OutputData() { int i; sprintf( msg, "[PTAT:%3.1f] ", tPTAT ); Serial.print( msg ); for ( i = 0; i < 7; i++) { sprintf( msg, "%3.1f, ", tdata[i] ); Serial.print( msg ); } sprintf( msg, "%3.1f ", tdata[7] ); Serial.println( msg ); }