0.1.3 DHT2pin

This commit is contained in:
rob tillaart 2022-11-01 20:26:33 +01:00
parent 2aa605a8e8
commit ccdf651a18
7 changed files with 107 additions and 64 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile: compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
platforms: platforms:
@ -7,5 +22,7 @@ compile:
# - leonardo # - leonardo
- m4 - m4
- esp32 - esp32
# - esp8266 - esp8266
# - mega2560 # - mega2560
- rpipico

View File

@ -0,0 +1,33 @@
# Change Log DHT2pin
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.3] - 2022-11-01
- add changelog.md
- add rp2040 to build-CI
## [0.1.2] - 2021-12-16
- update library.json, license, minor edits
## [0.1.1] - 2020-12-19
- added arduino-ci + unit test
## [0.1.0] - 2020-06-30
- own repository
- #pragma once
## [0.0.3]
- Fix issue #33
## [0.0.2]
- support for non "F_CPU" boards especially Galileo
- Tested and verified by Maria Emanuella Moura Silva (thanks)
- changed name to DHT2pin
## [0.0.1] - 2016-09-05
- initial version - based upon 0.1.13 DHT

View File

@ -1,36 +1,29 @@
// //
// FILE: DHT2pin.cpp // FILE: DHT2pin.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.2 // VERSION: 0.1.3
// PURPOSE: Experimental DHT Temperature & Humidity Sensor library for Arduino // PURPOSE: Experimental DHT Temperature & Humidity Sensor library for Arduino
// URL: https://github.com/RobTillaart/DHT2pin // URL: https://github.com/RobTillaart/DHT2pin
// http://arduino.cc/playground/Main/DHTLib // http://arduino.cc/playground/Main/DHTLib
// //
// HISTORY: // HISTORY: see changelog.md
// 0.1.2 2021-12-16 update library.json, license, minor edits
// 0.1.1 2020-12-19 added arduino-ci + unit test
// 0.1.0 2020-06-30 own repository; #pragma once
// 0.0.3 Fix issue #33
// 0.0.2 support for non "F_CPU" boards especially Galileo
// Tested and verified by Maria Emanuella Moura Silva (thanks)
// changed name to DHT2pin
// 0.0.1 initial version - 2016 SEP 05 (based upon 0.1.13 DHT)
//
#include "DHT2pin.h" #include "DHT2pin.h"
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// //
// PUBLIC // PUBLIC
// //
// return values: // return values:
// DHTLIB_OK // DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM // DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT // DHTLIB_ERROR_TIMEOUT
int DHT2pin::read11() int DHT2pin::read11()
{ {
// READ VALUES // READ VALUES
int rv = _readSensor(DHTLIB_DHT11_WAKEUP); int rv = _readSensor(DHTLIB_DHT11_WAKEUP);
if (rv != DHTLIB_OK) if (rv != DHTLIB_OK)
{ {
@ -39,12 +32,12 @@ int DHT2pin::read11()
return rv; return rv;
} }
// CONVERT AND STORE // CONVERT AND STORE
humidity = bits[0]; // bits[1] == 0; humidity = bits[0]; // bits[1] == 0;
temperature = bits[2]; // bits[3] == 0; temperature = bits[2]; // bits[3] == 0;
// TEST CHECKSUM // TEST CHECKSUM
// bits[1] && bits[3] both 0 // bits[1] && bits[3] both 0
uint8_t sum = bits[0] + bits[2]; uint8_t sum = bits[0] + bits[2];
if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
@ -52,25 +45,25 @@ int DHT2pin::read11()
} }
// return values: // return values:
// DHTLIB_OK // DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM // DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT // DHTLIB_ERROR_TIMEOUT
int DHT2pin::read() int DHT2pin::read()
{ {
// READ VALUES // READ VALUES
int rv = _readSensor(DHTLIB_DHT_WAKEUP); int rv = _readSensor(DHTLIB_DHT_WAKEUP);
if (rv != DHTLIB_OK) if (rv != DHTLIB_OK)
{ {
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
temperature = DHTLIB_INVALID_VALUE; // invalid value temperature = DHTLIB_INVALID_VALUE; // invalid value
return rv; // propagate error value return rv; // propagate error value
} }
// CONVERT AND STORE // CONVERT AND STORE
humidity = word(bits[0], bits[1]) * 0.1; humidity = word(bits[0], bits[1]) * 0.1;
temperature = word(bits[2] & 0x7F, bits[3]) * 0.1; temperature = word(bits[2] & 0x7F, bits[3]) * 0.1;
if (bits[2] & 0x80) // negative temperature if (bits[2] & 0x80) // negative temperature
{ {
temperature = -temperature; temperature = -temperature;
} }
@ -86,28 +79,28 @@ int DHT2pin::read()
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// //
// PRIVATE // PRIVATE
// //
// return values: // return values:
// DHTLIB_OK // DHTLIB_OK
// DHTLIB_ERROR_TIMEOUT // DHTLIB_ERROR_TIMEOUT
int DHT2pin::_readSensor(uint8_t wakeupDelay) int DHT2pin::_readSensor(uint8_t wakeupDelay)
{ {
// INIT BUFFERVAR TO RECEIVE DATA // INIT BUFFERVAR TO RECEIVE DATA
uint8_t mask = 128; uint8_t mask = 128;
uint8_t idx = 0; uint8_t idx = 0;
// EMPTY BUFFER // EMPTY BUFFER
for (uint8_t i = 0; i < 5; i++) bits[i] = 0; for (uint8_t i = 0; i < 5; i++) bits[i] = 0;
// REQUEST SAMPLE // REQUEST SAMPLE
digitalWrite(_wpin, LOW); digitalWrite(_wpin, LOW);
delay(wakeupDelay); delay(wakeupDelay);
digitalWrite(_wpin, HIGH); digitalWrite(_wpin, HIGH);
delayMicroseconds(40); delayMicroseconds(40);
// GET ACKNOWLEDGE or TIMEOUT // GET ACKNOWLEDGE or TIMEOUT
uint16_t loopCnt = DHTLIB_TIMEOUT; uint16_t loopCnt = DHTLIB_TIMEOUT;
while(digitalRead(_rpin) == LOW) while(digitalRead(_rpin) == LOW)
{ {
@ -152,6 +145,7 @@ int DHT2pin::_readSensor(uint8_t wakeupDelay)
return DHTLIB_OK; return DHTLIB_OK;
} }
//
// END OF FILE
// // -- END OF FILE --

View File

@ -2,18 +2,16 @@
// //
// FILE: dht2pin.h // FILE: dht2pin.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.2 // VERSION: 0.1.3
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: https://github.com/RobTillaart/DHT2pin // URL: https://github.com/RobTillaart/DHT2pin
// http://arduino.cc/playground/Main/DHTLib // http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// see dht.cpp file
//
#include <Arduino.h> #include <Arduino.h>
#define DHT2PIN_LIB_VERSION (F("0.1.2"))
#define DHT2PIN_LIB_VERSION (F("0.1.3"))
#define DHTLIB_OK 0 #define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1 #define DHTLIB_ERROR_CHECKSUM -1
@ -26,11 +24,11 @@
#define DHTLIB_DHT11_WAKEUP 18 #define DHTLIB_DHT11_WAKEUP 18
#define DHTLIB_DHT_WAKEUP 1 #define DHTLIB_DHT_WAKEUP 1
// max timeout is 100usec. // max timeout is 100usec.
// For a 16Mhz proc that is max 1600 clock cycles // For a 16Mhz proc that is max 1600 clock cycles
// loops using TIMEOUT use at least 4 clock cycli // loops using TIMEOUT use at least 4 clock cycli
// so 100 us takes max 400 loops // so 100 us takes max 400 loops
// so by dividing F_CPU by 40000 we "fail" as fast as possible // so by dividing F_CPU by 40000 we "fail" as fast as possible
#ifdef F_CPU #ifdef F_CPU
#define DHTLIB_TIMEOUT (F_CPU/40000) #define DHTLIB_TIMEOUT (F_CPU/40000)
#else #else
@ -40,10 +38,10 @@
class DHT2pin class DHT2pin
{ {
public: public:
// return values: // return values:
// DHTLIB_OK // DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM // DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT // DHTLIB_ERROR_TIMEOUT
DHT2pin(uint8_t rpin, uint8_t wpin) DHT2pin(uint8_t rpin, uint8_t wpin)
{ {
_rpin = rpin; _rpin = rpin;
@ -72,10 +70,10 @@ public:
private: private:
uint8_t _rpin; uint8_t _rpin;
uint8_t _wpin; uint8_t _wpin;
uint8_t bits[5]; // buffer to receive data uint8_t bits[5]; // buffer to receive data
int _readSensor(uint8_t wakeupDelay); int _readSensor(uint8_t wakeupDelay);
}; };
//
// END OF FILE // -- END OF FILE --
//

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/DHT2pin" "url": "https://github.com/RobTillaart/DHT2pin"
}, },
"version": "0.1.2", "version": "0.1.3",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=DHT2pin name=DHT2pin
version=0.1.2 version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Experimental library of the DHT library that uses 2 pins. sentence=Experimental library of the DHT library that uses 2 pins.

View File

@ -55,6 +55,7 @@ unittest(test_constructor)
assertEqualFloat(-999, DHT.humidity, 0.001); assertEqualFloat(-999, DHT.humidity, 0.001);
} }
unittest_main() unittest_main()
// -------- // --------