Skip to content

mingyo186/dht22_env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DHT22 Environmental Sensor — ROS2 Jazzy Driver (GPIO)

ROS2 Jazzy driver for the DHT22 (AM2302) temperature and humidity sensor over a single GPIO pin.

Features

  • Publishes sensor_msgs/Temperature on dht22/temperature
  • Publishes sensor_msgs/RelativeHumidity on dht22/humidity
  • fake_mode for testing without hardware (random Gaussian data)
  • BCM GPIO pin configurable (default: GPIO4)
  • Runtime publish_rate change via ros2 param set
  • Calibration and reset services

Why this package?

There is also a dht11_env driver for DHT11. The DHT22 provides significantly better specifications:

Feature DHT11 (dht11_env) DHT22 (this package)
Temperature range 0 ~ 50 °C -40 ~ 80 °C
Temperature accuracy ±2 °C ±0.5 °C
Humidity range 20 ~ 90 %RH 0 ~ 100 %RH
Humidity accuracy ±5 %RH ±2-5 %RH
Max sampling rate ~1 Hz ~0.5 Hz
Resolution 1 °C / 1 %RH 0.1 °C / 0.1 %RH

Choose dht11_env for low-cost prototyping where accuracy is not critical. Choose this package for better accuracy and wider measurement range.

Prerequisites

  • ROS 2 Jazzy
  • Python 3
  • Real hardware only:
    • adafruit-circuitpython-dht (pip install adafruit-circuitpython-dht)
    • libgpiod2 (sudo apt install libgpiod2)

Installation

cd ~/ros2_ws colcon build --packages-select dht22_env --symlink-install source install/setup.bash

Usage

Launch (fake mode — default)

ros2 launch dht22_env dht22_launch.py

Run node directly

ros2 run dht22_env dht22_node.py

Real hardware (Raspberry Pi)

ros2 launch dht22_env dht22_launch.py \ params_file:=path/to/your_params.yaml

Set fake_mode: false and gpio_pin in your YAML file.

Verify output

ros2 topic echo /dht22/temperature ros2 topic echo /dht22/humidity

Parameters

Parameter Type Default Description
fake_mode bool true Generate random data without hardware
gpio_pin int 4 BCM GPIO pin number (2-27)
publish_rate float 0.5 Publishing rate in Hz (DHT22 max ~0.5 Hz)
frame_id string dht22_link TF frame ID
temperature_variance float 0.0 Temperature variance (0 = unknown)
humidity_variance float 0.0 Humidity variance (0 = unknown)

Services

Service Type Description
dht22/calibrate std_srvs/srv/Trigger Collect samples for 10 s, report averages
dht22/reset std_srvs/srv/Trigger Clear bias, reinitialize sensor

Package Structure

dht22_env/ ├── CMakeLists.txt ├── package.xml ├── config/ │ └── dht22_params.yaml ├── launch/ │ └── dht22_launch.py ├── dht22_env/ │ ├── __init__.py │ └── dht22_driver.py ├── nodes/ │ └── dht22_node.py ├── test/ │ └── test_dht22_node.py ├── .gitignore ├── LICENSE ├── CONTRIBUTING.md └── README.md 

Test Results

Tested on Ubuntu 24.04 (WSL2) with fake_mode: true.

Test Category Test Result
Topics dht22/temperature publishes sensor_msgs/Temperature PASS
Topics dht22/humidity publishes sensor_msgs/RelativeHumidity PASS
Services dht22/calibrate returns success=True PASS
Services dht22/reset returns success=True PASS
Parameters publish_rate runtime change PASS
Shutdown Clean exit PASS
Linting pep257, flake8, copyright, xmllint PASS

License

MIT

About

ROS2 Jazzy driver for DHT22 (AM2302) temperature & humidity sensor (GPIO)

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors