Dhtlin /(dht22) problem

Hello friends
My problem is that I am using the dhtlib library and I am getting the values ​​with the dht22 sensor I have installed. Until now, everything is in its normal content, I am using ntc to measure the temperature, my problem is that when it reaches 102 degrees, the screen resets and I continue after 100 in the form of 1/2/3. This is only in the dhtlib library. In the other DHT_senso_lib library, it goes up to 125 degrees without any problems. What I want to do is when I change the dhtlib library. I can show the numbers up to 125 degrees without resetting the source code and I'm adding the
how should i change dhtlib folder now

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include <dht.h>

#define DHT22_PIN 8 // DHT22 sensor
dht DHT;
int hum; //Stores humidity value
int temp; //Stores temperature value

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup(void) {
u8g2.begin();
int chk = DHT.read22(DHT22_PIN);
u8g2.clearBuffer();
u8g2.sendBuffer();
}

void loop(void) {
u8g2.begin();
int chk = DHT.read22(DHT22_PIN);

//Read data and store it to variables hum and temp
hum = DHT.humidity;
temp= DHT.temperature;

u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso20_tr); // choose a suitable font
u8g2.drawStr(0,10,"Hello World!");
u8g2.setCursor(45, 40);
u8g2.print(temp);// write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.firstPage();
}

[/code]

dhtlib

//
//    FILE: dht.cpp
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.35
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino, AVR optimized
//     URL: https://github.com/RobTillaart/DHTlib
//          http://arduino.cc/playground/Main/DHTLib
//
//
//  HISTORY:
//  0.1.35   2021-12-16  update library.json, license, #pragma once, 
//                       move private defines to .cpp file
//  0.1.34   2021-11-13  fix negative temperature DHT22 again (code from DHTNew)
//  0.1.33   2021-02-16  fix #6 T-GO signal in handshake. (needed for long wires)
//  0.1.32   2021-02-01  fix negative temperature DHT22 again (code from DHTNew)
//  0.1.31   2020-12-15  fix negative temperature DHT22 (code from DHTNew)
//  0.1.30   2020-06-30  own repo;
//  0.1.29   2018-09-02  fix negative temperature DHT12 - issue #111
//  0.1.28   2018-04-03  refactor
//  0.1.27   2018-03-26  added _disableIRQ flag
//  0.1.26   2017-12-12  explicit support for AM23XX series and DHT12
//  0.1.25   2017-09-20  FIX https://github.com/RobTillaart/Arduino/issues/80
//  0.1.24   2017-07-27  FIX https://github.com/RobTillaart/Arduino/issues/33  double -> float
//  0.1.23   2017-07-24  FIX https://github.com/RobTillaart/Arduino/issues/31
//  0.1.22   undo delayMicroseconds() for wakeups larger than 8
//  0.1.21   replace delay with delayMicroseconds() + small fix
//  0.1.20   Reduce footprint by using uint8_t as error codes. (thanks to chaveiro)
//  0.1.19   masking error for DHT11 - FIXED (thanks Richard for noticing)
//  0.1.18   version 1.16/17 broke the DHT11 - FIXED
//  0.1.17   replaced micros() with adaptive loopcount
//           removed DHTLIB_INVALID_VALUE
//           added  DHTLIB_ERROR_CONNECT
//           added  DHTLIB_ERROR_ACK_L  DHTLIB_ERROR_ACK_H
//  0.1.16   masking unused bits (less errors); refactored bits[]
//  0.1.15   reduced # micros calls 2->1 in inner loop.
//  0.1.14   replace digital read with faster (~3x) code => more robust low MHz machines.
//           
//  0.1.13   fix negative temperature
//  0.1.12   support DHT33 and DHT44 initial version
//  0.1.11   renamed DHTLIB_TIMEOUT
//  0.1.10   optimized faster WAKEUP + TIMEOUT
//  0.1.09   optimize size: timeout check + use of mask
//  0.1.08   added formula for timeout based upon clockspeed
//  0.1.07   added support for DHT21
//  0.1.06   minimize footprint (2012-12-27)
//  0.1.05   fixed negative temperature bug (thanks to Roseman)
//  0.1.04   improved readability of code using DHTLIB_OK in code
//  0.1.03   added error values for temp and humidity when read failed
//  0.1.02   added error codes
//  0.1.01   added support for Arduino 1.0, fixed typos (31/12/2011)
//  0.1.00   by Rob Tillaart (01/04/2011)
//
// inspired by DHT11 library


