mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 DHTINT
This commit is contained in:
parent
5f418397a8
commit
ac2f01f82d
11
libraries/DHTINT/.arduino-ci.yml
Normal file
11
libraries/DHTINT/.arduino-ci.yml
Normal file
@ -0,0 +1,11 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- due
|
||||
- zero
|
||||
- leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
- mega2560
|
13
libraries/DHTINT/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/DHTINT/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/DHTINT/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/DHTINT/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/DHTINT/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/DHTINT/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
21
libraries/DHTINT/LICENSE
Normal file
21
libraries/DHTINT/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
54
libraries/DHTINT/README.md
Normal file
54
libraries/DHTINT/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/DHTINT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/DHTINT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DHTINT/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/DHTINT/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DHTINT/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DHTINT/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DHTINT.svg?maxAge=3600)](https://github.com/RobTillaart/DHTINT/releases)
|
||||
|
||||
|
||||
# DHTINT
|
||||
|
||||
Arduino library for DHT sensors - integer only
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
This is an **experimental** integer only library,
|
||||
based upon - https://github.com/RobTillaart/DHTNew - version 0.4.12
|
||||
|
||||
Goal is to reduce footprint by using integer math only.
|
||||
This way the lib becomes more usable for processors like the ATTINY 45 or 85.
|
||||
|
||||
As the library only uses integer math it will not trigger the automatic including of
|
||||
the floating point math libraries.
|
||||
This will save additional memory unless other code uses floating point math.
|
||||
|
||||
|
||||
### Compare DHTINT versus DHTNEW
|
||||
|
||||
Sketch: ..\example\dhtint_minimum.ino
|
||||
|
||||
replaced DHTINT with DHTNEW
|
||||
|
||||
|
||||
| platform | library | sketch size | variables |
|
||||
|:--------:|:--------|------------:|----------:|
|
||||
| UNO | DHTNEW | 5730 | 341 |
|
||||
| UNO | DHTINT | 3978 | 321 |
|
||||
| | delta | 1752 | 20 |
|
||||
| | | | |
|
||||
| ESP32 | DHTNEW | 206730 | 13464 |
|
||||
| ESP32 | DHTINT | 206110 | 13456 |
|
||||
| | delta | 620 | 8 |
|
||||
| | | | |
|
||||
|
||||
|
||||
Gain is most substantial for the UNO platform.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- Keep in sync with DHTNEW.
|
||||
- Test more
|
||||
- Add examples.
|
||||
|
388
libraries/DHTINT/dhtint.cpp
Normal file
388
libraries/DHTINT/dhtint.cpp
Normal file
@ -0,0 +1,388 @@
|
||||
//
|
||||
// FILE: dhtint.cpp
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for DHT sensors - integer only
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2022-05-08 initial version based upon DHTNEW
|
||||
|
||||
|
||||
#include "dhtint.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// these defines are not for user to adjust
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
|
||||
|
||||
// READ_DELAY for blocking read
|
||||
// datasheet: DHT11 = 1000 and DHT22 = 2000
|
||||
// use setReadDelay() to overrule (at own risk)
|
||||
// as individual sensors can be read faster.
|
||||
// see example DHTnew_setReadDelay.ino
|
||||
#define DHTLIB_DHT11_READ_DELAY 1000
|
||||
#define DHTLIB_DHT22_READ_DELAY 2000
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
DHTINT::DHTINT(uint8_t pin)
|
||||
{
|
||||
_dataPin = pin;
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
void DHTINT::reset()
|
||||
{
|
||||
// Data-bus's free status is high voltage level.
|
||||
pinMode(_dataPin, OUTPUT);
|
||||
digitalWrite(_dataPin, HIGH);
|
||||
|
||||
_wakeupDelay = 0;
|
||||
_type = 0;
|
||||
_humOffset = 0;
|
||||
_tempOffset = 0;
|
||||
_humidity = 0;
|
||||
_temperature = 0;
|
||||
_lastRead = 0;
|
||||
_disableIRQ = true;
|
||||
_waitForRead = false;
|
||||
_suppressError = false;
|
||||
_readDelay = 0;
|
||||
#if defined(__AVR__)
|
||||
_disableIRQ = false;
|
||||
#endif
|
||||
// #if defined(MKR1010) // TODO find out real define
|
||||
// _disableIRQ = false;
|
||||
// #endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t DHTINT::getType()
|
||||
{
|
||||
if (_type == 0) read();
|
||||
return _type;
|
||||
}
|
||||
|
||||
|
||||
void DHTINT::setType(uint8_t type)
|
||||
{
|
||||
if ((type == 0) || (type == 11))
|
||||
{
|
||||
_type = type;
|
||||
_wakeupDelay = DHTLIB_DHT11_WAKEUP;
|
||||
}
|
||||
if (type == 22)
|
||||
{
|
||||
_type = type;
|
||||
_wakeupDelay = DHTLIB_DHT_WAKEUP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_WAITING_FOR_READ
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_BIT_SHIFT
|
||||
// DHTLIB_ERROR_SENSOR_NOT_READY
|
||||
// DHTLIB_ERROR_TIMEOUT_A
|
||||
// DHTLIB_ERROR_TIMEOUT_B
|
||||
// DHTLIB_ERROR_TIMEOUT_C
|
||||
// DHTLIB_ERROR_TIMEOUT_D
|
||||
int DHTINT::read()
|
||||
{
|
||||
if (_readDelay == 0)
|
||||
{
|
||||
_readDelay = DHTLIB_DHT22_READ_DELAY;
|
||||
if (_type == 11) _readDelay = DHTLIB_DHT11_READ_DELAY;
|
||||
}
|
||||
if (_type != 0)
|
||||
{
|
||||
while (millis() - _lastRead < _readDelay)
|
||||
{
|
||||
if (!_waitForRead) return DHTLIB_WAITING_FOR_READ;
|
||||
yield();
|
||||
}
|
||||
return _read();
|
||||
}
|
||||
|
||||
_type = 22;
|
||||
_wakeupDelay = DHTLIB_DHT_WAKEUP;
|
||||
int rv = _read();
|
||||
if (rv == DHTLIB_OK) return rv;
|
||||
|
||||
_type = 11;
|
||||
_wakeupDelay = DHTLIB_DHT11_WAKEUP;
|
||||
rv = _read();
|
||||
if (rv == DHTLIB_OK) return rv;
|
||||
|
||||
_type = 0; // retry next time
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_BIT_SHIFT
|
||||
// DHTLIB_ERROR_SENSOR_NOT_READY
|
||||
// DHTLIB_ERROR_TIMEOUT_A
|
||||
// DHTLIB_ERROR_TIMEOUT_B
|
||||
// DHTLIB_ERROR_TIMEOUT_C
|
||||
// DHTLIB_ERROR_TIMEOUT_D
|
||||
int DHTINT::_read()
|
||||
{
|
||||
// READ VALUES
|
||||
int rv = _readSensor();
|
||||
interrupts();
|
||||
|
||||
// Data-bus's free status is high voltage level.
|
||||
pinMode(_dataPin, OUTPUT);
|
||||
digitalWrite(_dataPin, HIGH);
|
||||
_lastRead = millis();
|
||||
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
if (_suppressError == false)
|
||||
{
|
||||
_humidity = DHTLIB_INVALID_VALUE;
|
||||
_temperature = DHTLIB_INVALID_VALUE;
|
||||
}
|
||||
return rv; // propagate error value
|
||||
}
|
||||
|
||||
if (_type == 22) // DHT22, DHT33, DHT44, compatible
|
||||
{
|
||||
_humidity = (_bits[0] * 256 + _bits[1] + 5) / 10;
|
||||
int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
|
||||
if (t == 0)
|
||||
{
|
||||
_temperature = 0; // prevent -0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_temperature = (t + 5 ) / 10;
|
||||
if((_bits[2] & 0x80) == 0x80 )
|
||||
{
|
||||
_temperature = -_temperature;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // if (_type == 11) // DHT11, DH12, compatible
|
||||
{
|
||||
_humidity = _bits[0] + (_bits[1] + 5) / 10;
|
||||
_temperature = _bits[2] + (_bits[3] + 5) / 10;
|
||||
}
|
||||
|
||||
// HEXDUMP DEBUG
|
||||
/*
|
||||
Serial.println();
|
||||
// CHECKSUM
|
||||
if (_bits[4] < 0x10) Serial.print(0);
|
||||
Serial.print(_bits[4], HEX);
|
||||
Serial.print(" ");
|
||||
// TEMPERATURE
|
||||
if (_bits[2] < 0x10) Serial.print(0);
|
||||
Serial.print(_bits[2], HEX);
|
||||
if (_bits[3] < 0x10) Serial.print(0);
|
||||
Serial.print(_bits[3], HEX);
|
||||
Serial.print(" ");
|
||||
Serial.print(_temperature, 1);
|
||||
Serial.print(" ");
|
||||
// HUMIDITY
|
||||
if (_bits[0] < 0x10) Serial.print(0);
|
||||
Serial.print(_bits[0], HEX);
|
||||
if (_bits[1] < 0x10) Serial.print(0);
|
||||
Serial.print(_bits[1], HEX);
|
||||
Serial.print(" ");
|
||||
Serial.print(_humidity, 1);
|
||||
*/
|
||||
|
||||
// TEST OUT OF RANGE
|
||||
#ifdef DHTLIB_VALUE_OUT_OF_RANGE
|
||||
if (_humidity > 100)
|
||||
{
|
||||
return DHTLIB_HUMIDITY_OUT_OF_RANGE;
|
||||
}
|
||||
if ((_temperature < -40) || (_temperature > 80))
|
||||
{
|
||||
return DHTLIB_TEMPERATURE_OUT_OF_RANGE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_humOffset != 0)
|
||||
{
|
||||
_humidity += _humOffset;
|
||||
if (_humidity < 0) _humidity = 0;
|
||||
if (_humidity > 100) _humidity = 100;
|
||||
}
|
||||
if (_tempOffset != 0)
|
||||
{
|
||||
_temperature += _tempOffset;
|
||||
}
|
||||
|
||||
// TEST CHECKSUM
|
||||
uint8_t sum = _bits[0] + _bits[1] + _bits[2] + _bits[3];
|
||||
if (_bits[4] != sum)
|
||||
{
|
||||
return DHTLIB_ERROR_CHECKSUM;
|
||||
}
|
||||
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
|
||||
|
||||
void DHTINT::powerUp()
|
||||
{
|
||||
digitalWrite(_dataPin, HIGH);
|
||||
// do a dummy read to sync the sensor
|
||||
read();
|
||||
};
|
||||
|
||||
|
||||
void DHTINT::powerDown()
|
||||
{
|
||||
digitalWrite(_dataPin, LOW);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_BIT_SHIFT
|
||||
// DHTLIB_ERROR_SENSOR_NOT_READY
|
||||
// DHTLIB_ERROR_TIMEOUT_A
|
||||
// DHTLIB_ERROR_TIMEOUT_B
|
||||
// DHTLIB_ERROR_TIMEOUT_C
|
||||
// DHTLIB_ERROR_TIMEOUT_D
|
||||
int DHTINT::_readSensor()
|
||||
{
|
||||
// INIT BUFFERVAR TO RECEIVE DATA
|
||||
uint8_t mask = 0x80;
|
||||
uint8_t idx = 0;
|
||||
|
||||
// EMPTY BUFFER
|
||||
for (uint8_t i = 0; i < 5; i++) _bits[i] = 0;
|
||||
|
||||
// REQUEST SAMPLE - SEND WAKEUP TO SENSOR
|
||||
pinMode(_dataPin, OUTPUT);
|
||||
digitalWrite(_dataPin, LOW);
|
||||
|
||||
// WAKE UP - add 10% extra for timing inaccuracies in sensor.
|
||||
uint32_t startWakeup = micros();
|
||||
do
|
||||
{
|
||||
// HANDLE PENDING IRQ
|
||||
yield();
|
||||
// 180 gives good wakeup delay on UNO for DHT22 / DHT11 (issue #72)
|
||||
delayMicroseconds(180UL);
|
||||
}
|
||||
while((micros() - startWakeup) < (_wakeupDelay * 1100UL));
|
||||
|
||||
// HOST GIVES CONTROL TO SENSOR
|
||||
digitalWrite(_dataPin, HIGH);
|
||||
delayMicroseconds(2);
|
||||
pinMode(_dataPin, INPUT_PULLUP);
|
||||
|
||||
// DISABLE INTERRUPTS when clock in the bits
|
||||
if (_disableIRQ) { noInterrupts(); }
|
||||
|
||||
// DHT22
|
||||
// SENSOR PULLS LOW after 20-40 us => if stays HIGH ==> device not ready
|
||||
// timeout is 20 us less due to delay() above
|
||||
// DHT11
|
||||
// SENSOR PULLS LOW after 6000-10000 us
|
||||
uint32_t WAITFORSENSOR = 50;
|
||||
if (_type == 11) WAITFORSENSOR = 15000UL;
|
||||
if (_waitFor(LOW, WAITFORSENSOR)) return DHTLIB_ERROR_SENSOR_NOT_READY;
|
||||
|
||||
// SENSOR STAYS LOW for ~80 us => or TIMEOUT
|
||||
if (_waitFor(HIGH, 90)) return DHTLIB_ERROR_TIMEOUT_A;
|
||||
|
||||
// SENSOR STAYS HIGH for ~80 us => or TIMEOUT
|
||||
if (_waitFor(LOW, 90)) return DHTLIB_ERROR_TIMEOUT_B;
|
||||
|
||||
// SENSOR HAS NOW SEND ACKNOWLEDGE ON WAKEUP
|
||||
// NOW IT SENDS THE BITS
|
||||
|
||||
// READ THE OUTPUT - 40 BITS => 5 BYTES
|
||||
for (uint8_t i = 40; i != 0; i--)
|
||||
{
|
||||
// EACH BIT START WITH ~50 us LOW
|
||||
if (_waitFor(HIGH, 90))
|
||||
{
|
||||
// Most critical timeout
|
||||
// Serial.print("IC: ");
|
||||
// Serial.println(i);
|
||||
return DHTLIB_ERROR_TIMEOUT_C;
|
||||
}
|
||||
|
||||
// DURATION OF HIGH DETERMINES 0 or 1
|
||||
// 26-28 us ==> 0
|
||||
// 70 us ==> 1
|
||||
uint32_t t = micros();
|
||||
if (_waitFor(LOW, 90))
|
||||
{
|
||||
// Serial.print("ID: ");
|
||||
// Serial.println(i);
|
||||
return DHTLIB_ERROR_TIMEOUT_D;
|
||||
}
|
||||
if ((micros() - t) > DHTLIB_BIT_THRESHOLD)
|
||||
{
|
||||
_bits[idx] |= mask;
|
||||
}
|
||||
|
||||
// PREPARE FOR NEXT BIT
|
||||
mask >>= 1;
|
||||
if (mask == 0) // next byte?
|
||||
{
|
||||
mask = 0x80;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
// After 40 bits the sensor pulls the line LOW for 50 us
|
||||
// No functional need to wait for this one
|
||||
// if (_waitFor(HIGH, 60)) return DHTLIB_ERROR_TIMEOUT_E;
|
||||
|
||||
// CATCH RIGHTSHIFT BUG ESP (only 1 single bit shift)
|
||||
// humidity is maximum 1000 = 0x03E8 for DHT22 and 0x6400 for DHT11
|
||||
// so most significant bit may never be set.
|
||||
if (_bits[0] & 0x80) return DHTLIB_ERROR_BIT_SHIFT;
|
||||
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
|
||||
|
||||
// returns true if timeout has passed.
|
||||
// returns false if timeout is not reached and state is seen.
|
||||
bool DHTINT::_waitFor(uint8_t state, uint32_t timeout)
|
||||
{
|
||||
uint32_t start = micros();
|
||||
uint8_t count = 2;
|
||||
while ((micros() - start) < timeout)
|
||||
{
|
||||
// delayMicroseconds(1); // less # reads ==> minimizes # glitch reads
|
||||
if (digitalRead(_dataPin) == state)
|
||||
{
|
||||
count--;
|
||||
if (count == 0) return false; // requested state seen count times
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
127
libraries/DHTINT/dhtint.h
Normal file
127
libraries/DHTINT/dhtint.h
Normal file
@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: dhtint.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for DHT sensors - integer only
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define DHTINT_LIB_VERSION (F("0.1.0 experimental"))
|
||||
|
||||
|
||||
#define DHTLIB_OK 0
|
||||
#define DHTLIB_ERROR_CHECKSUM -1
|
||||
#define DHTLIB_ERROR_TIMEOUT_A -2
|
||||
#define DHTLIB_ERROR_BIT_SHIFT -3
|
||||
#define DHTLIB_ERROR_SENSOR_NOT_READY -4
|
||||
#define DHTLIB_ERROR_TIMEOUT_C -5
|
||||
#define DHTLIB_ERROR_TIMEOUT_D -6
|
||||
#define DHTLIB_ERROR_TIMEOUT_B -7
|
||||
#define DHTLIB_WAITING_FOR_READ -8
|
||||
|
||||
// optionally detect out of range values.
|
||||
// occurs seldom so not enabled by default.
|
||||
// #define DHTLIB_VALUE_OUT_OF_RANGE
|
||||
#define DHTLIB_HUMIDITY_OUT_OF_RANGE -100
|
||||
#define DHTLIB_TEMPERATURE_OUT_OF_RANGE -101
|
||||
|
||||
// allows to overrule DHTLIB_INVALID_VALUE e.g. to prevent spike in graphs.
|
||||
#ifndef DHTLIB_INVALID_VALUE
|
||||
#define DHTLIB_INVALID_VALUE -999
|
||||
#endif
|
||||
|
||||
|
||||
// bits are timing based (datasheet)
|
||||
// 26-28us ==> 0
|
||||
// 70 us ==> 1
|
||||
// See https://github.com/RobTillaart/DHTNew/issues/11
|
||||
#ifndef DHTLIB_BIT_THRESHOLD
|
||||
#define DHTLIB_BIT_THRESHOLD 50
|
||||
#endif
|
||||
|
||||
|
||||
class DHTINT
|
||||
{
|
||||
public:
|
||||
|
||||
DHTINT(uint8_t pin);
|
||||
|
||||
// resets all internals to construction time
|
||||
// might help to reset a sensor behaving badly..
|
||||
void reset();
|
||||
|
||||
// 0 = unknown, 11 or 22
|
||||
uint8_t getType();
|
||||
void setType(uint8_t type = 0);
|
||||
int read();
|
||||
|
||||
// lastRead is in MilliSeconds since start sketch
|
||||
uint32_t lastRead() { return _lastRead; };
|
||||
|
||||
// preferred interface
|
||||
int getHumidity() { return _humidity; };
|
||||
int getTemperature() { return _temperature; };
|
||||
|
||||
// adding offsets works well in normal range
|
||||
// might introduce under- or overflow at the ends of the sensor range
|
||||
void setHumOffset(int offset) { _humOffset = offset; };
|
||||
void setTempOffset(int offset) { _tempOffset = offset; };
|
||||
float getHumOffset() { return _humOffset; };
|
||||
float getTempOffset() { return _tempOffset; };
|
||||
|
||||
bool getDisableIRQ() { return _disableIRQ; };
|
||||
void setDisableIRQ(bool b ) { _disableIRQ = b; };
|
||||
|
||||
bool getWaitForReading() { return _waitForRead; };
|
||||
void setWaitForReading(bool b ) { _waitForRead = b; };
|
||||
|
||||
// set readDelay to 0 will reset to datasheet values
|
||||
uint16_t getReadDelay() { return _readDelay; };
|
||||
void setReadDelay(uint16_t rd = 0) { _readDelay = rd; };
|
||||
|
||||
// minimal support for low power applications.
|
||||
// after powerUp one must wait up to two seconds.
|
||||
void powerUp();
|
||||
void powerDown();
|
||||
|
||||
// suppress error values of -999 => check return value of read() instead
|
||||
bool getSuppressError() { return _suppressError; };
|
||||
void setSuppressError(bool b) { _suppressError = b; };
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _dataPin = 0;
|
||||
uint8_t _wakeupDelay = 0;
|
||||
uint8_t _type = 0;
|
||||
int _humOffset = 0;
|
||||
int _tempOffset = 0;
|
||||
int _humidity = 0;
|
||||
int _temperature = 0;
|
||||
uint32_t _lastRead = 0;
|
||||
bool _disableIRQ = true;
|
||||
bool _waitForRead = false;
|
||||
bool _suppressError = false;
|
||||
uint16_t _readDelay = 0;
|
||||
|
||||
uint8_t _bits[5]; // buffer to receive data
|
||||
int _read();
|
||||
int _readSensor();
|
||||
bool _waitFor(uint8_t state, uint32_t timeout);
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,162 @@
|
||||
//
|
||||
// FILE: dhtint_adaptive_delay.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
//
|
||||
|
||||
//
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
// Note:
|
||||
// Adaptive delay makes no sense anymore as the DHTINT lib catches reads that
|
||||
// are done faster than READ_DELAY apart (see dhtint.cpp file).
|
||||
// that said it is the goal to get this adaptability into the library one day.
|
||||
// A way to do this is to add a function auto_calibrate() that finds the timing
|
||||
// where reading fails and use that value + safety margin (20%?)
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_adaptive_delay.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("\n1. Type detection test, first run might take longer to determine type");
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
|
||||
Serial.println("\n2. Humidity offset test");
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
mySensor.setHumOffset(2);
|
||||
test();
|
||||
mySensor.setHumOffset(5);
|
||||
test();
|
||||
mySensor.setHumOffset(-5);
|
||||
test();
|
||||
mySensor.setHumOffset(0);
|
||||
test();
|
||||
|
||||
Serial.println("\n3. Temperature offset test");
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
mySensor.setTempOffset(2);
|
||||
test();
|
||||
mySensor.setTempOffset(5);
|
||||
test();
|
||||
mySensor.setTempOffset(-5);
|
||||
test();
|
||||
mySensor.setTempOffset(0);
|
||||
test();
|
||||
|
||||
Serial.println("\n4. LastRead test");
|
||||
mySensor.read();
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (millis() - mySensor.lastRead() > 1000)
|
||||
{
|
||||
mySensor.read();
|
||||
Serial.println("actual read");
|
||||
}
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getTemperature());
|
||||
delay(250);
|
||||
}
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
{
|
||||
static uint16_t dht_delay = 600;
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int chk = mySensor.read();
|
||||
uint32_t stop = micros();
|
||||
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
dht_delay -= 10;
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
dht_delay += 10;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("Time out A error,\t");
|
||||
dht_delay += 10;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("Time out B error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("Time out C error,\t");
|
||||
dht_delay += 10;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("Time out D error,\t");
|
||||
dht_delay += 10;
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("Sensor not ready,\t");
|
||||
dht_delay += 10;
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("Bit shift error,\t");
|
||||
dht_delay += 10;
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown: ");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
dht_delay += 100;
|
||||
break;
|
||||
}
|
||||
|
||||
dht_delay = constrain(dht_delay, 100, 5000);
|
||||
// DISPLAY DATA
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getTemperature());
|
||||
Serial.print(",\t");
|
||||
uint32_t duration = stop - start;
|
||||
Serial.print(duration);
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getType());
|
||||
Serial.print(",\t");
|
||||
Serial.println(dht_delay);
|
||||
delay(dht_delay);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
115
libraries/DHTINT/examples/dhtint_array/dhtint_array.ino
Normal file
115
libraries/DHTINT/examples/dhtint_array/dhtint_array.ino
Normal file
@ -0,0 +1,115 @@
|
||||
//
|
||||
// FILE: dhtint_array.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
//
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT kitchen(4);
|
||||
DHTINT living(5);
|
||||
DHTINT outside(6);
|
||||
|
||||
DHTINT ar[3] = { kitchen, living, outside };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_array.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
for (int idx = 0; idx < 3; idx++)
|
||||
{
|
||||
test(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int idx = 0; idx < 3; idx++)
|
||||
{
|
||||
test(idx);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void test(int idx)
|
||||
{
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int chk = ar[idx].read();
|
||||
uint32_t stop = micros();
|
||||
|
||||
Serial.print(idx);
|
||||
Serial.print(",\t");
|
||||
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("Time out A error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("Time out B error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("Time out C error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("Time out D error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("Sensor not ready,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("Bit shift error,\t");
|
||||
break;
|
||||
case DHTLIB_WAITING_FOR_READ:
|
||||
Serial.print("Waiting for read,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown: ");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
break;
|
||||
}
|
||||
|
||||
// DISPLAY DATA
|
||||
Serial.print(ar[idx].getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.print(ar[idx].getTemperature());
|
||||
Serial.print(",\t");
|
||||
uint32_t duration = stop - start;
|
||||
Serial.print(duration);
|
||||
Serial.print(",\t");
|
||||
Serial.println(ar[idx].getType());
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
41
libraries/DHTINT/examples/dhtint_debug/dhtint_debug.ino
Normal file
41
libraries/DHTINT/examples/dhtint_debug/dhtint_debug.ino
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// FILE: dhtint_debug.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library debug sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_debug.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(2000);
|
||||
mySensor.read(); // put print statements in core lib (see read())
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
131
libraries/DHTINT/examples/dhtint_endless/dhtint_endless.ino
Normal file
131
libraries/DHTINT/examples/dhtint_endless/dhtint_endless.ino
Normal file
@ -0,0 +1,131 @@
|
||||
//
|
||||
// FILE: dhtint_endless.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
uint32_t count = 0;
|
||||
uint32_t start, stop;
|
||||
|
||||
uint32_t errors[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_endless.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
count++;
|
||||
// show counters for OK and errors.
|
||||
if (count % 50 == 0)
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("OK \tCRC \tTOA \tTOB \tTOC \tTOD \tSNR \tBS \tWFR \tUNK");
|
||||
for (uint8_t i = 0; i < 10; i++)
|
||||
{
|
||||
Serial.print(errors[i]);
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
if (count % 10 == 0)
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("TIM\tCNT\tSTAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
}
|
||||
Serial.print(millis());
|
||||
Serial.print("\t");
|
||||
Serial.print(count);
|
||||
Serial.print("\t");
|
||||
|
||||
start = micros();
|
||||
int chk = mySensor.read();
|
||||
stop = micros();
|
||||
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
errors[0]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("CRC,\t");
|
||||
errors[1]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("TOA,\t");
|
||||
errors[2]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("TOB,\t");
|
||||
errors[3]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("TOC,\t");
|
||||
errors[4]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("TOD,\t");
|
||||
errors[5]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("SNR,\t");
|
||||
errors[6]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("BS,\t");
|
||||
errors[7]++;
|
||||
break;
|
||||
case DHTLIB_WAITING_FOR_READ:
|
||||
Serial.print("WFR,\t");
|
||||
errors[8]++;
|
||||
break;
|
||||
default:
|
||||
Serial.print("U");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
errors[9]++;
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getTemperature());
|
||||
Serial.print(",\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getType());
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,143 @@
|
||||
//
|
||||
// FILE: dhtint_endless_insideFunction.ino
|
||||
// AUTHORS: Rob Tillaart, Vladislaw Kuzmin
|
||||
// PURPOSE: Demonstration example of endless DHT values' reporting in a function
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PINs' layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
uint64_t previousMillis;
|
||||
uint32_t count = 0;
|
||||
uint32_t start, stop;
|
||||
|
||||
uint32_t errors[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_endless.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DHTt(const uint8_t pin)
|
||||
{
|
||||
if (millis() - previousMillis > 2000)
|
||||
{
|
||||
previousMillis = millis();
|
||||
DHTINT mySensor(pin);
|
||||
|
||||
count++;
|
||||
// show counters for OK and errors.
|
||||
if (count % 50 == 0)
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("OK \tCRC \tTOA \tTOB \tTOC \tTOD \tSNR \tBS \tWFR \tUNK");
|
||||
for (uint8_t i = 0; i < 10; i++)
|
||||
{
|
||||
Serial.print(errors[i]);
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
if (count % 10 == 0)
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("TIM\tCNT\tSTAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
}
|
||||
Serial.print(millis());
|
||||
Serial.print("\t");
|
||||
Serial.print(count);
|
||||
Serial.print("\t");
|
||||
|
||||
start = micros();
|
||||
int chk = mySensor.read();
|
||||
stop = micros();
|
||||
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
errors[0]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("CRC,\t");
|
||||
errors[1]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("TOA,\t");
|
||||
errors[2]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("TOB,\t");
|
||||
errors[3]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("TOC,\t");
|
||||
errors[4]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("TOD,\t");
|
||||
errors[5]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("SNR,\t");
|
||||
errors[6]++;
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("BS,\t");
|
||||
errors[7]++;
|
||||
break;
|
||||
case DHTLIB_WAITING_FOR_READ:
|
||||
Serial.print("WFR,\t");
|
||||
errors[8]++;
|
||||
break;
|
||||
default:
|
||||
Serial.print("U");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
errors[9]++;
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getTemperature());
|
||||
Serial.print(",\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// call function
|
||||
DHTt(2);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
58
libraries/DHTINT/examples/dhtint_minimum/dhtint_minimum.ino
Normal file
58
libraries/DHTINT/examples/dhtint_minimum/dhtint_minimum.ino
Normal file
@ -0,0 +1,58 @@
|
||||
//
|
||||
// FILE: dhtint_minimum.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
// #include <dhtnew.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("BEFORE OFFSET");
|
||||
mySensor.read();
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print("\t");
|
||||
Serial.println(mySensor.getTemperature());
|
||||
|
||||
mySensor.setHumOffset(10);
|
||||
mySensor.setTempOffset(-3);
|
||||
|
||||
Serial.println("AFTER OFFSET");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - mySensor.lastRead() > 2000)
|
||||
{
|
||||
mySensor.read();
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print("\t");
|
||||
Serial.println(mySensor.getTemperature());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,57 @@
|
||||
//
|
||||
// FILE: dhtint_minimum_insideFunction.ino
|
||||
// AUTHORS: Rob Tillaart, Vladislaw Kuzmin
|
||||
// PURPOSE: DHTINT library test sketch
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
uint64_t previousMillis;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void DHTt(uint8_t pin)
|
||||
{
|
||||
DHTINT mySensor(pin);
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
if (millis() - mySensor.lastRead() > 2000)
|
||||
{
|
||||
previousMillis = millis();
|
||||
mySensor.read();
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print("\t");
|
||||
Serial.println(mySensor.getTemperature());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// call function...
|
||||
DHTt(2);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,84 @@
|
||||
//
|
||||
// FILE: dhtint_powerDown.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
// to see the effect one must apply a voltmeter to the data pin of the sensor
|
||||
// during the low power mode. Measuring during communication will disrupt the
|
||||
// data transfer.
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(16);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_powerDown.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("\nstartup");
|
||||
delay(2000);
|
||||
|
||||
Serial.println("read sensor with 2 second interval");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int rv = mySensor.read();
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
Serial.println(rv); // will print -7 when measuring voltage
|
||||
}
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getTemperature());
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
Serial.println("switch to low power (~ 5 seconds )");
|
||||
Serial.println("measure voltage");
|
||||
mySensor.powerDown();
|
||||
delay(5000);
|
||||
|
||||
Serial.println("switch sensor on (and wait 2 seconds)");
|
||||
mySensor.powerUp();
|
||||
// wait for 2 seconds.
|
||||
delay(2000);
|
||||
|
||||
Serial.println("read sensor with 2 second interval");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
mySensor.read();
|
||||
Serial.print(mySensor.getHumidity());
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getTemperature());
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,209 @@
|
||||
//
|
||||
// FILE: dhtint_pulse_diag.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINTlibrary pulse measurement tool - diagnostics
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
|
||||
uint8_t _dataPin = 5;
|
||||
uint8_t _wakeupDelay = DHTLIB_DHT_WAKEUP;
|
||||
|
||||
uint16_t count = 0;
|
||||
uint32_t times[100], t = 0;
|
||||
uint8_t idx = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_pulse_diag.ino");
|
||||
Serial.println();
|
||||
|
||||
// default should be HIGH
|
||||
pinMode(_dataPin, OUTPUT);
|
||||
digitalWrite(_dataPin, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
measure();
|
||||
dump();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
void dump()
|
||||
{
|
||||
int i = 1;
|
||||
Serial.println();
|
||||
Serial.print("RUN:\t"); Serial.println(count);
|
||||
Serial.print("IDX:\t"); Serial.println(idx);
|
||||
|
||||
Serial.println("WAKEUP");
|
||||
for (int n = 0; n < 6; n++)
|
||||
{
|
||||
Serial.print("\t");
|
||||
Serial.print(times[i++]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("HUM");
|
||||
for (int n = 0; n < 32; n++)
|
||||
{
|
||||
Serial.print("\t");
|
||||
Serial.print(times[i++]);
|
||||
if ((n & 15) == 15) Serial.println();
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("TEMP");
|
||||
for (int n = 0; n < 32; n++)
|
||||
{
|
||||
Serial.print("\t");
|
||||
Serial.print(times[i++]);
|
||||
if ((n & 15) == 15) Serial.println();
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("CRC");
|
||||
for (int n = 0; n < 16; n++)
|
||||
{
|
||||
Serial.print("\t");
|
||||
Serial.print(times[i++]);
|
||||
if ((n & 7) == 7) Serial.println();
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("BYE");
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
Serial.print("\t");
|
||||
Serial.print(times[i++]);
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void measure()
|
||||
{
|
||||
count++;
|
||||
// yield(); // handle pending interrupts
|
||||
|
||||
// reset measurements table
|
||||
idx = 0;
|
||||
t = micros();
|
||||
for (int i = 0; i < 100; i++) times[i] = 0;
|
||||
|
||||
times[idx++] = micros();
|
||||
// REQUEST SAMPLE - SEND WAKEUP TO SENSOR
|
||||
pinMode(_dataPin, OUTPUT);
|
||||
digitalWrite(_dataPin, LOW);
|
||||
// add 10% extra for timing inaccuracies in sensor.
|
||||
delayMicroseconds(_wakeupDelay * 1100UL);
|
||||
|
||||
Serial.print("awake ");
|
||||
|
||||
times[idx++] = micros();
|
||||
// HOST GIVES CONTROL TO SENSOR
|
||||
pinMode(_dataPin, INPUT_PULLUP);
|
||||
|
||||
// DISABLE INTERRUPTS when clock in the bits
|
||||
// noInterrupts(); // gives problems on AVR
|
||||
|
||||
|
||||
times[idx++] = micros();
|
||||
// SENSOR PULLS LOW after 20-40 us => if stays HIGH ==> device not ready
|
||||
while (digitalRead(_dataPin) == HIGH);
|
||||
|
||||
Serial.print("2 ");
|
||||
|
||||
times[idx++] = micros();
|
||||
// SENSOR STAYS LOW for ~80 us => or TIMEOUT
|
||||
while (digitalRead(_dataPin) == LOW);
|
||||
|
||||
Serial.print("3 ");
|
||||
|
||||
|
||||
times[idx++] = micros();
|
||||
// SENSOR STAYS HIGH for ~80 us => or TIMEOUT
|
||||
while (digitalRead(_dataPin) == HIGH);
|
||||
times[idx++] = micros();
|
||||
|
||||
Serial.print("4 ");
|
||||
|
||||
|
||||
// SENSOR HAS NOW SEND ACKNOWLEDGE ON WAKEUP
|
||||
// NOW IT SENDS THE BITS
|
||||
|
||||
// READ THE OUTPUT - 40 BITS => 5 BYTES
|
||||
uint32_t start = micros();
|
||||
uint8_t i = 40;
|
||||
for (i = 40; i != 0; i--)
|
||||
{
|
||||
times[idx++] = micros();
|
||||
// EACH BIT START WITH ~50 us LOW
|
||||
while (digitalRead(_dataPin) == LOW)
|
||||
{
|
||||
if (micros() - start > 10000)
|
||||
{
|
||||
Serial.print(" <");
|
||||
Serial.println(i);
|
||||
Serial.println("> ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
times[idx++] = micros();
|
||||
// DURATION OF HIGH DETERMINES 0 or 1
|
||||
// 26-28 us ==> 0
|
||||
// 70 us ==> 1
|
||||
while (digitalRead(_dataPin) == HIGH)
|
||||
{
|
||||
if (micros() - start > 10000)
|
||||
{
|
||||
Serial.println(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print("5 ");
|
||||
|
||||
times[idx++] = micros();
|
||||
// After 40 bits the sensor pulls the line LOW for 50 us
|
||||
// TODO: should we wait?
|
||||
while (digitalRead(_dataPin) == LOW);
|
||||
|
||||
Serial.print("6 ");
|
||||
|
||||
times[idx++] = micros();
|
||||
times[idx++] = micros();
|
||||
|
||||
for (int n = 100; n > 0; n--)
|
||||
{
|
||||
times[n] -= times[n - 1];
|
||||
}
|
||||
|
||||
Serial.println("7 ");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
60
libraries/DHTINT/examples/dhtint_runtime/dhtint_runtime.ino
Normal file
60
libraries/DHTINT/examples/dhtint_runtime/dhtint_runtime.ino
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// FILE: dhtint_runtime.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
uint32_t lastTime = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_runtime");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - lastTime > 2000)
|
||||
{
|
||||
lastTime = millis();
|
||||
for (int pin = 6; pin < 10; pin++)
|
||||
{
|
||||
DHTINT sensor(pin);
|
||||
sensor.read();
|
||||
Serial.print(pin);
|
||||
Serial.print("\t");
|
||||
Serial.print(sensor.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
Serial.println(sensor.getTemperature(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Do other things here
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,131 @@
|
||||
//
|
||||
// FILE: dhtint_setReadDelay.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library waitForRead example sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_setReadDelay");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
delay(2000); // boot time
|
||||
|
||||
mySensor.setWaitForReading(true);
|
||||
|
||||
uint16_t rd = 2000;
|
||||
uint16_t step = 2000;
|
||||
|
||||
while (step)
|
||||
{
|
||||
step /= 2;
|
||||
mySensor.setReadDelay(rd);
|
||||
int chk = mySensor.read();
|
||||
|
||||
Serial.print("ReadDelay (ms): ");
|
||||
Serial.print(mySensor.getReadDelay());
|
||||
Serial.print("\t T: ");
|
||||
Serial.print(mySensor.getTemperature(), 1);
|
||||
Serial.print("\t H: ");
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
printStatus(chk);
|
||||
|
||||
if (chk == DHTLIB_OK) rd -= step;
|
||||
else {
|
||||
rd += step;
|
||||
mySensor.read();
|
||||
}
|
||||
}
|
||||
|
||||
// safety margin of 100 uSec
|
||||
rd += 100;
|
||||
mySensor.setReadDelay(rd);
|
||||
Serial.print("\nreadDelay set to (ms) : ");
|
||||
Serial.print(mySensor.getReadDelay());
|
||||
Serial.println("\n\nDuration test started");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Note: the library prevents reads faster than readDelay...
|
||||
// it will return previous values for T & H
|
||||
int chk = mySensor.read();
|
||||
Serial.print(millis());
|
||||
Serial.print("\t");
|
||||
Serial.print(mySensor.getReadDelay());
|
||||
Serial.print("\t T: ");
|
||||
Serial.print(mySensor.getTemperature(), 1);
|
||||
Serial.print("\t H: ");
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
printStatus(chk);
|
||||
}
|
||||
|
||||
|
||||
void printStatus(int chk)
|
||||
{
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("Time out A error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("Time out B error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("Time out C error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("Time out D error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("Sensor not ready,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("Bit shift error,\t");
|
||||
break;
|
||||
case DHTLIB_WAITING_FOR_READ:
|
||||
Serial.print("Waiting for read,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown: ");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
break;
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,70 @@
|
||||
//
|
||||
// FILE: dhtint_suppressError.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
// run sketch without connected sensor to see effect
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_suppressError");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
// test flag working => prints 010
|
||||
Serial.print(mySensor.getSuppressError());
|
||||
mySensor.setSuppressError(true);
|
||||
Serial.print(mySensor.getSuppressError());
|
||||
mySensor.setSuppressError(false);
|
||||
Serial.print(mySensor.getSuppressError());
|
||||
|
||||
// change to false to see difference
|
||||
mySensor.setSuppressError(true);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - mySensor.lastRead() > 2000)
|
||||
{
|
||||
if ((count % 10) == 0) Serial.println("\nERR\tHUM\tTEMP");
|
||||
count++;
|
||||
|
||||
int errcode = mySensor.read();
|
||||
Serial.print(errcode);
|
||||
Serial.print("\t");
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
Serial.println(mySensor.getTemperature(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
144
libraries/DHTINT/examples/dhtint_test/dhtint_test.ino
Normal file
144
libraries/DHTINT/examples/dhtint_test/dhtint_test.ino
Normal file
@ -0,0 +1,144 @@
|
||||
//
|
||||
// FILE: dhtint_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DHTINT library test sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("dhtint_test.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("\n1. Type detection test, first run might take longer to determine type");
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
|
||||
Serial.println("\n2. Humidity offset test");
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
mySensor.setHumOffset(2.5);
|
||||
test();
|
||||
mySensor.setHumOffset(5.5);
|
||||
test();
|
||||
mySensor.setHumOffset(-5.5);
|
||||
test();
|
||||
mySensor.setHumOffset(0);
|
||||
test();
|
||||
|
||||
Serial.println("\n3. Temperature offset test");
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
mySensor.setTempOffset(2.5);
|
||||
test();
|
||||
mySensor.setTempOffset(5.5);
|
||||
test();
|
||||
mySensor.setTempOffset(-5.5);
|
||||
test();
|
||||
mySensor.setTempOffset(0);
|
||||
test();
|
||||
|
||||
Serial.println("\n4. LastRead test");
|
||||
mySensor.read();
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (millis() - mySensor.lastRead() > 1000)
|
||||
{
|
||||
mySensor.read();
|
||||
Serial.println("actual read");
|
||||
}
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getTemperature(), 1);
|
||||
delay(250);
|
||||
}
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
{
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int chk = mySensor.read();
|
||||
uint32_t stop = micros();
|
||||
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("Time out A error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("Time out B error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("Time out C error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("Time out D error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("Sensor not ready,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("Bit shift error,\t");
|
||||
break;
|
||||
case DHTLIB_WAITING_FOR_READ:
|
||||
Serial.print("Waiting for read,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown: ");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
break;
|
||||
}
|
||||
|
||||
// DISPLAY DATA
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getTemperature(), 1);
|
||||
Serial.print(",\t");
|
||||
uint32_t duration = stop - start;
|
||||
Serial.print(duration);
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getType());
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,126 @@
|
||||
//
|
||||
// FILE: dhtint_waitForRead.ino
|
||||
// AUTHOR: Mr-HaleYa
|
||||
// PURPOSE: DHTINT library waitForRead example sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("\n");
|
||||
Serial.println("dhtint_waitForRead.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("This sketch shows the use of the setWaitForReading() flag (default value is false).");
|
||||
Serial.println("Setting the flag to true will make the sketch wait until the sensor is ready to take another reading.");
|
||||
Serial.println("Otherwise, if the sensor was not ready to take a new reading the previous data will be returned.");
|
||||
Serial.println("Note: Sensor reading times vary with sensor type");
|
||||
|
||||
Serial.println("\n1. Test with WaitForReading not set");
|
||||
Serial.println("AGE\tHUMI\tTEMP\tTIME\tTYPE\tSTAT");
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
|
||||
Serial.print("\n2. Test with WaitForReading set to ");
|
||||
mySensor.setWaitForReading(true);
|
||||
Serial.println(mySensor.getWaitForReading() ? "true" : "false");
|
||||
Serial.println("AGE\tHUMI\tTEMP\tTIME\tTYPE\tSTAT");
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
test();
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
{
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int chk = mySensor.read();
|
||||
uint32_t stop = micros();
|
||||
uint32_t duration = stop - start;
|
||||
|
||||
// DISPLAY IF OLD OR NEW DATA
|
||||
if (duration > 50){Serial.print("NEW\t");}else{Serial.print("OLD\t");}
|
||||
|
||||
// DISPLAY DATA
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getTemperature(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(duration);
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getType());
|
||||
Serial.print(",\t");
|
||||
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("Time out A error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("Time out B error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("Time out C error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("Time out D error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("Sensor not ready,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("Bit shift error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown: ");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
break;
|
||||
}
|
||||
Serial.println();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,101 @@
|
||||
//
|
||||
// FILE: dhtint_waitForRead_nonBlocking.ino
|
||||
// AUTHOR: Budulinek
|
||||
// PURPOSE: DHTINT non-blocking wait for read example sketch for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTINT
|
||||
|
||||
// DHT PIN layout from left to right
|
||||
// =================================
|
||||
// FRONT : DESCRIPTION
|
||||
// pin 1 : VCC
|
||||
// pin 2 : DATA
|
||||
// pin 3 : Not Connected
|
||||
// pin 4 : GND
|
||||
|
||||
|
||||
#include <dhtint.h>
|
||||
|
||||
DHTINT mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while(!Serial); // MKR1010 needs this
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("\n");
|
||||
Serial.println("dhtint_waitForRead_nonBlocking.ino");
|
||||
Serial.print("DHTINT_LIB_VERSION: ");
|
||||
Serial.println(DHTINT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
// MKR1010 needs this
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("This example shows how you can use the output of the read() function to implement non-blocking waiting for read.");
|
||||
Serial.println("In this example, Arduino continuously polls the read() function and returns fresh data (or an error) only when the read delay is over.");
|
||||
Serial.println("Infinite loop.");
|
||||
Serial.println();
|
||||
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int chk = mySensor.read();
|
||||
uint32_t stop = micros();
|
||||
|
||||
if (chk != DHTLIB_WAITING_FOR_READ) {
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_A:
|
||||
Serial.print("Time out A error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_B:
|
||||
Serial.print("Time out B error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_C:
|
||||
Serial.print("Time out C error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT_D:
|
||||
Serial.print("Time out D error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
||||
Serial.print("Sensor not ready,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_BIT_SHIFT:
|
||||
Serial.print("Bit shift error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown: ");
|
||||
Serial.print(chk);
|
||||
Serial.print(",\t");
|
||||
break;
|
||||
}
|
||||
|
||||
// DISPLAY DATA
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(mySensor.getTemperature(), 1);
|
||||
Serial.print(",\t");
|
||||
uint32_t duration = stop - start;
|
||||
Serial.print(duration);
|
||||
Serial.print(",\t");
|
||||
Serial.println(mySensor.getType());
|
||||
}
|
||||
|
||||
// do some other stuff
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/DHTINT/library.json
Normal file
21
libraries/DHTINT/library.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "DHTINT",
|
||||
"keywords": "DHT11, DHT22, DHT33, DHT44, AM2301, AM2302, AM2303, autodetect, offset, interrupt, powerDown",
|
||||
"description": "Arduino library for DHT sensors. Integer only to save footprint.",
|
||||
"authors":
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
},
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DHTINT.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "dhtint.h"
|
||||
}
|
11
libraries/DHTINT/library.properties
Normal file
11
libraries/DHTINT/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=DHTINT
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for DHT temperature and humidity sensor. Integer only to save footprint.
|
||||
paragraph=based upon DHTNEW
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/DHTINT
|
||||
architectures=*
|
||||
includes=dhtint.h
|
||||
depends=
|
143
libraries/DHTINT/test/unit_test_001.cpp
Normal file
143
libraries/DHTINT/test/unit_test_001.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-05-08
|
||||
// PURPOSE: unit tests for the DHT temperature and humidity sensor
|
||||
// https://github.com/RobTillaart/DHTINT
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "dhtint.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "DHTINT_LIB_VERSION: %s\n", (char *) DHTINT_LIB_VERSION);
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
assertEqual( 0, DHTLIB_OK );
|
||||
assertEqual(-1, DHTLIB_ERROR_CHECKSUM );
|
||||
assertEqual(-2, DHTLIB_ERROR_TIMEOUT_A );
|
||||
assertEqual(-3, DHTLIB_ERROR_BIT_SHIFT );
|
||||
assertEqual(-4, DHTLIB_ERROR_SENSOR_NOT_READY);
|
||||
assertEqual(-5, DHTLIB_ERROR_TIMEOUT_C );
|
||||
assertEqual(-6, DHTLIB_ERROR_TIMEOUT_D );
|
||||
assertEqual(-7, DHTLIB_ERROR_TIMEOUT_B );
|
||||
assertEqual(-8, DHTLIB_WAITING_FOR_READ );
|
||||
|
||||
assertEqual(-100, DHTLIB_HUMIDITY_OUT_OF_RANGE );
|
||||
assertEqual(-101, DHTLIB_TEMPERATURE_OUT_OF_RANGE);
|
||||
|
||||
assertEqual(-999, DHTLIB_INVALID_VALUE);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
DHTINT dht(4);
|
||||
|
||||
// verify default flags
|
||||
// assertEqual(0, dht.getType()); // calls read which blocks.
|
||||
assertEqual(0, dht.getHumOffset());
|
||||
assertEqual(0, dht.getTempOffset());
|
||||
#if defined(__AVR__)
|
||||
fprintf(stderr, "__AVR__ defined.");
|
||||
assertFalse(dht.getDisableIRQ());
|
||||
#else
|
||||
fprintf(stderr, "__AVR__ not defined.");
|
||||
assertTrue(dht.getDisableIRQ());
|
||||
#endif
|
||||
assertFalse(dht.getWaitForReading());
|
||||
assertEqual(0, dht.getReadDelay());
|
||||
assertFalse(dht.getSuppressError());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_hum_temp)
|
||||
{
|
||||
DHTINT dht(4);
|
||||
|
||||
assertEqual(0, dht.getHumidity());
|
||||
assertEqual(0, dht.getHumOffset());
|
||||
dht.setHumOffset(2);
|
||||
assertEqual(2, dht.getHumOffset());
|
||||
|
||||
assertEqual(0, dht.getTemperature());
|
||||
assertEqual(0, dht.getTempOffset());
|
||||
dht.setTempOffset(-3);
|
||||
assertEqual(-3, dht.getTempOffset());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_process_flags)
|
||||
{
|
||||
DHTINT dht(4);
|
||||
|
||||
dht.setType(11);
|
||||
assertEqual(11, dht.getType());
|
||||
dht.setType(22);
|
||||
assertEqual(22, dht.getType());
|
||||
|
||||
dht.setDisableIRQ(true);
|
||||
assertTrue(dht.getDisableIRQ());
|
||||
dht.setDisableIRQ(false);
|
||||
assertFalse(dht.getDisableIRQ());
|
||||
|
||||
dht.setWaitForReading(true);
|
||||
assertTrue(dht.getWaitForReading());
|
||||
dht.setWaitForReading(false);
|
||||
assertFalse(dht.getWaitForReading());
|
||||
|
||||
dht.setReadDelay(1500);
|
||||
assertEqual(1500, dht.getReadDelay());
|
||||
dht.setType(11);
|
||||
dht.setReadDelay();
|
||||
assertEqual(0, dht.getReadDelay());
|
||||
dht.setType(22);
|
||||
dht.setReadDelay();
|
||||
assertEqual(0, dht.getReadDelay());
|
||||
|
||||
dht.setSuppressError(true);
|
||||
assertTrue(dht.getSuppressError());
|
||||
dht.setSuppressError(false);
|
||||
assertFalse(dht.getSuppressError());
|
||||
}
|
||||
|
||||
|
||||
unittest(test_read)
|
||||
{
|
||||
DHTINT dht(4);
|
||||
|
||||
fprintf(stderr, "\tread() cannot be tested GODMODE?\n");
|
||||
// int rc = dht.read();
|
||||
// fprintf(stderr, "%d\n", rc);
|
||||
|
||||
long lr = dht.lastRead();
|
||||
fprintf(stderr, "\ttime since lastRead %ld\n", lr);
|
||||
}
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
Loading…
x
Reference in New Issue
Block a user