Code Monkey home page Code Monkey logo

simpledht's Introduction

SimpleDHT

Description

An Arduino library for the DHT series of low-cost temperature/humidity sensors.

You can find DHT11 and DHT22 tutorials here.

Installation

First Method

image

  1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
  2. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
  3. Then search for SimpleDHT using the search bar.
  4. Click on the text area and then select the specific version and install it.

Second Method

  1. Navigate to the Releases page.
  2. Download the latest release.
  3. Extract the zip file
  4. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library

Usage

To use this library:

  1. Open example: Arduino => File => Examples => SimpleDHT => DHT11Default
  2. Connect the DHT11 and upload the program to Arduino.
  3. Open the Serial Window of Arduino IDE, we got the result as follows.
=================================
Sample DHT11...
Sample OK: 19 *C, 31 H
=================================
Sample DHT11...
Sample OK: 19 *C, 31 H
=================================

Remark: For DHT11, no more than 1 Hz sampling rate (once every second). Remark: For DHT22, no more than 0.5 Hz sampling rate (once every 2 seconds).

Features

  • Simple

    Simple C++ code with lots of comments.

  • Stable

    Strictly follow the standard DHT protocol.

  • Fast

    Support 0.5HZ(DHT22) or 1HZ(DHT11) sampling rate.

  • Compatible

    SimpleDHT sensor library is compatible with multiple low-cost temperatures and humidity sensors like DHT11 and DHT22. A few examples are implemented just to demonstrate how to modify the code for different sensors.

  • MIT License

    DHT sensor library is open-source and uses one of the most permissive licenses so you can use it on any project.

    • Commercial use
    • Modification
    • Distribution
    • Private use

Functions

  • read()
  • setPinInputMode()
  • setPin()
  • getBitmask()
  • getPort()
  • levelTime()
  • bits2byte()
  • parse()
  • read2()
  • sample()

Sensors

Examples

This library including the following examples:

  1. DHT11Default: Use DHT11 to sample.
  2. DHT11WithRawBits: Use DHT11 to sample and get the 40bits RAW data.
  3. DHT11ErrCount: Use DHT11 to sample and stat the success rate.
  4. DHT22Default: Use DHT22 to sample.
  5. DHT22WithRawBits: Use DHT22 to sample and get the 40bits RAW data.
  6. DHT22Integer: Use DHT22 to sample and ignore the fractional data.
  7. DHT22ErrCount: Use DHT22 to sample and stat the success rate.
  8. TwoSensorsDefault: Use two DHT11 to sample.

One of the SimpleDHT examples is the following:

  • DHT22Integer

#include <SimpleDHT.h>

int pinDHT22 = 2;
SimpleDHT22 dht22(pinDHT22);

void setup() {
  Serial.begin(115200);
}

void loop() {

  Serial.println("=================================");
  Serial.println("Sample DHT22...");

  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.print(SimpleDHTErrCode(err));
    Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(2000);
    return;
  }

  Serial.print("Sample OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" RH%");

  delay(2500);
}

Links

  1. adafruit/DHT-sensor-library
  2. Arduino #4469: Add SimpleDHT library.
  3. DHT11 datasheet and protocol.
  4. DHT22 datasheet and protoocl.

Winlin 2016.1

Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell others about this library
  • Contribute new protocols

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Credits

The author and maintainer of this library is Winlin [email protected].

Based on previous work by:

  • t-w
  • O. Santos
  • P. H. Dabrowski
  • per1234
  • P. Rinn
  • G. M. Vacondio
  • D. Faust
  • C. Stroie
  • Samlof
  • Agha Saad Fraz

License

This library is licensed under MIT.

simpledht's People

Contributors

aghasaad04 avatar cstroie avatar d2bit avatar danielfaust avatar dvsproductions avatar gvacondio avatar innir avatar per1234 avatar phd avatar samlof avatar santosomar avatar t-w avatar winlinvip avatar yasiupl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

