Dtynin
Dtynin
GPIO Pin Configuration Error for DHT22 on AVR32UC with Zephyr OS
After checking the GPIO controller capabilities and flags, I realized I needed an additional flag for the input configuration. Here’s the updated code:
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define DHT22_PIN 2
#define GPIO_PORT DT_LABEL(DT_NODELABEL(gpio0))

const struct device *gpio_dev;

void main(void)
{
printk("Starting DHT22 sensor integration\n");

gpio_dev = device_get_binding(GPIO_PORT);
if (!gpio_dev) {
printk("Failed to bind GPIO device: %s\n", GPIO_PORT);
return;
} else {
printk("Successfully bound to GPIO device: %s\n", GPIO_PORT);
}

int ret = gpio_pin_configure(gpio_dev, DHT22_PIN, GPIO_INPUT | GPIO_PULL_UP);
if (ret < 0) {
printk("Failed to configure GPIO pin %d, error: %d\n", DHT22_PIN, ret);
} else {
printk("Successfully configured GPIO pin %d\n", DHT22_PIN);
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define DHT22_PIN 2
#define GPIO_PORT DT_LABEL(DT_NODELABEL(gpio0))

const struct device *gpio_dev;

void main(void)
{
printk("Starting DHT22 sensor integration\n");

gpio_dev = device_get_binding(GPIO_PORT);
if (!gpio_dev) {
printk("Failed to bind GPIO device: %s\n", GPIO_PORT);
return;
} else {
printk("Successfully bound to GPIO device: %s\n", GPIO_PORT);
}

int ret = gpio_pin_configure(gpio_dev, DHT22_PIN, GPIO_INPUT | GPIO_PULL_UP);
if (ret < 0) {
printk("Failed to configure GPIO pin %d, error: %d\n", DHT22_PIN, ret);
} else {
printk("Successfully configured GPIO pin %d\n", DHT22_PIN);
}
}
Now it’s working perfectly. Thanks for the help! @Dark AI
5 replies