Go Down

Topic: Adafruit DHT Library and ATtiny85 (Read 11498 times) previous topic - next topic

orangeLearner

Hello there to everyone who has experience,

I am trying to use Arduino-tiny for the first time. I did this so that I could use the Adafruit DHT11 sensor library. I have successfully implemented the example sketch on an Arduino Nano (mega328) However, when I connect the one-wire sensor to the ATtiny, it reads as zero. I know I have the pin right because when I disconnect the wire I get "Read failFailed to read from DHT". I am running at 8MHz internal oscillator.

Can someone look in the DHT library code read() function and see whether anything would run differently on an ATtiny?

Serial output:
Humidity: 0.00 %   Temperature: 0.00 *C
Humidity: 0.00 %   Temperature: 0.00 *C
Humidity: 0.00 %   Temperature: 0.00 *C
Humidity: 0.00 %   Temperature: 0.00 *C
Humidity: 0.00 %   Temperature: 0.00 *C

Coding Badly

Quote
Hello there to everyone who has experience,


What about the rest of us?  No hello for us?

Quote
Can someone look in the DHT library code read() function and see whether anything would run differently on an ATtiny?


Nothing jumps out at me.

Give this one a try.  It looks like the error trapping is more complete...
http://arduino.cc/playground/Main/DHT11Lib

Coding Badly


If the timing is critical (which appears to be the case) the problem could be as simple as the uncalibrated internal oscillator.

orangeLearner



Give this one a try.  It looks like the error trapping is more complete...
http://arduino.cc/playground/Main/DHT11Lib



Thanks for this suggestion. The new library works exactly like it should and has better error reporting like you said. I was able to create my nice ATtiny thermometer with seven-segment display.

bodtx

This library works on Attiny 85 @8mhz and a DHT22 .
http://playground.arduino.cc/Main/DHTLib
you have to create manually the .h and .cpp as described at the end of the page.
Code: [Select]
//
//    FILE: dht_test.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//     URL: http://arduino.cc/playground/Main/DHTLib
//
// Released to the public domain
//

#include <dht.h>
#include <SoftwareSerial.h>
dht DHT;

#define DHT22_PIN 0
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
void setup()
{
 
    pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(9600);

  mySerial.println("DHT TEST PROGRAM ");
  mySerial.print("LIBRARY VERSION: ");
  mySerial.println(DHT_LIB_VERSION);
  mySerial.println();
  mySerial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  mySerial.print("DHT22, \t");
  int chk = DHT.read22(DHT22_PIN);
  switch (chk)
  {
    case DHTLIB_OK: 
mySerial.print("OK,\t");
break;
    case DHTLIB_ERROR_CHECKSUM:
mySerial.print("Checksum error,\t");
break;
    case DHTLIB_ERROR_TIMEOUT:
mySerial.print("Time out error,\t");
break;
    default:
mySerial.print("Unknown error,\t");
break;
  }
  // DISPLAY DATA
  mySerial.print(DHT.humidity, 1);
  mySerial.print(",\t");
  mySerial.println(DHT.temperature, 1);

  delay(1000);

}
//
// END OF FILE
//


robtillaart

#5
Jan 04, 2014, 04:19 pm Last Edit: Jan 04, 2014, 04:32 pm by robtillaart Reason: 1
Thanks for testing the lib on the attiny85. I'll update the playground article that it works with attiny85
[done]
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Alvar_g

#6
Apr 07, 2015, 01:25 pm Last Edit: Apr 07, 2015, 06:13 pm by Alvar_g
This library works on Attiny 85 @8mhz and a DHT22 .
http://playground.arduino.cc/Main/DHTLib
you have to create manually the .h and .cpp as described at the end of the page.
Code: [Select]
//
//    FILE: dht_test.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//     URL: http://arduino.cc/playground/Main/DHTLib
//
// Released to the public domain
//

#include <dht.h>
#include <SoftwareSerial.h>
dht DHT;

#define DHT22_PIN 0
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
void setup()
{
  
    pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(9600);

  mySerial.println("DHT TEST PROGRAM ");
  mySerial.print("LIBRARY VERSION: ");
  mySerial.println(DHT_LIB_VERSION);
  mySerial.println();
  mySerial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  mySerial.print("DHT22, \t");
  int chk = DHT.read22(DHT22_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
mySerial.print("OK,\t");
break;
    case DHTLIB_ERROR_CHECKSUM:
mySerial.print("Checksum error,\t");
break;
    case DHTLIB_ERROR_TIMEOUT:
mySerial.print("Time out error,\t");
break;
    default:
mySerial.print("Unknown error,\t");
break;
  }
  // DISPLAY DATA
  mySerial.print(DHT.humidity, 1);
  mySerial.print(",\t");
  mySerial.println(DHT.temperature, 1);

  delay(1000);

}
//
// END OF FILE
//


I am not able to run the library with Attiny, I give compilation error.




" Arduino:1.6.3 (Windows XP), Placa:"ATtiny, ATtiny85, 8 MHz (internal)"

In file included from dht_test.ino:1:0:

C:\Documents and Settings\R2Yum\Mis documentos\Arduino\libraries\dht_Attiny/dht.h:64:2: error: #endif without #if

#endif

 ^

In file included from dht_test.ino:13:0:

C:\Documents and Settings\R2Yum\Mis documentos\Arduino\libraries\dht_Attiny/dht.h:64:2: error: #endif without #if

#endif

 ^

"

 ^
I have arduino IDE 1.6.3

stenry

Thanks for testing the lib on the attiny85. I'll update the playground article that it works with attiny85
[done]
The library also works well with Digispark USB attiny85 @16.5MHz, using IDE 1.6.5 and board defined with Board Manager. Tested on AM2301.


newsogn

Hey guys so I know this is an old thread but I just thought I would post my own personal struggles with this subject and how i got it to work. So to start with I am using the high low tech attiny85 core and I wanted to get the dht22 to work on it. But it was not and I struggled with the code for days now. I am using the tillart dht22 library i think my version is 1.20 because I cant find a zip of any other version. But i could not get the code to work. it would compile and upload but nothing. Finally in desperation I removed my 10k pullup resistor! and then I got positive results. It was because my pullup resistor was too high!! So I thought I would post that here and let you guys know just in case someone else stubbles here and is frustrated like I was.

Go Up