simpledht's Issues

Is it possible to set the pin mode of the DHT22 pin?

Is it possible to set the pinMode for the pin used by SimpleDHT to use the internal pullup?

Also, is the internal pullup enough for the DHT22? (I looked at what datasheets I could find, but, didn't see any specification. )

Reading errors

DHT22 with ESP8266 producing in my case a lot of repeating read errors (sample rate 5sec), error rate was about 9:1 (error:success). Little looking in code and here seems was that issue:

int SimpleDHT::confirm(int pin, int us, byte level) {
...  
      delayMicroseconds(10);
...
}

changing delayMicroseconds(10); to delayMicroseconds(20); fix this problem, 0 errors after 2hours of testing

Getting error `SimpleDHTErrStartLow` unnecessarily

In my DHT sensor, I'm consistently seeing a low time of 23-24us measured here:

https://github.com/winlinvip/SimpleDHT/blob/1.0.12/SimpleDHT.cpp#L220

I'm not sure if it's because the microcontroller I'm using has timing issues, or it's an odd DHT sensor, but simply reducing the threshold from 30 to 20 is the difference between the sensor failing continuously, and consistently reading successfully.

Would it make sense to allow this threshold to be customizable? Will it break things to allow slightly faster values?

SimpleDht rawbits.

Hello .i am using the Ardunio simulator on the web. I am using the SimpleDHT lib. in that i use the simpledht using rawbits.
but it getting 0 temp or 0 humidity.

byte data[5] = {0};

How can i pass the 8 bit data to get appropriate output.

Error Code

Hello,

My project was working fine, but suddently it only reports errors:

"Read DHT2 failed, err2=3088"
"Read DHT2 failed, err2=2832"

The errors keep changing, and I can not find a reference list regarding what the error actually means.
It is not the sensor, It also gives errors with others. It´s a DHT22 sensor.

Can you please share a list of what the errors mean?

Thanks

Negative temperatures

Have you tested this library with negative temperatures?

With a DHT22 I'm getting values like -3276.3°C for values slightly below 0°C (possibly for -0.7°C).

-3277.0°C is not reached, that one is then 0.0°C

First read always fail with error 101

Hi,

I'm using code from sample with DHT22:

if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000); return; }

It always fails the first time.
It's annoying because I use esp8266 in deepmode. So the code, as it's executed after reset, is always in a first execution.

I've changed my code to double the read with a delay before the second:

if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { delay(1000); if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000); return; } }

It works but it's ugly and takes more time (more power is consumed).
What can I do else ?
I don't have a DHT11 to test.

Thanks in advance.

Noury

Sample DHT22... Read DHT22 failed, err=101

Kit: Wemos D1 Mini, Sensor DHT22

I've used the SimpleDHT code and have the required libraries. Compiled and uploaded OK but keep getting

Sample DHT22...
Read DHT22 failed, err=101

I'm powering the sensor externally and connected it to D4 on my Wemos D1 Mini board. The code in the same to assign the pin is:

int pinDHT22 = 2;

I'm not sure what that 2 refers to. Is it D2, or GPIO2 or physical pin 2 (which is A0) can someone who's used this successfully please clarify?
Wemos Pinout is here: https://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/

Thanks in advance.

Suggestion

Hello,
I suggest to invert lines 66 end 67 In SampleDHT.cpp code. This is because, after the start signal, the sensor pull down the data line before the wait time of 30uS.
In attach you can see the effect:

ds1z_quickprint22

Inverting the two lines of code, after submitting the start signal, data line switch immediately in INPUT mode and the problem is avoided.

Regards
Gian Marcoi

Compilation problem with modules

