Thanks @AchimKraus your devicetrees helped me a lot! In combination with a w1 scanner and by assigning each sensor one of the found values source here I was able to get the ROM values of each sensor. But when I measure it I get a result of 85 °C, indicating that there are some communication issues. I tested the exact setup I have with an raspberry pi (i took the wires from the feather and put it into the raspberry pi). On the pi everything works fine. I additionally added some capacitors to increase power stability but with no effect.
This is the serial output I get:
[00:00:15.264,251] <inf> main: Device found; family: 0x28, serial: 0x28ff6deda217043b
[00:00:15.284,576] <dbg> DS18B20: ds18b20_configure: Init DS18B20: ROM=28ff6deda217043b
85.0 Cel
[00:00:16.090,362] <inf> main: Device found; family: 0x28, serial: 0x28ff59bea21704f0
[00:00:16.110,687] <dbg> DS18B20: ds18b20_configure: Init DS18B20: ROM=28ff59bea21704f0
85.0 Cel
[00:00:16.916,381] <inf> main: Device found; family: 0x28, serial: 0x28ffe949a2170516
[00:00:16.936,798] <dbg> DS18B20: ds18b20_configure: Init DS18B20: ROM=28ffe949a2170516
85.0 Cel
[00:00:17.720,825] <inf> main: Number of devices found on bus: 3
And this the code i created:
void w1_search_callback(struct w1_rom rom, void* voiderment)
{
LOG_INF("Device found; family: 0x%02x, serial: 0x%016llx", rom.family, w1_rom_to_uint64(&rom));
const struct device *therm = DEVICE_DT_GET_ANY(maxim_ds18b20);
while (!device_is_ready(therm))
{
LOG_ERR("Device %s is not ready\n", therm->name);
}
struct sensor_value temperature;
w1_rom_to_sensor_value(&rom,&temperature);
sensor_attr_set(therm,SENSOR_CHAN_ALL,SENSOR_ATTR_W1_ROM,&temperature);
int fetch_result_code = sensor_sample_fetch(therm);
if (fetch_result_code != 0)
{
LOG_ERR("Sensor fetch failed: %d\n", fetch_result_code);
return;
}
fetch_result_code = sensor_channel_get(therm, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
if (fetch_result_code != 0)
{
LOG_ERR("get failed: %d\n", fetch_result_code);
return;
}
double thermDouble = sensor_value_to_double(&temperature);
printf("%.1f Cel\n", thermDouble);
}
// w1 scanner source: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/drivers/w1/scanner/src/main.c
static void w1_scanner(struct Measurement* msmnt)
{
const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(w1_0));
if (!device_is_ready(dev))
{
LOG_ERR("Device not ready");
return;
}
int w1_devices_amount = w1_get_slave_count(dev);
w1_search_rom(dev, w1_search_callback, msmnt);
LOG_INF("Number of devices found on bus: %d", w1_devices_amount);
}
Do you have any idea why I would the able to retrieve the ROM values but a measurement isn’t possible? I’m pretty stuck event though it fells like it’s just a small mistake.