#include <OneWire.h>
#include <DallasTemperature.h>
const int oneWireBus = 5;
//9F9D876799C4F808
//28C630D0020000F9
//28 C6 55 58 04 00 00 2E
//28 7C 0C D0 02 00 00 94
//28 57 27 D0 02 00 00 52
// OneWire oneWire(oneWireBus);
// DallasTemperature sensors(&oneWire);
// DeviceAddress tempDeviceAddress;
// void printFoundAddresses() {
// Serial.println("Знайдені адреси датчиків:");
// for (int i = 0; i < sensors.getDeviceCount(); i++) {
// sensors.getAddress(tempDeviceAddress, i);
// Serial.print("Датчик ");
// Serial.print(i);
// Serial.print(" : ");
// for (int j = 0; j < 8; j++) {
// if (tempDeviceAddress[j] < 16) Serial.print("0");
// Serial.print(tempDeviceAddress[j], HEX);
// Serial.print(" ");
// }
// Serial.println();
// }
// }
// void setup() {
// // put your setup code here, to run once:
// Serial.begin(115200);
// Serial.println("Hello, ESP32!");
// sensors.begin();
// sensors.setWaitForConversion(false);
// int deviceCount = sensors.getDeviceCount();
// // Виводимо адреси знайдених датчиків
// if (deviceCount > 0) {
// printFoundAddresses();
// } else {
// Serial.println("Датчики не знайдені");
// }
// }
// void loop() {
// // put your main code here, to run repeatedly:
// sensors.requestTemperatures();
// Serial.print("Temperature is: ");
// delay(10);
// Serial.println(sensors.getTempCByIndex(0));
// delay(5000);
// }
//--------------Experiment------------
OneWire ds(oneWireBus);
#define MAX_DS_SENSOR 4
byte addr[8];
byte arrayAddr[MAX_DS_SENSOR][8];
int numberOfDevices =0 ;
void clearArray(){
for (byte x =0 ; x < MAX_DS_SENSOR; x++){
for (byte a =0 ; a < 8; a++){
arrayAddr[x][a] = 0;
}
}
}
void serialPrintAddrHex() {
Serial.print(" Device found= ");
Serial.println(numberOfDevices);
for (int i=0 ; i < numberOfDevices ; i++){
Serial.print(" DEV=");
Serial.print(i);
Serial.print(" ROM=");
for (byte a = 0; a < 8; a++) {
Serial.write(" ");
Serial.print(arrayAddr[i][a], HEX);
}
}
Serial.println();
}
void scan1WireDevice(){
byte addr[8];
byte a;
clearArray();
Serial.print("\n Scan device- ");
for (byte i =0 ; i < MAX_DS_SENSOR ; i++){
if (!ds.search(addr)) {
Serial.println(" No more addresses.");
ds.reset_search();
numberOfDevices = i;
delay(250);
return;
}
Serial.print(i);
Serial.print(" ");
for (a =0 ; a < 8; a++){
arrayAddr[i][a] = addr[a];
}
}
Serial.print("End Scan");
}
void setup(void) {
Serial.begin(115200);
scan1WireDevice();
serialPrintAddrHex();
}
void loop(void) {
Serial.println("Loop");
delay(5000);
}