• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Problem z odczytem temperatury DHT11
#1
Photo 
Witam wszystkich serdecznie.



Mój problem dotyczy kodu lub biblioteki do wyświetlenia temperatury i wilgotności na LCD po I2C z wykorzystaniem DHT11. W internecie na youtube obejrzałem filmik i skorzystałem z udostępnionego kodu. Posiadam arduino Leonardo i Nano.

Początkowo myślałem, że mam uszkodzone czujniki DHTxx, lecz testując na monitorze portu COM wszystko jest OK ale jak chcę wyświetlić dane po wgraniu poniższego kodu to mam błędy typu "Checkum error" i wyświetla  -1.

Kod:
/*
  Board              int.0      int.1      int.2      int.3      int.4      int.5
Uno, Ethernet      2      3
Mega2560      2      3      21      20      19      18
Leonardo      3      2      0      1
   (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
*/

#include <idDHT11.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 3
LiquidCrystal_I2C    lcd(0x27,2,1,0,4,5,6,7);

int idDHT11pin = 3; //Digital pin for comunications
int idDHT11intNumber = 1; //interrupt number (must be the one that use the previus defined pin (see table above)
//declaration
void dht11_wrapper(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);

void setup()
{
  Serial.begin(9600);
  Serial.println("idDHT11 Example program");
  Serial.print("LIB version: ");
  Serial.println(IDDHT11LIB_VERSION);
  Serial.println("---------------");
   lcd.begin(16, 2);
   lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
   lcd.setBacklight(HIGH);
  lcd.print("TEMP C   Wilgot.");
  lcd.setCursor(0, 1);
  lcd.print(" ");
  lcd.setCursor (10, 1);
  lcd.print(" ");
   lcd.setCursor (4, 1);
  lcd.print("st.");
  lcd.setCursor (13, 1);
  lcd.print("%");
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapper() {
  DHT11.isrCallback();
}
void loop()
{
  Serial.print("\nRetrieving information from sensor: ");
  Serial.print("Read sensor: ");
  //delay(100);
  DHT11.acquire();
  while (DHT11.acquiring())
    ;
  int result = DHT11.getStatus();
  switch (result)
  {
  case IDDHTLIB_OK:
    Serial.println("OK");
    break;
  case IDDHTLIB_ERROR_CHECKSUM:
    Serial.println("Error\n\r\tChecksum error");
    break;
  case IDDHTLIB_ERROR_ISR_TIMEOUT:
    Serial.println("Error\n\r\tISR Time out error");
    break;
  case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
    Serial.println("Error\n\r\tResponse time out error");
    break;
  case IDDHTLIB_ERROR_DATA_TIMEOUT:
    Serial.println("Error\n\r\tData time out error");
    break;
  case IDDHTLIB_ERROR_ACQUIRING:
    Serial.println("Error\n\r\tAcquiring");
    break;
  case IDDHTLIB_ERROR_DELTA:
    Serial.println("Error\n\r\tDelta time to small");
    break;
  case IDDHTLIB_ERROR_NOTSTARTED:
    Serial.println("Error\n\r\tNot started");
    break;
  default:
    Serial.println("Unknown error");
    break;
  }
  lcd.setCursor(10, 1);
  lcd.print(DHT11.getHumidity(), 0);
  Serial.print("Humidity (%): ");
  Serial.println(DHT11.getHumidity(), 2);
lcd.setCursor(1, 1);
  lcd.print(DHT11.getCelsius(), 0);
  Serial.print("Temperature (oC): ");
  Serial.println(DHT11.getCelsius(), 2);

  Serial.print("Temperature (oF): ");
  Serial.println(DHT11.getFahrenheit(), 2);

  Serial.print("Temperature (K): ");
  Serial.println(DHT11.getKelvin(), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(DHT11.getDewPoint());

  Serial.print("Dew Point Slow (oC): ");
  Serial.println(DHT11.getDewPointSlow());

  delay(2000);
}


Załączone pliki Miniatury
       
 
Odpowiedź
  


Wiadomości w tym wątku
Problem z odczytem temperatury DHT11 - przez milek22 - 10-11-2019, 12:16

Skocz do:


Przeglądający: 1 gości