mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.3 DHT2pin
This commit is contained in:
parent
2aa605a8e8
commit
ccdf651a18
@ -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:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -7,5 +22,7 @@ compile:
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
- esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
||||
|
33
libraries/DHT2pin/CHANGELOG.md
Normal file
33
libraries/DHT2pin/CHANGELOG.md
Normal 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
|
||||
|
@ -1,36 +1,29 @@
|
||||
//
|
||||
// FILE: DHT2pin.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// PURPOSE: Experimental DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHT2pin
|
||||
// http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// 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)
|
||||
//
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "DHT2pin.h"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
// PUBLIC
|
||||
//
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int DHT2pin::read11()
|
||||
{
|
||||
// READ VALUES
|
||||
// READ VALUES
|
||||
int rv = _readSensor(DHTLIB_DHT11_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
@ -39,12 +32,12 @@ int DHT2pin::read11()
|
||||
return rv;
|
||||
}
|
||||
|
||||
// CONVERT AND STORE
|
||||
// CONVERT AND STORE
|
||||
humidity = bits[0]; // bits[1] == 0;
|
||||
temperature = bits[2]; // bits[3] == 0;
|
||||
|
||||
// TEST CHECKSUM
|
||||
// bits[1] && bits[3] both 0
|
||||
// TEST CHECKSUM
|
||||
// bits[1] && bits[3] both 0
|
||||
uint8_t sum = bits[0] + bits[2];
|
||||
if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
|
||||
|
||||
@ -52,25 +45,25 @@ int DHT2pin::read11()
|
||||
}
|
||||
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int DHT2pin::read()
|
||||
{
|
||||
// READ VALUES
|
||||
// READ VALUES
|
||||
int rv = _readSensor(DHTLIB_DHT_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv; // propagate error value
|
||||
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv; // propagate error value
|
||||
}
|
||||
|
||||
// CONVERT AND STORE
|
||||
// CONVERT AND STORE
|
||||
humidity = word(bits[0], bits[1]) * 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;
|
||||
}
|
||||
@ -86,28 +79,28 @@ int DHT2pin::read()
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int DHT2pin::_readSensor(uint8_t wakeupDelay)
|
||||
{
|
||||
// INIT BUFFERVAR TO RECEIVE DATA
|
||||
// INIT BUFFERVAR TO RECEIVE DATA
|
||||
uint8_t mask = 128;
|
||||
uint8_t idx = 0;
|
||||
|
||||
// EMPTY BUFFER
|
||||
// EMPTY BUFFER
|
||||
for (uint8_t i = 0; i < 5; i++) bits[i] = 0;
|
||||
|
||||
// REQUEST SAMPLE
|
||||
// REQUEST SAMPLE
|
||||
digitalWrite(_wpin, LOW);
|
||||
delay(wakeupDelay);
|
||||
digitalWrite(_wpin, HIGH);
|
||||
delayMicroseconds(40);
|
||||
|
||||
// GET ACKNOWLEDGE or TIMEOUT
|
||||
// GET ACKNOWLEDGE or TIMEOUT
|
||||
uint16_t loopCnt = DHTLIB_TIMEOUT;
|
||||
while(digitalRead(_rpin) == LOW)
|
||||
{
|
||||
@ -152,6 +145,7 @@ int DHT2pin::_readSensor(uint8_t wakeupDelay)
|
||||
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,18 +2,16 @@
|
||||
//
|
||||
// FILE: dht2pin.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHT2pin
|
||||
// http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// see dht.cpp file
|
||||
//
|
||||
|
||||
|
||||
#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_ERROR_CHECKSUM -1
|
||||
@ -26,11 +24,11 @@
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
|
||||
// max timeout is 100usec.
|
||||
// For a 16Mhz proc that is max 1600 clock cycles
|
||||
// loops using TIMEOUT use at least 4 clock cycli
|
||||
// so 100 us takes max 400 loops
|
||||
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
||||
// max timeout is 100usec.
|
||||
// For a 16Mhz proc that is max 1600 clock cycles
|
||||
// loops using TIMEOUT use at least 4 clock cycli
|
||||
// so 100 us takes max 400 loops
|
||||
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
||||
#ifdef F_CPU
|
||||
#define DHTLIB_TIMEOUT (F_CPU/40000)
|
||||
#else
|
||||
@ -40,10 +38,10 @@
|
||||
class DHT2pin
|
||||
{
|
||||
public:
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
DHT2pin(uint8_t rpin, uint8_t wpin)
|
||||
{
|
||||
_rpin = rpin;
|
||||
@ -72,10 +70,10 @@ public:
|
||||
private:
|
||||
uint8_t _rpin;
|
||||
uint8_t _wpin;
|
||||
uint8_t bits[5]; // buffer to receive data
|
||||
uint8_t bits[5]; // buffer to receive data
|
||||
int _readSensor(uint8_t wakeupDelay);
|
||||
};
|
||||
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DHT2pin"
|
||||
},
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DHT2pin
|
||||
version=0.1.2
|
||||
version=0.1.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Experimental library of the DHT library that uses 2 pins.
|
||||
|
@ -55,6 +55,7 @@ unittest(test_constructor)
|
||||
assertEqualFloat(-999, DHT.humidity, 0.001);
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
Loading…
x
Reference in New Issue
Block a user