ATTINY84 do not read DHT22

Hi everyboby
I get in trouble with ATTINY84A PU
My configuration
ARDUINO ide 1.0.5-R2
ARDUINO UNO R3
DHT22
TX FS1000A

ATTINY84(bod desactived) 8Mhz internal oscillator
The following code (with the right pins for arduino works perfectly)

#include <VirtualWire.h>
#include <DHT.h>
byte sensorPin = 6; // ATTINY 9
#define DHTTYPE DHT22
DHT sensor; // create the sensor object
int t;
int h;
#define DTH22_POWER 0 
const int transmit_pin = 3; //attiny 6
char dataString [18];
//----------------------------------------------------------------
void setup()
{sensor.setup(sensorPin);
pinMode(DTH22_POWER, OUTPUT);
  vw_set_tx_pin(transmit_pin);
  vw_set_ptt_inverted(true);
  vw_setup(2000);      
}

//---------------------------------------------------------------
void loop()
{
 digitalWrite(DTH22_POWER, HIGH);
  delay(5000);
 double t = sensor.getTemperature();
double h = sensor.getHumidity();
//delay(1000);
  int h1 = (h-(int)h)*100;
  int t1 = (t-(int)t)*100;
  sprintf(dataString,"Text 1:%1d.%1d:%1d.%1d",int(t),t1,int(h),h1); 
  vw_send((uint8_t *)dataString, 18);
  vw_wait_tx(); 
 digitalWrite(DTH22_POWER, LOW);
delay(5000);

}

As soon as I put this one on attiny
the result is
Text 1: ; 00.00 00.00
If I use the later:

int h = (myDHT22.getHumidity());
int t = (myDHT22.getTemperatureC());
}[code]

I get
Text 1: ;-99.00 -99.00
I try to change the pins allocation without success
No more results on the web
Using different libraries.

FYI the same code structure works fine with a DS 18 B20
( with the ds library )

Any help ?

Thanks in advance

Dennis
[/code]

Edit your post, use the command hashtag on your post to write code properly and so we can read and help.

thank you sir I just make some progress good lesson next time it would be better

Maybe you should try with newer attiny core. There is one in Github, just google Attiny core. The one for version 1.0.X IDE.

Which DHT library do you use ?

mine is confirmed with an ATTINY85 , - http://playground.arduino.cc/Main/DHTLib -

please give it a try,

R.

Thank you Mart and Rob I try the other core with no result (for the moment) I am using your library, Rob : both dht11 and dht this doesn't save the situation I just order attiny 85 20 pu within the next forthnight I will keep you informed Dennis

Do you get some output from my DHT lib (e.g. test sketch?

Might help me improve the lib as I do not have tiny84's.

Thanks.

Hello Rob using the code up I get text1: 00.00 ; 00.00 time to time text1: 00.00;02.00

within the next weeks I will try the sketch test ( I wait for a new DHT) I am not pretty sure that your dht .h is responsible of the errors.

I dont know if it is useful but: Using the attiny84 with ds18B20 everything is ok if I dont use the power output on the pin 2. If I use it ,Idont read DS18B20 (-85.00 )despite the fact the 3.3 V are presents on pin 2, shortening the pin 1 and the pin 2 makes the result ok. the same action doesn't save the situation with DHT22.

As promise I will do the test of the test sketch I have time I am retired for more than 10 years ............

all the best Rob

Assuming you used the ADAFRUIT lib I have changed one line in your code

It might be that the lib is not initialzed correctly and therefor spits out only zero’s

Can you try this sketch to see if the sensor works when initialized with extra parameters:

#include <VirtualWire.h>
#include <DHT.h>

byte sensorPin = 6;        // ATTINY 9

#define DHTTYPE DHT22
DHT sensor(sensorPin,  DHTTYPE);           // <<<<<<<<<<<<<<<<<<<

#define DTH22_POWER 0 

const int transmit_pin = 3;       //attiny 6

char dataString [18];


//----------------------------------------------------------------
void setup()
{
  sensor.setup(sensorPin);
  pinMode(DTH22_POWER, OUTPUT);
  
  vw_set_tx_pin(transmit_pin);
  vw_set_ptt_inverted(true);
  vw_setup(2000);      
}

//---------------------------------------------------------------
void loop()
{
  digitalWrite(DTH22_POWER, HIGH);
  delay(5000);

  double t = sensor.getTemperature();
  double h = sensor.getHumidity();

  int h1 = (h-(int)h)*100;
  int t1 = (t-(int)t)*100;
  sprintf(dataString,"Text 1:%1d.%1d:%1d.%1d", int(t), t1, int(h), h1); 

  vw_send((uint8_t *)dataString, 18);
  vw_wait_tx(); 

 digitalWrite(DTH22_POWER, LOW);
 delay(5000);
}

from the library

float DHT::readTemperature(bool S) {
  float f;

  if (read()) {
    switch (_type) {  // <<<<<<<<<< if not initialized it won't execute any code and return zero.
    case DHT11:
      f = data[2];
      if(S)
      	f = convertCtoF(f);
      	
      return f;
    case DHT22:
    case DHT21:
      f = data[2] & 0x7F;
      f *= 256;
      f += data[3];
      f /= 10;
      if (data[2] & 0x80)
	f *= -1;
      if(S)
	f = convertCtoF(f);

      return f;
    }
  }
  return NAN;
}

Hi Rob
You are true , I was using adafruit’s library . I got an horrible mess
in my libaries folder using the wrong way ( cut copy paste ).
I don’t succeed with your recommendations both attiny84 & 85?
I am not at a sufficient level in C.
So I try not using one wire.
Finally I write a code " falling down working by accident " using adafruit’s library .
this code work both attiny 84 and 85.

// Basic node using adafruit dht lib (july 2014 version)
// code   dennis V. W.  picked up from misc examples
#include <VirtualWire.h>
#include <DHT.h>
//#include <Narcoleptic.h>//don't work with attiny85
#define DHTPIN 2////attiny85 (2)7 attiny84 (8)11
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE,3);//<<<<<<<< modification for 8 Mhz
int t;
int h;
#define DTH22_POWER 0 ////attiny85 (0)5 attiny84 (0)2
const int transmit_pin = 1; //attiny85 (1)6 attiny84 (5)8
char dataString [15];
//----------------------------------------------------------------
void setup()
{
pinMode(DTH22_POWER, OUTPUT);
  vw_set_tx_pin(transmit_pin);
  vw_set_ptt_inverted(true);
  vw_setup(2000);      
}
//---------------------------------------------------------------
void loop()
{
 digitalWrite(DTH22_POWER, HIGH);
  delay(2000);
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 int t1 = (t-(int)t)*100;
  sprintf(dataString,"T/H 1:;%1d.%1d;%1d;",int(t),t1,int(h)); 
  vw_send((uint8_t *)dataString, 15);
  vw_wait_tx(); 
 digitalWrite(DTH22_POWER, LOW);
 delay(60000);
 //Narcoleptic.delay(60000);//don't work with attiny85

}

Thank you again for your support

Dennis