In both examples (single and multiple) sensors data pin is connected to GPIO15 on ESP32.
You may disable or enable logging in the library by setting LOGGING_ENABLED in the top of ds18b20.c file:
#define LOGGING_ENABLED 0 // logging disabled
#define LOGGING_ENABLED 1 // logging enabled
if (ds18b20_init(15) == true) {
ESP_LOGI(TAG, "Initialization completed.");
}
else {
ESP_LOGI(TAG, "Initialization failed!");
}
float temperature;
if (ds18b20_get_temperature(&temperature, NULL) == true) {
ESP_LOGI(TAG, "Temperature: %0.1f", temperature);
}
else {
ESP_LOGI(TAG, "Error reading temperature!");
}
if (ds18b20_set_thermometer_resolution(RES_11_BIT, NULL) == true) {
ESP_LOGI(TAG, "Successfully set temperature resolution to 11 bit.");
}
else {
ESP_LOGI(TAG, "Failed to set temperature resolution to 11 bit!");
}
if (ds18b20_set_alarm_temperature(30, -6, NULL) == true) {
ESP_LOGI(TAG, "Successfully set alarm temperatures.");
}
else {
ESP_LOGI(TAG, "Failed to set alarm temperatures!");
}
int8_t temperatureLow;
if (ds18b20_get_alarm_temperature_low(&temperatureLow, NULL) == true) {
ESP_LOGI(TAG, "Low alarm temperature: %d", temperatureLow);
}
else {
ESP_LOGI(TAG, "Failed to get a low alarm temperature!");
}
// Suppose we have 4 sensors
if (ds18b20_init(15) == true) {
ESP_LOGI(TAG, "Initialization completed.");
}
else {
ESP_LOGI(TAG, "Initialization failed!");
}
uint8_t address[4][8] = {0};
uint8_t numOfDevices = 0;
while (ds18b20_search_ROM(address[numOfDevices]) == true) {
numOfDevices++;
ESP_LOGI(TAG, "Found address number %d.", numOfDevices);
}
for (uint8_t i=0; i<numOfDevices; i++)
{
float temperature;
if (ds18b20_get_temperature(&temperature, address[i]) == true) {
ESP_LOGI(TAG, "Temperature of %d. sensor: %0.1f", i, temperature);
}
else {
ESP_LOGI(TAG, "Error reading temperature of sensor %d!", i);
}
}
if (ds18b20_set_thermometer_resolution(RES_9_BIT, address) == true) {
ESP_LOGI(TAG, "Successfully set temperature resolution to 9 bit.");
}
else {
ESP_LOGI(TAG, "Failed to set temperature resolution to 9 bit!");
}
if (ds18b20_set_alarm_temperature_high(28, address) == true) {
ESP_LOGI(TAG, "Successfully set alarm temperatures.");
}
else {
ESP_LOGI(TAG, "Failed to set alarm temperatures!");
}
uint8_t alarmAddress[8] = {0};
while (ds18b20_alarm_search(alarmAddress) == true) {
ESP_LOGI(TAG, "ALARM for address: %x%x%x%x%x%x%x%x", alarmAddress[0], alarmAddress[1], alarmAddress[2], alarmAddress[3], alarmAddress[4], alarmAddress[5], alarmAddress[6], alarmAddress[7]);
}