#include "dht.h"


#define DHTLIB_DHT11_WAKEUP             18
#define DHTLIB_DHT_WAKEUP               1

#define DHTLIB_DHT11_LEADING_ZEROS      1
#define DHTLIB_DHT_LEADING_ZEROS        6


// max timeout is 100 microseconds.
// For a 16 MHz processor 100 microseconds is 1600 clock cycles
// loops using DHTLIB_TIMEOUT use at least 4 clock cycles
// so 100 us takes max 400 loops
// so by dividing F_CPU by 40000 we "fail" as fast as possible
#ifndef F_CPU
#define DHTLIB_TIMEOUT 1000  // should be approx. clock/40000
#else
#define DHTLIB_TIMEOUT (F_CPU/40000)
#endif


/////////////////////////////////////////////////////
//
// PUBLIC
//

int8_t dht::read11(uint8_t pin)
{
    // READ VALUES
    if (_disableIRQ) noInterrupts();
    int8_t result = _readSensor(pin, DHTLIB_DHT11_WAKEUP, DHTLIB_DHT11_LEADING_ZEROS);
    if (_disableIRQ) interrupts();

    // these bits are always zero, masking them reduces errors.
    bits[0] &= 0x7F;
    bits[2] &= 0x7F;

    // CONVERT AND STORE
    humidity    = bits[0];  // bits[1] == 0;
    temperature = bits[2];  // bits[3] == 0;

    // TEST CHECKSUM
    uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
    if (bits[4] != sum)
    {
        return DHTLIB_ERROR_CHECKSUM;
    }
    return result;
}


int8_t dht::read12(uint8_t pin)
{
    // READ VALUES
    if (_disableIRQ) noInterrupts();
    int8_t result = _readSensor(pin, DHTLIB_DHT11_WAKEUP, DHTLIB_DHT11_LEADING_ZEROS);
    if (_disableIRQ) interrupts();

    // CONVERT AND STORE
    humidity = bits[0] + bits[1] * 0.1;
    temperature = bits[2] + (bits[3] & 0x7F) * 0.1;
    if (bits[3] & 0x80)  // negative temperature
    {
        temperature = -temperature;
    }

    // TEST CHECKSUM
    uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
    if (bits[4] != sum)
    {
        return DHTLIB_ERROR_CHECKSUM;
    }
    return result;
}


int8_t dht::read(uint8_t pin)
{
    // READ VALUES
    if (_disableIRQ) noInterrupts();
    int8_t result = _readSensor(pin, DHTLIB_DHT_WAKEUP, DHTLIB_DHT_LEADING_ZEROS);
    if (_disableIRQ) interrupts();

    // these bits are always zero, masking them reduces errors.
    bits[0] &= 0x03;
    bits[2] &= 0x83;

    // CONVERT AND STORE
    humidity  = (bits[0] * 256 + bits[1]) * 0.1;
    int16_t t = ((bits[2] & 0x7F) * 256 + bits[3]);
    if (t == 0)
    {
      temperature = 0.0;     // prevent -0.0;
    }
    else
    {
      temperature = t * 0.1;
      if((bits[2] & 0x80) == 0x80 )
      {
        temperature = -temperature;
      }
    }

    // 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 CHECKSUM
    uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
    if (bits[4] != sum)
    {
        return DHTLIB_ERROR_CHECKSUM;
    }
    return result;
}


