Multiple DHT22 on UNO with Adafruit Data logger shield

Hallo

I have tried to make a sketch that logs DHT22 temperature and humidity from 7 sensors. I can only make it to 6 working sensors, if i have all 7 going the SD file is blank, the serial monitor, shows all data... I have not connected more than 2 DHT22, so the rest of the data is reported as nan.

if i uncomment "ASG5" or "ASG4" it works fine, and i get SD and monitor data on 6 sensors, but with 7 sensors only serial monitor data but a blank file on the SD card, data logging is every 30 seconds...

Serial monitor looks like this:

Initializing SD card...card initialized.
Logging to: LOGGER18.CSV
datetime,rh,temp_c
,11/25/2021 08:39:27,Ref, 47.10,20.50,ASG 1, nan,nan,ASG 2, nan,nan,ASG 3, nan,nan,ASG 4, nan,nan,ASG 5, nan,nan,ASG 6, nan,nan
,11/25/2021 08:39:57,Ref, 38.70,20.60,ASG 1, nan,nan,ASG 2, nan,nan,ASG 3, nan,nan,ASG 4, nan,nan,ASG 5, nan,nan,ASG 6, nan,nan

I tried different approachs, and this is the nearest i got... my code is propably very infant;-)
Any suggestions to what is wrong?
I will try wiring up all sensors and hope it just a question on one nan to many....

best regards

Jan

// log DHT sensor readings to SD card
#include "DHT.h"
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

RTC_PCF8523 RTC;

// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
#define LOG_INTERVAL  30000 // mills between entries (reduce to take more/faster data)

#define ECHO_TO_SERIAL   1 // echo data to serial port

#define REF 7     // what pin we're connected to
#define ASG1 8
#define ASG2 9
#define ASG3 5
#define ASG4 1
#define ASG5 2
#define ASG6 6

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(REF, DHTTYPE);
DHT dht1(ASG1, DHTTYPE);
DHT dht2(ASG2, DHTTYPE);
DHT dht3(ASG3, DHTTYPE);
DHT dht4(ASG4, DHTTYPE);
DHT dht5(ASG5, DHTTYPE);
DHT dht6(ASG6, DHTTYPE);

// select 10 for adafruit shield
const int chipSelect = 10;

// create file to log to
File logfile;

