Skip to content

Commit

Permalink
Update bbn_m5atomS3_lite_DS18B20.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Oct 24, 2024
1 parent 5dab381 commit e3255ff
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bbn_m5atomS3_lite_DS18B20/bbn_m5atomS3_lite_DS18B20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS G8
#define ONE_WIRE_BUS G8 // Pin to which 1wire bus is connected to esp32
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

Expand All @@ -16,12 +16,26 @@ void setup() {
Serial.printf("Sensors found %d\n", count);
}

void printAddress(DeviceAddress deviceAddress) {
for (uint8_t i = 0; i < 8; i++) {
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}

void loop() {
int count = sensors.getDeviceCount();
if (count > 0) {
sensors.requestTemperatures();
for (int i = 0; i < count; i++) {
Serial.printf("Temp %.2f\n", sensors.getTempCByIndex(i));
DeviceAddress addr;
if (!sensors.getAddress(addr, i)) {
Serial.println("Unable to find address for Device");
} else {
printAddress(addr);
}
Serial.printf(" Temp %.2f\n", sensors.getTempCByIndex(i));
}
}
delay(1000);
Expand Down

0 comments on commit e3255ff

Please sign in to comment.