/////////////////////////////////////////////////////
//
// PRIVATE
//
int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits)
{
    // INIT BUFFERVAR TO RECEIVE DATA
    uint8_t mask = 128;
    uint8_t idx = 0;

    uint8_t data = 0;
    uint8_t state = LOW;
    uint8_t pstate = LOW;
    uint16_t zeroLoop = DHTLIB_TIMEOUT;
    uint16_t delta = 0;

    leadingZeroBits = 40 - leadingZeroBits; // reverse counting...

    // replace digitalRead() with Direct Port Reads.
    // reduces footprint ~100 bytes => portability issue?
    // direct port read is about 3x faster
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);
    volatile uint8_t *PIR = portInputRegister(port);

    // REQUEST SAMPLE
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW); // T-be
    if (wakeupDelay > 8) delay(wakeupDelay);
    else delayMicroseconds(wakeupDelay * 1000UL);
    digitalWrite(pin, HIGH); // T-go
    pinMode(pin, INPUT);

    uint16_t loopCount = DHTLIB_TIMEOUT * 2;  // 200uSec max
    // while(digitalRead(pin) == HIGH)
    while ((*PIR & bit) != LOW )
    {
        if (--loopCount == 0) 
        {
          return DHTLIB_ERROR_CONNECT;
        }
    }

    // GET ACKNOWLEDGE or TIMEOUT
    loopCount = DHTLIB_TIMEOUT;
    // while(digitalRead(pin) == LOW)
    while ((*PIR & bit) == LOW )  // T-rel
    {
        if (--loopCount == 0) 
        {
          return DHTLIB_ERROR_ACK_L;
        }
    }

    loopCount = DHTLIB_TIMEOUT;
    // while(digitalRead(pin) == HIGH)
    while ((*PIR & bit) != LOW )  // T-reh
    {
        if (--loopCount == 0)
        {
          return DHTLIB_ERROR_ACK_H;
        }
    }

    loopCount = DHTLIB_TIMEOUT;

    // READ THE OUTPUT - 40 BITS => 5 BYTES
    for (uint8_t i = 40; i != 0; )
    {
        // WAIT FOR FALLING EDGE
        state = (*PIR & bit);
        if (state == LOW && pstate != LOW)
        {
            if (i > leadingZeroBits) // DHT22 first 6 bits are all zero !!   DHT11 only 1
            {
                zeroLoop = min(zeroLoop, loopCount);
                delta = (DHTLIB_TIMEOUT - zeroLoop)/4;
            }
            else if ( loopCount <= (zeroLoop - delta) ) // long -> one
            {
                data |= mask;
            }
            mask >>= 1;
            if (mask == 0)   // next byte
            {
                mask = 128;
                bits[idx] = data;
                idx++;
                data = 0;
            }
            // next bit
            --i;

            // reset timeout flag
            loopCount = DHTLIB_TIMEOUT;
        }
        pstate = state;
        // Check timeout
        if (--loopCount == 0)
        {
          return DHTLIB_ERROR_TIMEOUT;
        }

    }





    // pinMode(pin, OUTPUT);
    // digitalWrite(pin, HIGH);
    return DHTLIB_OK;
}






// -- END OF FILE --

dhtlib.h

#pragma once
//
//    FILE: dht.h
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.35
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino. AVR optimized
//     URL: https://github.com/RobTillaart/DHTlib
//          http://arduino.cc/playground/Main/DHTLib


#if ARDUINO < 100
#include <WProgram.h>
#include <pins_arduino.h>  // fix for broken pre 1.0 version - TODO TEST
#else
#include <Arduino.h>
#endif


#define DHT_LIB_VERSION                 (F("0.1.35"))

#define DHTLIB_OK                       0
#define DHTLIB_ERROR_CHECKSUM           -1
#define DHTLIB_ERROR_TIMEOUT            -2
#define DHTLIB_ERROR_CONNECT            -3
#define DHTLIB_ERROR_ACK_L              -4
#define DHTLIB_ERROR_ACK_H              -5


class dht
{
public:
    dht() { _disableIRQ = false; };
    // return values:
    // DHTLIB_OK
    // DHTLIB_ERROR_CHECKSUM
    // DHTLIB_ERROR_TIMEOUT
    // DHTLIB_ERROR_CONNECT
    // DHTLIB_ERROR_ACK_L
    // DHTLIB_ERROR_ACK_H
    int8_t read11(uint8_t pin);
    int8_t read(uint8_t pin);
    int8_t read12(uint8_t pin);

    inline int8_t read21(uint8_t pin)   { return read(pin); };
    inline int8_t read22(uint8_t pin)   { return read(pin); };
    inline int8_t read33(uint8_t pin)   { return read(pin); };
    inline int8_t read44(uint8_t pin)   { return read(pin); };
    inline int8_t read2301(uint8_t pin) { return read(pin); };
    inline int8_t read2302(uint8_t pin) { return read(pin); };
    inline int8_t read2303(uint8_t pin) { return read(pin); };
    inline int8_t read2320(uint8_t pin) { return read(pin); };
    inline int8_t read2322(uint8_t pin) { return read(pin); };
    
    bool getDisableIRQ()                { return _disableIRQ; };
    void setDisableIRQ(bool b )         { _disableIRQ = b; };

    float humidity;
    float temperature;

private:
    uint8_t bits[5];  // buffer to receive data
    int8_t _readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits);
    bool   _disableIRQ;
};


// -- END OF FILE --

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.