We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
Rating:
Author: MIKROE
Last Updated: 2019-01-10
Package Version: 1.0.0.1
mikroSDK Library: 1.0.0.0
Category: Temperature & humidity
Downloaded: 8857 times
Followed by: 4 users
License: MIT license
This example demonstrates how to use DHT22 click.
DHT22 sensor measures temperature and relative humidity.
Do you want to subscribe in order to receive notifications regarding "DHT22 click" changes.
Do you want to unsubscribe in order to stop receiving notifications regarding "DHT22 click" changes.
Do you want to report abuse regarding "DHT22 click".
Library Description
The library covers all the necessary functions to control DHT22 Click board.
Library performs the communication with the device via CS pin as output and input.
Library have drivers for sending start signal to the sensor, release the bus to wait the sensor response signal function, for reading data from sensor ( humidity and temperature data ) and for calculating temperature and humidity data and for converting sensory data into percent humidity [ % RH ] and degree Celsius [ °C ].
Key functions:
uint32_t dht22_getSensorData()
- Reading data from the sensor function.uint16_t dht22_calculateTemperature( uint32_t sensorData )
- Calculate the temperature data function.uint16_t dht22_calculateHumidity( uint32_t sensorData )
- Calculate the humidity data function.Examples description
The application is composed of the three sections :
void applicationTask() { mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_CS_PIN, _GPIO_OUTPUT ); dht22_startSignal(); mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_CS_PIN, _GPIO_INPUT ); if ( dht22_checkSensorResponse() ) { sensorData = dht22_getSensorData(); if ( sensorData != 0 ) { temperature = dht22_calculateTemperature( sensorData ); humidity = dht22_calculateHumidity( sensorData ); dht22_displayTempHum(); } } Delay_1sec(); }
Additional Functions :
dht22_displayTempHum()
- - Write log to Usart Terminal of humidity and temperature as a two-digit number.Other mikroE Libraries used in the example:
UART
Conversions
Additional notes and information
Depending on the development board you are using, you may need USB UART click, USB UART 2 click or RS232 click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.