#include OneWire ds(4); //D2 GPIO4 DS18B20 IN OUT void setup() { Serial.begin(115200); delay(1000); } void loop() { // put your main code here, to run repeatedly: getROMCode(); delay(10000); } void getROMCode(void) { byte i,i1; byte addr[8]; //ROMCode格納変数 Serial.println(""); Serial.println(""); Serial.print(" ====================== DS18B20 Getting the ROMCode ======================\n\r"); Serial.println(" 8bitFamilyCode | 48bit SerialNumber | 8bit CRC"); while(ds.search(addr)) { Serial.print("No"); Serial.print(++i1); Serial.print(" Search ROMCode is:\t"); for( i = 0; i < 8; i++) { Serial.print("0x"); if (addr[i] < 16) { Serial.print('0'); } Serial.print(addr[i], HEX); if (i < 7) { Serial.print(", "); } } if ( OneWire::crc8( addr, 7) != addr[7]) { Serial.print("CRC is not valid!\n"); return; } Serial.println(""); } ds.reset_search(); return; }