Go Down

Topic: Please Help!Mirf and DHT11 Questions. (Read 365 times) previous topic - next topic

jay_L

I found a source code from internet for DHT11,
And i put it into another mirf program.
The problem is when i run the DHT11 code. ReadDHT(),
it will stop if(!Mirf.isSending() && Mirf.dataReady()).
Why the DHT11 code effect to the MirfisSending?
How can i correct it?
Many Thanks.


The DHT11 ReadDHT() code:
Code: [Select]
void ReadDHT(){
  /*Uses global variables dht_dat[0-4], and bGlobalErr to pass
   "answer" back. bGlobalErr=0 if read went okay.
   Depends on global dht_PIN for where to look for sensor.*/
  bGlobalErr=0;
  byte dht_in;
  byte i;
  // Send "start read and report" command to sensor....
  // First: pull-down i/o pin for 18ms
  digitalWrite(dht_dpin,LOW);//Was: PORTC &= ~_BV(dht_PIN);
  delay(18);
  delay(5);//TKB, frm Quine at Arduino forum
  /*aosong.com datasheet for DHT22 says pin should be low at least
   500us. I infer it can be low longer without any]
   penalty apart from making "read sensor" process take
   longer. */
  //Next line: Brings line high again,
  //   second step in giving "start read..." command
  digitalWrite(dht_dpin,HIGH);//Was: PORTC |= _BV(dht_PIN);
  delayMicroseconds(40);//DHT22 datasheet says host should
  //keep line high 20-40us, then watch for sensor taking line
  //low. That low should last 80us. Acknowledges "start read
  //and report" command.

  //Next: Change Arduino pin to an input, to
  //watch for the 80us low explained a moment ago.
  pinMode(dht_dpin,INPUT);//Was: DDRC &= ~_BV(dht_PIN);
  delayMicroseconds(40);

  dht_in=digitalRead(dht_dpin);//Was: dht_in = PINC & _BV(dht_PIN);

  if(dht_in){
    bGlobalErr=1;//Was: Serial.println("dht11 start condition 1 not met");
    return;
  }//end "if..."
  delayMicroseconds(80);

  dht_in=digitalRead(dht_dpin);//Was: dht_in = PINC & _BV(dht_PIN);

  if(!dht_in){
    bGlobalErr=2;//Was: Serial.println("dht11 start condition 2 not met");
    return;
  }//end "if..."

  /*After 80us low, the line should be taken high for 80us by the
   sensor. The low following that high is the start of the first
   bit of the forty to come. The routine "read_dht_dat()"
   expects to be called with the system already into this low.*/
  delayMicroseconds(80);
  //now ready for data reception... pick up the 5 bytes coming from
  //   the sensor
  for (i=0; i<5; i++)
    dht_dat[i] = read_dht_dat();

  //Next: restore pin to output duties
  pinMode(dht_dpin,OUTPUT);//Was: DDRC |= _BV(dht_PIN);
  //N.B.: Using DDRC put restrictions on value of dht_pin

  //Next: Make data line high again, as output from Arduino
  digitalWrite(dht_dpin,HIGH);//Was: PORTC |= _BV(dht_PIN);
  //N.B.: Using PORTC put restrictions on value of dht_pin

  //Next see if data received consistent with checksum received
  byte dht_check_sum =
    dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];
  /*Condition in following "if" says "if fifth byte from sensor
   not the same as the sum of the first four..."*/
  if(dht_dat[4]!= dht_check_sum)
  {
    bGlobalErr=3;
  }//Was: Serial.println("DHT11 checksum error");
};//end ReadDHT()

guix

#1
Nov 21, 2012, 07:11 pm Last Edit: Nov 21, 2012, 07:27 pm by guix Reason: 1
Can you try with another library to replace the mirf library? https://github.com/maniacbug/RF24/

http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/

Also another DHT library you might want to test: https://github.com/adafruit/DHT-sensor-library

While I don't know what is your problem, I might get the same problem because I have a DHT22 and plan to use a pair of nRF24L01+ soon

Go Up