.../Arduino/libraries/SimpleDHT/SimpleDHT.cpp:72:27: error: no 'int SimpleDHT::getBitmask()' member function declared in class 'SimpleDHT'
 int SimpleDHT::getBitmask() {
                           ^
.../Arduino/libraries/SimpleDHT/SimpleDHT.cpp:76:24: error: no 'int SimpleDHT::getPort()' member function declared in class 'SimpleDHT'
 int SimpleDHT::getPort() {
                        ^

The path is OK, I've modified it
This is the first time i'm trying to use something else but DHT.h
Feel free to ask for any tests

Does not work with Teensy

Hi,
I've got a DHT22, running the DHT22Default example.
I'm trying to get this library to work with the Teensy 3.6 and I'm getting a standard error:
err=101

This is using a cloned library of this git so latest version I assume. The board works with the standard ADAFRUIT library but I'd prefer to use this one as I can access just the simple bits which would speed up the data collection. I've read that the Teensy is much more accurate with its delayMicroseconds and the CPU I'm running clocks at 180MHz whereas an arduino would be around 18MHz, maybe I should just slow down the transfer?
Thanks,
Rowan

UPDATE ***
After reading https://forum.pjrc.com/threads/16806-T3-FYI-Adafruit-DHT22-AM2302
I changed the delayMicroseconds(10) to (15) in your .cpp and (30) to (35) and got this output

Sample OK: 0 *C, 2 %

Now unfortunately I think this data is incorrect as it's definitely not 0*C!
I'll have another go tomorrow

diff values for Humidity for dht11&dht22

Hi,
thanks for library,

i have an issue that i don't understand,

i am reading different Humidity values on same breadboard with diff sensor,

here is the result:
Sample RAW Bits: 0100 0011 0000 0000 0001 0101 0000 0000 0101 1000
Sample OK for DHT11: 21 *C, 67 %
Sample RAW Bits: 0000 0001 1110 1011 0000 0000 1100 1001 1011 0101
Sample OK for DHT22: 20 *C, 49 %

Where are the error codes listed?

This library works fine for me, except in the beginning and randomly distributed throughout I will receive 4 digit error codes. Where can I look these up? Thanks.

err 100

I tried with arduino DTH11
rev 1.0.10
and got the following error

Sample DHT11...
Read DHT11 failed, err=100

I don't know what err 100 means

Problems using Arduino Uno

I am using version 1.0.12 with Arduino Uno.
I used the Example DHT11 files and needed to change setup to:

Serial.begin(9600);

Because Arduino Only support this. Using higher values results in crap charachters displayed on serial display.
I obtain the following errors:

Sample DHT11...
Read DHT11 failed, err=4112

Sample DHT11...
Read DHT11 failed, err=3088

Sample DHT11...
Read DHT11 failed, err=4112

Sample DHT11...
Read DHT11 failed, err=3088

(removed the ===)

Is it possible that the sensor cannot be used on Arduino Uno?
Or is it broken?

Errors with timerone

Got such code

// Encoder
#include <ClickEncoder.h>
#include <TimerOne.h>

// DHT
#include <SimpleDHT.h>

char outTemp[50];

int pinDHT11 = 3;
SimpleDHT11 dht11(pinDHT11);

ClickEncoder *encoder;
int16_t last, value;

void timerIsr() {
  encoder->service();
}
int encoderValue;
int encoderPosition;

void setup() {
  Serial.begin(9600);

  encoder = new ClickEncoder(A2, A3, 4);
  encoder->setAccelerationEnabled(true);

  Timer1.initialize();
  Timer1.setPeriod(1000);
  Timer1.attachInterrupt(timerIsr); 
  last = -1;
}

void loop() {
  value += encoder->getValue();
  
  if (value/4 != last) {
    encoderValue = value/4;
    encoderPosition = encoderValue%20;
      
    last = encoderValue;

    if(encoderPosition <0)
      encoderPosition = -encoderPosition;

    Serial.print("last: ");
    Serial.println((int)last);
    Serial.print("position: ");
    Serial.println((int)encoderPosition);
  }
  
  printTemp();
  delay(50);
}

void printTemp() {
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    delay(100);
    Serial.print("DHT11 failed: ");
    Serial.println(err); 
  }
  else {
    snprintf(outTemp, 50, "       %dC %d%%", (int)temperature, (int)humidity);
    Serial.println(outTemp);
  }
}

Got such output
screen shot 2018-10-28 at 19 17 23

Also it freezes for 5 secs about every 5 secs also. So sec working, another 5 sec freezing

Running on Mega2560 cause unstable reading results

HI! Thanks for this great library!

I want to report a strange behavior on mega2560.
Same dht22, VCC 5v, same pullUP 10K resistor, same wires, same Pin on board.

attempt №1 , I connect it to my Arduino Nano and run example sketch:
Arduino Nano (Atmega 328P)

=================================
Sample DHT22 with error count
//...iterate 100 times
24.80 *C, 27.50 RH%, total: 100, err: 0, success rate: 100.00%

Success rate 100% after 100 iterates.

Attempt №2, I connect it to my Arduino Mega Pro and run same sketch:
Arduino Mega Pro (Atmega2560 / 12MHz)

=================================
Sample DHT22 with error count
//...iterate 100 times
Read DHT22 failed, err=105
0.00 *C, 0.00 RH%, total: 100, err: 31, success rate: 69.00%

attempt №3
Arduino Mega (Atmega 2560 / 16MHz)

=================================
Sample DHT22 with error count
//...iterate 100 times
Read DHT22 failed, err=105 // happened not before next line
24.10 *C, 31.80 RH%, total: 100, err: 29, success rate: 71.00%

On both mega2560 error with code 105 occur. (checksum)
What can be a problem?

undeclared functions when compiling for non-AVR boards

when compiling for ESP8266 or ESP32 (others propably too) compilation fails with the following error:

C:\Users\user\Documents\Arduino\libraries\SimpleDHT\SimpleDHT.cpp:72:27: error: no 'int SimpleDHT::getBitmask()' member function declared in class 'SimpleDHT'

int SimpleDHT::getBitmask() {

                       ^

C:\Users\user\Documents\Arduino\libraries\SimpleDHT\SimpleDHT.cpp:76:24: error: no 'int SimpleDHT::getPort()' member function declared in class 'SimpleDHT'

int SimpleDHT::getPort() {

                    ^

this is because the function definitions of SimpleDHT::getBitmask() and SimpleDHT::getPort() are not enclosed within a conditional compilation block, unlike their declarations in SimpleDHT.h

Stat the sampling success rate

It seems DHT11 is more stable than DHT22. DHT22 may sample failed for 101 or 105 sometimes. Let me write examples to stat the success rate.

New Feature suggestion 😀 Link to Online Simulator for SimpleDHT

Hi There,

thank you for the working code. We liked it. We are working on the Arduino emulator where users can freely run and check the libraries without the actual hardware or the sensor. This will be helpful to make a quick test or a decision on the run.

Example: For Adafruit library we have here a permanent link: https://wokwi.com/arduino/libraries/DHT-sensor-library where the users can just try the library and get a good feel of the outcome even before they buy the hardware/rig up the hardware.

Example 1: https://wokwi.com/arduino/libraries/DHT-sensor-library/DHT-Tester
Example 2: https://wokwi.com/arduino/libraries/DHT-sensor-library/DHT-unified-sensor

Also, we would like to ask for your suggestions and feedback. We will be happy to implement the useful features to make it more user friendly and helpful to the Arduino community 😍

I hope, this will be helpful for the users, using this library. We will be happy to share the link, create a Pull Request for the readMe file (for example) to provide the permanent simulated pages for the SimpleDHT library.

We will be happy to hear from you. Thank you :)

doubt: what is 'raw bits' ?

Hi! How use it ? What is it useful for?

NOTE:
library works with Arduino IDE v1.6.13

BN: Arduino/Genuino Uno
VID: 2341
PID: 0043
SN: 95530343335351

Err : 5904 and/or 6160

Hello, I find myself with random errors "5904" or "6160" and I have no idea what they mean. I can't find any reference to these error codes in the code available on github but maybe I'm not looking for it. Please excuse me.

Incorrect SimpleDHTErr* status returned by read(int pin, ...) and read2(int pin, ...) methods

There is a nasty bug in read()/read2() methods taking the pin argument:

  • int SimpleDHT::read(int pin, byte* ptemperature, byte* phumidity, byte pdata[40])
  • int SimpleDHT11::read2(int pin, float* ptemperature, float* phumidity, byte pdata[40])
  • int SimpleDHT22::read2(int pin, float* ptemperature, float* phumidity, byte pdata[40])

They do not have return statements, so they return random value as temperature reading status.

DHT22 reading doesn't work when WiFi switched off

Hi,
I changed from version 1.0.12 to 1.0.14 and now the reading of values from DHT22 doesn't work anymore, when Wifi is switchde off.

I use ESP8266.

SimpleDHT22 dht22(DHTPIN);
...
WiFi.mode( WIFI_OFF );
WiFi.forceSleepBegin();
delay( 1 );
...
err = SimpleDHTErrSuccess;
if ((err = dht22.read2(&temp, &hum, NULL)) != SimpleDHTErrSuccess)
{

Without the 2nd part all works fine also with v1.0.14, but when using the 2nd part, it only work with v1.0.12.

DHT22 does not work inside sketch

I am using Arduino UNO.

The DHT22default sketch compiles and runs well.

I am attempting to apply the same approach as in the sketch but display the results on a 1.8" TFT.

I am however unable to achieve this as the TFT enabled sketch fails to read from the DHT22 sensor and gives me error 4112 or 3088 on serial or on TFT (I got that to work)

The DHT22 deployment is basically identical to the sketch except I used #define instead of int to bind the pin. #define works in the DHT22default sketch when I made the same change.

So, basically when I run the DHT22default sketch, the sensor works, when I run the (seemingly) identical sketch modified for TFT output, the sensor fails.

Here is the sketch. I also included the serial output to help me debug. It did not help.

`

// DHT
#include <SimpleDHT.h>

// include TFT and SPI libraries
#include <TFT.h>
#include <SPI.h>

// pin definition for Arduino UNO
#define cs 10
#define dc 9
#define rst 8

// DHT section
#define pinDHT22 12
// int pinDHT22 = 12;
SimpleDHT22 dht22(pinDHT22);

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

void setup() {
Serial.begin(9600);

//initialize the library
TFTscreen.begin();

// clear the screen with a black background
TFTscreen.background(0, 0, 0);
//set the text size
TFTscreen.setTextSize(1);
TFTscreen.stroke(255,0,255);
TFTscreen.text("=================================", 6, 6);
TFTscreen.text("Sample DHT22...", 6, 14);
delay (1000);
TFTscreen.background(0,0,0);

}

void loop() {
TFTscreen.background(0,0,0);
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT22 failed, err="); Serial.println(err);
}
String errorValue = String(err);
char errorPrint[10];
if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
errorValue.toCharArray(errorPrint, 10); TFTscreen.text("Read DHT22 failed, err=", 6, 6); TFTscreen.text(errorPrint, 6, 14); delay(2000); return;
}

TFTscreen.text ("Sensor Ok", 6, 6);
delay (2000);
TFTscreen.background(0,0,0);

Serial.print("Sample OK: ");
Serial.print((float)temperature); Serial.print(" *C, ");
Serial.print((float)humidity); Serial.println(" RH%");

// DHT22 sampling rate is 0.5HZ.
delay(2500);

}`

levelTimeout is 5s not 500ms

class SimpleDHT {
protected:
    long levelTimeout = 5000000; // 500ms

I just noticed that the comment in the file SimpleDHT.h says "500ms" for the variable long levelTimeout = 5000000;. The number works out to be 5 seconds, not 500ms. I don't know what value is better, so either the comment should be changed to "5 seconds" or the value should be changed to 500000.

Even better, the value should be customizable using another method, like setTimeout, similar to other Arduino libraries.

this is probably not an issue...

I'm using Arduino IDE 1.8.3 on osx.

The static values aren't working
I get an error

DHT11:26: error: 'SimpleDHT' has not been declared
   int err = SimpleDHT::ErrSuccess; 
             ^
DHT11:27: error: 'SimpleDHT' has not been declared

I'm assuming this is more an issue of my compiler than the code? If so any idea how to fix or what I'd search the net for? (I know I can hack it by substituting 0 for SimpleDHT::ErrSuccess, just wondering how to fix that the static class member's not being seen.)

read2( ) which uses float temperature and humidity only return integer values.

I noticed that there are read2( ) functions that take float arguments.

I tried them but I only get integer results even though the DHT11 has a resolution of 0.1°C

This shows the issue:

#include <SimpleDHT.h>

void setup() {
  
  Serial.begin(115200);
  Serial.println(); 
}

void loop() {
  
	float temperature = 0;
	float humidity = 0;
	
  SimpleDHT11 dht11(-1);
	int err;
  if (dht11.read2(14, &temperature, &humidity, NULL) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err));
    //Serial.print(","); Serial.println(SimpleDHTErrDuration(err));
  
  }
   
  Serial.print(temperature); Serial.print("°C  ");Serial.print(humidity);Serial.println("%");
  delay (1500);
}

Library 1.0.14 Issue

I have come to report that, with this library version, I am getting more fail readings than successful ones.
It is not happening on the previous version "1.0.13", which works perfectly ATM.
Using ESP8266 + DHT22.

Example code question.

Hi,

I am using SimpleDHT and it works fine.

My question is about this snippet in the examples:

void loop() { ... if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000); return; ... }

Why is there a return?

Doesn't this exit loop()? (And wouldn't that return to the somewhere in the boot process of the device?)

Thanks,
Mac

err 101

Hi!
I'm using the default code with Arduino Uno and a DHT11 but keep getting error code 101. I couldn't figure out a way to fix it.

Empty constructor fails, I don't understand why

SimpleDH11 defines two public constructors:

    SimpleDHT11();
    SimpleDHT11(int pin);

and they are implemented like this:

SimpleDHT11::SimpleDHT11() {
}
SimpleDHT11::SimpleDHT11(int pin) : SimpleDHT (pin) {
}

Which all looks perfectly fine. If, however, we declare an object of type SimpleDHT11 without a pin, the sketch fails to compile.

Here is a minimal sketch to show it.

#include <SimpleDHT.h>

int pinDHT11 = 14;

SimpleDHT11 dht11(); // fails, error: request for member 'read2' in 'dht11', which is of non-class type 'SimpleDHT11()'
//SimpleDHT11 dht11(-1); //works fine

void setup() {
  Serial.begin(115200);
}

void loop(){
  float temperature = 0;
  float humidity = 0;
  int err = dht11.read2( pinDHT11, &temperature, &humidity, NULL);
  Serial.println(humidity);
  delay(1200);
}

If we pass in a dummy pin number, such as -1, the code compiles and works. I pass in the pin number to the read/read2 function which are all overloaded to include, or not include, the pin.

Because of the design of my application, I wish to be able to specify the pin on each call to read, so my plan was to not specify a pin in the constructor call. I have no problem passing in a dummy value, but I am trying to understand why it does not work without.

This is happening on a Wemos D1 (ESP8266), Arduino IDE 2.0.3

Can we make setPin() public?

Hey,

Thanks for the lib.
I am interfacing your lib with my own class so I can have all temperature logic in one place.

Doing this:
SimpleDHT11 dht11(2);

Stops me from being able to do this:

class Temperature{
    public:
      void setChannel(int _channel){
        channel = _channel;
        dht11.setPin(_channel);
      }
    ...

Is there a another way to instantiate this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.