GY-63_MS5611/libraries/DHT12/README.md

92 lines
3.2 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/DHT12/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-10-25 11:35:53 -04:00
[![Arduino-lint](https://github.com/RobTillaart/DHT12/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DHT12/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/DHT12/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DHT12/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DHT12/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DHT12.svg?maxAge=3600)](https://github.com/RobTillaart/DHT12/releases)
2020-11-27 05:10:47 -05:00
# DHT12
Arduino library for I2C DHT12 temperature and humidity sensor.
2021-10-25 11:35:53 -04:00
2020-11-27 05:10:47 -05:00
## Description
The library should be initiated by calling the **begin()** function,
2021-10-25 11:35:53 -04:00
optionally **begin(dataPin, clockPin)** for **ESP32** and similar platforms.
2020-11-27 05:10:47 -05:00
Thereafter one has to call the **read()** function to do the actual reading,
and with **getTemperature()** and **getHumidity()** to get the read values.
Calling these latter again will return the same values until a new **read()** is called.
2023-02-09 12:45:30 -05:00
#### I2C
The DHT12 has a fixed I2C address of 0x5C. To use multiple DHT12's one need an
I2C multiplexer like PCA9548 or TCA9548.
The DHT12 should work up to 400 KHz however this is not tested (yet).
2021-10-25 11:35:53 -04:00
2021-01-29 06:31:58 -05:00
## Interface
2023-02-09 12:45:30 -05:00
```cpp
#include "DHT12.h"
```
2021-10-25 11:35:53 -04:00
2021-12-16 09:58:14 -05:00
2023-02-09 12:45:30 -05:00
#### Constructor
- **DHT12(TwoWire \*wire = &Wire)** constructor, using a specific Wire (I2C bus).
Default is set to Wire.
- **bool begin(uint8_t dataPin, uint8_t clockPin)** begin for ESP32 et al, to set I2C bus pins.
2021-12-16 09:58:14 -05:00
- **bool begin()** initializer for non ESP32. Returns true if connected.
- **bool isConnected()** returns true if the address of the DHT12 can be seen on the I2C bus. (since 0.3.2)
2021-01-29 06:31:58 -05:00
2021-10-25 11:35:53 -04:00
2023-02-09 12:45:30 -05:00
#### Core
2021-12-16 09:58:14 -05:00
2021-10-25 11:35:53 -04:00
- **int8_t read()** read the sensor and store the values internally. It returns the status of the read which should be 0.
- **float getHumidity()** returns last Humidity read, or -999 in case of error.
- **float getTemperature()** returns last Temperature read, or -999 in case of error.
2023-02-09 12:45:30 -05:00
- **uint32_t lastRead()** returns the timestamp of the last successful read in milliseconds since startup.
If zero there has been no **read()** called yet.
2021-10-25 11:35:53 -04:00
2023-02-09 12:45:30 -05:00
#### Offset
2021-01-29 06:31:58 -05:00
2023-02-09 12:45:30 -05:00
- **void setHumOffset(float offset = 0)** set an offset to calibrate (1st order) the sensor.
Default offset is 0.
- **float getHumOffset()** return current humidity offset, default 0.
- **void setTempOffset(float offset = 0)** set an offset to calibrate (1st order) the sensor.
Default offset is 0.
- **float getTempOffset()** return current temperature offset, default 0.
2021-12-16 09:58:14 -05:00
2021-10-25 11:35:53 -04:00
2023-02-09 12:45:30 -05:00
## Future
2021-10-25 11:35:53 -04:00
2023-02-09 12:45:30 -05:00
#### Must
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
2023-02-09 12:45:30 -05:00
#### Should
2021-10-25 11:35:53 -04:00
2023-02-09 12:45:30 -05:00
- test at different I2C speeds
- 400 KHz should be possible.
- add examples.
2020-11-27 05:10:47 -05:00
2021-12-16 09:58:14 -05:00
2023-02-09 12:45:30 -05:00
#### Could
2021-12-16 09:58:14 -05:00
2023-02-09 12:45:30 -05:00
- check for optimizations. although I2C overhead is much more.
- add **void setIgnoreChecksum(bool = false)** ignore checksum flag speeds up communication a bit
- add **bool getIgnoreChecksum()** get status. for completeness.
- investigate if it is possible to extract temp and hum separately
- faster?
- add **void suppressErrorReads(bool)** prevents the -999, returns previous value
- add **bool getSuppressError()**
2021-12-16 09:58:14 -05:00
2023-02-09 12:45:30 -05:00
#### Wont
2021-12-16 09:58:14 -05:00