GolamMostafa:
You may follow this post consisting of 2xDS18B20 and 1xDHT22 as a tutorial guide.
//12-bit default resolution; external power supply
#include<OneWire.h>
#define OneWireBusPin 8
#include <SimpleDHT.h>
#define pinDHT22 2
SimpleDHT22 dht22;
float dsTempA, dsTempB;//Temp01, Temp02;
OneWire ds(OneWireBusPin); //2
byte addrdsA[8]; //to hold 64-bit ROM Codes of DS-A
byte addrdsB[8]; //to ho;d 64-bit ROM-code DS-B
byte data[9]; //buffer to hold data coming from DS18B20
float celsius;
void setup()
{
Serial.begin(9600);
//----------------------------
ds.reset();
ds.search(addrdsA); //collect 64-bit ROM code from sensor (DS-A)
ds.search(addrdsB); //auto collec of ROM address of DS-B
}
void loop()
{
Serial.println("==Reading from DS18B20 Sensors================");
showTempAOnSM(); //show temp of DS-A on Serial Monitor
showTempBOnSM();
Serial.println("==Reading form DHT22 Sensor=================");
showHumiTempOnSM(); //show Temp/Humidity on Serial Monitor
delay(2000); //Humidity acquisition delay
}
void showTempAOnSM()
{
//----------------------------
ds.reset(); //bring 1-Wire into idle state
ds.select(addrdsA); //slect with DS-1 with address addr1
ds.write(0x44); //conversion command
delay(1000); //data ready withinh DS18B20 or poll status word
//---------------------------
ds.reset();
ds.select(addrdsA); //selectimg the desired DS18B20
ds.write(0xBE); //Function command to read Scratchpad Memory (9Byte)
ds.read_bytes(data, 9); //data comes from DS-A and are saved into buffer data[8]
//---------------------------------
int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
celsius = (float)raw / 16.0; //12-bit resolution
dsTempA = celsius;
Serial.print(celsius);
Serial.println(" Reading from DS-A");
}
void showTempBOnSM()
{
ds.reset(); //bring 1-Wire into idle state
ds.select(addrdsB); //slect with DS-1 with address addr1
ds.write(0x44); //conversion command
delay(1000); //data ready withinh DS18B20 or poll status word
//---------------------------
ds.reset();
ds.select(addrdsB); //selectimg the desired DS18B20
ds.write(0xBE); //Function command to read Scratchpad Memory (9Byte)
ds.read_bytes(data, 9); //data comes from DS-B and are saved into buffer data[8]
//---------------------------------
int16_t raw = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
celsius = (float)raw / 16.0; //12-bit resolution
dsTempB = celsius;
Serial.print(celsius);
Serial.println(" Reading from DS-B");
}
void showHumiTempOnSM()
{
float temperature = 0;
float humidity = 0;
byte data[40] = {0};
int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(pinDHT22, &temperature, &humidity, data)) != SimpleDHTErrSuccess)
{
Serial.print("Read DHT22 failed, err=");
Serial.println(err);
return;
}
Serial.print((float)temperature); Serial.print(" *C, ");
Serial.print((float)humidity); Serial.println(" RH%");
Serial.println();
}
Cant . Its a blocking route. I need non blocking.