void setup() {
  Serial.begin(9600); 
  
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    Serial.println("could not create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  
  logfile.println("datetime,rh,temp_c");    
#if ECHO_TO_SERIAL
  Serial.println("datetime,rh,temp_c");
#endif //ECHO_TO_SERIAL
  dht.begin();
}

void loop() {
  DateTime now;
  
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  String dataString = "";
  
  // fetch the time
  now = RTC.now();
  // log time
  //logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(",");
  if (now.month() < 10) {
    logfile.print(0, DEC);
  }
  logfile.print(now.month(), DEC);
  logfile.print("/");
  if (now.day() < 10) {
    logfile.print(0, DEC);
  }
  logfile.print(now.day(), DEC);
  logfile.print("/");
  logfile.print(now.year(), DEC);
  logfile.print(" ");
  if (now.hour() < 10) {
    logfile.print(0, DEC);
  }
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  if (now.minute() < 10) {
    logfile.print(0, DEC);
  }
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  if (now.second() < 10) {
    logfile.print(0, DEC);
  }
  logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
 // Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(",");
  if (now.month() < 10) {
    Serial.print(0, DEC);
  }
  Serial.print(now.month(), DEC);
  Serial.print("/");
  if (now.day() < 10) {
    Serial.print(0, DEC);
  }
  Serial.print(now.day(), DEC);
  Serial.print("/");
  Serial.print(now.year(), DEC);
  Serial.print(" ");
  if (now.hour() < 10) {
    Serial.print(0, DEC);
  }  
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  if (now.minute() < 10) {
    Serial.print(0, DEC);
  }
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  if (now.second() < 10) {
    Serial.print(0, DEC);
  }
  Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
  
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity(); // relative humidity, %
  float t_c = dht.readTemperature(); // air temp, degC
  float h1 = dht1.readHumidity(); // relative humidity, %
  float t_c1 = dht1.readTemperature(); // air temp, degC
   float h2 = dht2.readHumidity(); // relative humidity, %
  float t_c2 = dht2.readTemperature(); // air temp, degC
   float h3 = dht3.readHumidity(); // relative humidity, %
  float t_c3 = dht3.readTemperature(); // air temp, degC
 float h4 = dht4.readHumidity(); // relative humidity, %
 float t_c4 = dht4.readTemperature(); // air temp, degC
 float h5 = dht5.readHumidity(); // relative humidity, %
 float t_c5 = dht5.readTemperature(); // air temp, degC
 float h6 = dht6.readHumidity(); // relative humidity, %
 float t_c6 = dht6.readTemperature(); // air temp, degC


  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t_c) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    logfile.print(",");  
    logfile.print("Ref"); 
    logfile.print(",");    
    logfile.print(h, 2);
    logfile.print(",");    
    logfile.print(t_c, 2);
    logfile.print(","); 
    logfile.print("ASG 1"); 
    logfile.print(",");    
    logfile.print(h1, 2);
    logfile.print(",");    
    logfile.print(t_c1, 2);
    logfile.print(","); 
    logfile.print("ASG 2"); 
    logfile.print(",");       
    logfile.print(h2, 2);
    logfile.print(",");    
    logfile.print(t_c2, 2);
    logfile.print(","); 
    logfile.print("ASG 3"); 
    logfile.print(",");       
    logfile.print(h3, 2);
    logfile.print(",");    
    logfile.print(t_c3, 2);
    logfile.print(","); 
    logfile.print("ASG 4"); 
    logfile.print(",");       
   logfile.print(h4, 2);
    logfile.print(",");    
   logfile.print(t_c4, 2);
    logfile.print(","); 
    logfile.print("ASG 5"); 
    logfile.print(",");       
   logfile.print(h5, 2);
    logfile.print(",");    
    logfile.print(t_c5, 2);
    logfile.print(","); 
    logfile.print("ASG 6"); 
   logfile.print(",");       
 logfile.print(h6, 2);
 logfile.print(",");    
logfile.print(t_c6, 2);
 

#if ECHO_TO_SERIAL
    Serial.print(",");  
    Serial.print("Ref, "); 
    Serial.print(h, 2);
    Serial.print(",");    
    Serial.print(t_c, 2);
    Serial.print(",");  
    Serial.print("ASG 1, "); 
    Serial.print(h1, 2);
    Serial.print(",");    
    Serial.print(t_c1, 2);
     Serial.print(",");  
    Serial.print("ASG 2, "); 
    Serial.print(h2, 2);
    Serial.print(",");    
    Serial.print(t_c2, 2);
      Serial.print(",");  
    Serial.print("ASG 3, "); 
    Serial.print(h3, 2);
    Serial.print(",");    
    Serial.print(t_c3, 2);
          Serial.print(",");  
    Serial.print("ASG 4, "); 
  Serial.print(h4, 2);
    Serial.print(",");    
  Serial.print(t_c4, 2);
              Serial.print(",");  
    Serial.print("ASG 5, "); 
  Serial.print(h5, 2);
    Serial.print(",");    
   Serial.print(t_c5, 2);
    Serial.print(",");  
    Serial.print("ASG 6, "); 
 Serial.print(h6, 2);
    Serial.print(",");    
 Serial.print(t_c6, 2);

#endif //ECHO_TO_SERIAL
  }
  
  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  // flush to file
  logfile.flush();
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

From memory, pin 12 is MISO, which is needed to correctly receive responses from the SD card. Have you tried assigning ASG4 to a different pin?

And please use the the code tags when posting your code.

Sorry for messy post...

And thanks for answering.

Citatblok From memory, pin 12 is MISO, which is needed to correctly receive responses from the SD card. Have you tried assigning ASG4 to a different pin?

I tried to change ASG4 Pin 12 to Pin 1, no change, still no SD card data, serial port data are ok.

So any other suggestions are more than welcome.

Best regards

Jan