How to Resolve DHT22 Sensor Driver Binding Issue with Zephyr OS on AVR32UC?

Hello guys, I've been working on integrating the DHT22 sensor driver with Zephyr OS on the AVR32UC microcontroller, but currently, I'm struggling with the sensor driver binding. Despite my efforts, I keep encountering the error: Failed to bind DHT22 sensor. Here's a snippet of my code:
#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>

const struct device *sensor_dev;

void main(void)
{
sensor_dev = device_get_binding(DT_LABEL(DT_INST(0, ams_dht22)));
if (!sensor_dev) {
printk("Failed to bind DHT22 sensor\n");
return;
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>

const struct device *sensor_dev;

void main(void)
{
sensor_dev = device_get_binding(DT_LABEL(DT_INST(0, ams_dht22)));
if (!sensor_dev) {
printk("Failed to bind DHT22 sensor\n");
return;
}
}
I've made sure the DHT22 sensor driver is included and configured in prj.conf, checked the device tree (dts file) for the correct sensor definitions, and verified that the driver is supported and enabled for the AVR32UC. Despite this, I can't seem to get it to bind properly. How can I resolve this issue and successfully bind the DHT22 sensor driver, Anyone?
10 Replies
melta101
melta1015mo ago
could you show me the dts file?
Camila_99$$
Camila_99$$5mo ago
Yes like @melta101 said could you share the relevant parts of your dts file and prj.conf
Enthernet Code
Enthernet Code5mo ago
@Dtynin The code snippet you posted looks fine at first glance, but there are a few things we can check. Could you provide your prj.conf and the relevant section of your device tree file? This will help identify if there's something missing or misconfigured.
Enthernet Code
Enthernet Code5mo ago
make sure that the ams_dht22 is correctly defined in the device tree. Sometimes, the node label might be different. Can you re-check the node label in your device tree?
Dtynin
Dtynin5mo ago
@Enthernet Code @melta101 @Camila_99$$ , sure here is my prj.conf file
CONFIG_SENSOR=y
CONFIG_DHT=y
CONFIG_DHT_TRIGGER=y
CONFIG_SENSOR=y
CONFIG_DHT=y
CONFIG_DHT_TRIGGER=y
and here is the relevant section of my device tree file
&gpio0 {
status = "okay";
dht22: dht22 {
compatible = "ams,dht22";
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
};
};
&gpio0 {
status = "okay";
dht22: dht22 {
compatible = "ams,dht22";
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
};
};
melta101
melta1015mo ago
i would say, to use label instead of using instance if you are using only 1 sensor
melta101
melta1015mo ago
Also which particular are you using, would like to see it's dts file
Dtynin
Dtynin5mo ago
@Enthernet Code @melta101 I managed to fix the DHT22 sensor integration issues, I checked the GPIO controller settings and flags, and realized I needed an extra flag for input configuration. After adding an additional flag for the GPIO input configuration, and ensuring the device tree's node label and compatible string matched.
Dtynin
Dtynin5mo ago
I made sure the device tree label matched the driver’s needs and added the necessary label property. I also turned on detailed logging, did a full rebuild of the project, and updated the DTS file. Now, the DHT22 sensor works perfectly. Thanks a lot for your help now I can proceed:salute:
melta101
melta1015mo ago
That's great!!:1010:
Want results from more Discord servers?
Add your server