including second DHT21 sensor into data logger

Hello,

I have a sketch that runs four DS18B20 sensors and puts the data on an SD card. When I included a DHT21 sensor (marked with "//////////A" in the code) it still worked. When I included a second DHT21 sensor (marked with "//////////B" in the code) it didn't work anymore. I don't get any errors, but it prints "########" into the excel file instead of the actual date and values.

Can anyone help please?

//NJarpa
//Arduino Data Logger with 2 DS18B20 and sample rate control(every 1 min)
//You must have a datalogger shield(RTC and SD card) mounted
// DS18B20 Pinout (Wires)
//Black   = Ground
//Blue    = Signal (Pin 2):  (Normal power mode with 3.3K to 4.7K resistor to +5 or 3.3 )
//Red     = +5 or +3.3 V

#include <Wire.h>                //Libraries we need
#include "RTClib.h"
#include <OneWire.h>           
#include <DallasTemperature.h>
#include <SPI.h>
#include <SD.h>

#include <dht.h> //////////A
dht DHT; //////////A



#define ONE_WIRE_BUS_PIN 2              // The pin that we are using for sensors

#define DHT21A_PIN 3 //////////A
#define DHT21B_PIN 4 //////////B


//Variables //////////A
float humA;  //Stores humidity value //////////A
float tempA; //Stores temperature value //////////A

//Variables //////////B
float humB;  //Stores humidity value //////////B
float tempB; //Stores temperature value //////////B

OneWire oneWire(ONE_WIRE_BUS_PIN);     // Setup oneWire
DallasTemperature sensors(&oneWire);   //  oneWire to Dallas Temperature.
RTC_DS1307 RTC;                        // define the Real Time Clock object

const int chipSelect = 4;              //CS pin of your data logger shield.Maybe not yours!!
File Logfile;                          //Name of the file

// Assign the addresses of your  temp sensors.
//Every sensor has it own address.You must use 1 wire adress finder.

DeviceAddress Probe01 = { 0x28, 0x7E, 0xA5, 0x77, 0x91, 0x08, 0x02, 0x13 }; //inox2
DeviceAddress Probe02 = { 0x28, 0xAA, 0x21, 0x9E, 0x13, 0x13, 0x02, 0xE7 }; //Inox1
DeviceAddress Probe03 = { 0x28, 0xAA, 0x5E, 0xA8, 0x13, 0x13, 0x02, 0xA4 };
DeviceAddress Probe04 = { 0x28, 0xAA, 0xA9, 0xA5, 0x13, 0x13, 0x02, 0xCE };
//DeviceAddress Probe05 = { 0x28, 0x7E, 0xA5, 0x77, 0x91, 0x08, 0x02, 0x13 }; //uncomment for further DS18B20 sensor




void setup()
{
  //pinMode(10 , OUTPUT);           //For some data logger shields.Uncomment if you need
  
SD.begin(chipSelect);            //Initialize the libraries
Wire.begin();
RTC.begin();
sensors.begin();    
  
  // set the resolution to 9 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 9);
  sensors.setResolution(Probe02, 9);
  sensors.setResolution(Probe03, 9);
  sensors.setResolution(Probe04, 9);
  //sensors.setResolution(Probe05, 9); //uncomment for further DS18B20 sensor
  
Logfile=SD.open("Logfile.csv",FILE_WRITE);               //Open and write once, just for headers
//Logfile.println(" Date/Time         Temp1   Temp2   Temp3    Temp4    Temp5   Hum5");    //Print headers(not saved yet) //////////
Logfile.close();                                        //Print saved

}

//----------Temp Variable------------//
void printTemperature(DeviceAddress deviceAddress)
{
   float tempC = sensors.getTempC(deviceAddress);
 
   Logfile.print(tempC);
   Logfile.print(" C");
   Logfile.print(" ");
}

void loop()
{

 DateTime now = RTC.now();        // Clock call
 now = RTC.now();                 

if(now.second()==00){          //Sample every minute
 
 Logfile=SD.open("Logfile.csv",FILE_WRITE);  // Print date and time    

Logfile.println();
Logfile.print(now.year(), DEC);
Logfile.print("/");
Logfile.print(now.month(), DEC);
Logfile.print("/");
Logfile.print(now.day(), DEC);
Logfile.print(" ");
Logfile.print(now.hour(), DEC);
Logfile.print(":");
Logfile.print(now.minute(), DEC);
Logfile.print(":");
Logfile.print(now.second(), DEC);
Logfile.print("  ");              //Space beween date/time and temp1
Logfile.close();                  //Save date and time

sensors.requestTemperatures(); // Command all devices on bus to read temperature 
Logfile=SD.open("Logfile.csv",FILE_WRITE); 
  
 Logfile.print("Temp1: ");             //Print temp1
 printTemperature(Probe01);
 Logfile.print("Temp2: ");             //Print temp2
 printTemperature(Probe02);
 Logfile.print("Temp3: ");             //Print temp3
 printTemperature(Probe03);
 Logfile.print("Temp4: ");             //Print temp4
 printTemperature(Probe04);
 //Logfile.print("Temp5:");             //uncomment for further DS18B20 sensor //Print temp5
 //printTemperature(Probe05);

  int chkA = DHT.read21(DHT21A_PIN); //////////A
    //Read data and store it to variables hum and temp //////////A
    humA = DHT.humidity; //////////A
    tempA= DHT.temperature; //////////A
    //Print temp and humidity values to serial monitor //////////A
    Logfile.print("Hum6: "); //////////A
    Logfile.print(humA); //////////A
    Logfile.print(" %, Temp6: "); //////////A
    Logfile.print(tempA); //////////A
    Logfile.println(" C"); //////////A

    int chkB = DHT.read21(DHT21B_PIN); //////////B
    //Read data and store it to variables hum and temp //////////B
    humB = DHT.humidity; //////////B
    tempB= DHT.temperature; //////////B
    //Print temp and humidity values to serial monitor //////////B
    Logfile.print("Hum7: "); //////////B
    Logfile.print(humB); //////////B
    Logfile.print(" %, Temp7: "); //////////B
    Logfile.print(tempB); //////////B
    Logfile.println(" C"); //////////B

    
 Logfile.close();                //Print saved
 }
 
delay(1000);                        //One data per second
}

Can anyone help please?

What gets written to the Serial port? What ACTUALLY gets written to the file? Open the file in a text editor, instead of Excel. You may not have the field width or type correct in Excel.

2018/10/22 11:6:0 Temp1: 18.50 C Temp2: 19.00 C Temp3: 18.50 C Temp4: 19.00 C Hum6: 80.80 %, Temp6: 19.30 C

2018/10/22 11:12:0

This is what gets written in a text file. First line with one DHT21, everything fine. Second line with second DHT21 only gives date/time.

Second line with second DHT21 only gives date/time.

I wonder if the fact that you've attached the second DHT21 to the SD card's chip select pin is relevant.

(Not really, I don't).

PaulS:
I wonder if the fact that you've attached the second DHT21 to the SD card's chip select pin is relevant.

(Not really, I don't).

That was it! Now it works, thanks!