I have also checked that I am providing the required 3.3V to the sensors as well and tested the connections for all of the components.
My wiring color coordination is as follows:
Ground = Black
Power = Red
SCL = Blue
SDA = Green
Do I need to also boost the TCA9548A? I believe I do not need to boost the multiplexer as it is merely assigning the addresses for the other sensors, but I could be wrong.....
Any suggestions or solutions to this issue would be greatly appreciated. My backup plan is to resort back to the arduino Nano with the a data logging shield which I have tested and was able to get good data for my project; however, trying to synch and operate 30 individual sensors at once is very time consuming.
Code: Select all
# sht85-auto-detect code
#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht;
// To use a specific sensor instead of probing the bus use this command:
// SHTSensor sht(SHTSensor::SHT3X);
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(115200);
delay(1000); // let serial console settle
if (sht.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x
}
void loop() {
// put your main code here, to run repeatedly:
if (sht.readSample()) {
Serial.print("Temperature: ");
Serial.print(sht.getTemperature(), 2);
Serial.print(' ');
Serial.print("RH: ");
Serial.print(sht.getHumidity(), 2);
Serial.print(' ');
Serial.println();
} else {
Serial.print("Error in readSample()\n");
}
delay(1000);
}
Code: Select all
# this is the code that was written to run four sensors at once.
#include <Wire.h>
#include "SHTSensor.h"
#include <SPI.h>
#include <SD.h> // Include SD library
#include <RTClib.h>
//////////////// intiiliaze the 8 sensors in the box///////////////////////////////////
SHTSensor sht0;
SHTSensor sht1;
SHTSensor sht2;
SHTSensor sht3;
//SHTSensor sht4;
//SHTSensor sht5;
//SHTSensor sht6;
//SHTSensor sht7;
//////////////////////////////////////////////////////////////////////////////
RTC_DS1307 RTC;
File dataFile;
byte busStatus;
const int chipSelect = 10; // specify the data logging pin onboard the box
// To use a specific sensor instead of probing the bus use this command:
// SHTSensor sht(SHTSensor::SHT3X);
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup() {
// put your setup code here, to run once:
while (!Serial);
delay(1000);
Wire.begin();
Serial.begin(9600);
RTC.begin();
RTC.adjust(DateTime((__DATE__), (__TIME__))); //sets the RTC to the computer time when the sketch is loaded
while (!Serial){
}
///////////// Initiliaze the sht85 sensors////////////////////////////////////////////
tcaselect(0);
if (sht0.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
tcaselect(1);
if (sht1.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
tcaselect(2);
if (sht2.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
tcaselect(3);
if (sht3.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
// tcaselect(4);
// if (sht4.init()) {
// Serial.print("init(): success\n");
// } else {
// Serial.print("init(): failed\n");
// }
// tcaselect(5);
// if (sht5.init()) {
// Serial.print("init(): success\n");
// } else {
// Serial.print("init(): failed\n");
// }
// tcaselect(6);
// if (sht6.init()) {
// Serial.print("init(): success\n");
// } else {
// Serial.print("init(): failed\n");
// }
// tcaselect(7);
// if (sht7.init()) {
// Serial.print("init(): success\n");
// } else {
// Serial.print("init(): failed\n");
// }
//////////// Initiliazing the SD card and the RTC for time stamping samples/////////////////////////////////////
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
while (1);
Serial.println("initialization done.");
}
Serial.println("Initializing RTC...");
if(!RTC.begin()) {
Serial.println("Couldn't find RTC");
}
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
while(1);
Serial.println("RTC initialization done.");
}
}
void loop() {
DateTime now = DateTime(RTC.now().unixtime()+46);
dataFile = SD.open("sensor1.txt", FILE_WRITE);
if(dataFile) {
// put your main code here, to run repeatedly:
tcaselect(0);
if (sht0.readSample()) {
Serial.print("Temperature1: ");
Serial.print(sht0.getTemperature(), 2);
Serial.print(' ');
Serial.print("RH1: ");
Serial.print(sht0.getHumidity(), 2);
Serial.print(' ');
} else {
Serial.print("Error in readSample()\n");
}
tcaselect(1);
if (sht1.readSample()) {
Serial.print("Temperature2: ");
Serial.print(sht1.getTemperature(), 2);
Serial.print(' ');
Serial.print("RH2: ");
Serial.print(sht1.getHumidity(), 2);
Serial.print(' ');
} else {
Serial.print("Error in readSample()\n");
}
tcaselect(2);
if (sht2.readSample()) {
Serial.print("Temperature3: ");
Serial.print(sht2.getTemperature(), 2);
Serial.print(' ');
Serial.print("RH3: ");
Serial.print(sht2.getHumidity(), 2);
Serial.print(' ');
} else {
Serial.print("Error in readSample()\n");
}
tcaselect(3);
if (sht3.readSample()) {
Serial.print("Temperature4: ");
Serial.print(sht3.getTemperature(), 2);
Serial.print(' ');
Serial.print("RH4: ");
Serial.print(sht3.getHumidity(), 2);
Serial.print(' ');
} else {
Serial.print("Error in readSample()\n");
}
// tcaselect(4);
// if (sht4.readSample()) {
// Serial.print("Temperature5: ");
// Serial.print(sht4.getTemperature(), 2);
// Serial.print(' ');
// Serial.print("RH5: ");
// Serial.print(sht4.getHumidity(), 2);
// Serial.print(' ');
// } else {
// Serial.print("Error in readSample()\n");
// }
// tcaselect(5);
// if (sht5.readSample()) {
// Serial.print("Temperature6: ");
// Serial.print(sht5.getTemperature(), 2);
// Serial.print(' ');
// Serial.print("RH6: ");
// Serial.print(sht5.getHumidity(), 2);
// Serial.print(' ');
// } else {
// Serial.print("Error in readSample()\n");
// }
// tcaselect(6);
// if (sht6.readSample()) {
// Serial.print("Temperature7: ");
// Serial.print(sht6.getTemperature(), 2);
// Serial.print(' ');
// Serial.print("RH7: ");
// Serial.print(sht6.getHumidity(), 2);
// Serial.print(' ');
// } else {
// Serial.print("Error in readSample()\n");
// }
// tcaselect(7);
// if (sht7.readSample()) {
// Serial.print("Temperature8: ");
// Serial.print(sht7.getTemperature(), 2);
// Serial.print(' ');
// Serial.print("RH8: ");
// Serial.print(sht7.getHumidity(), 2);
// Serial.print(' ');
// } else {
// Serial.print("Error in readSample()\n");
// }
Serial.print(' ');
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
///////////////////// DATA LOGGING TO SD CARD LINES ////////////////////////////
dataFile.print(" RH1: ");
dataFile.print(sht0.getHumidity(), 2);
dataFile.print("");
dataFile.print(" Temperature1: ");
dataFile.print(sht0.getTemperature(),2);
dataFile.print(" RH2: ");
dataFile.print(sht1.getHumidity(), 2);
dataFile.print("");
dataFile.print(" Temperature2: ");
dataFile.print(sht1.getTemperature(),2);
dataFile.print(" RH3: ");
dataFile.print(sht2.getHumidity(), 2);
dataFile.print("");
dataFile.print(" Temperature3: ");
dataFile.print(sht2.getTemperature(),2);
dataFile.print(" RH4: ");
dataFile.print(sht3.getHumidity(), 2);
dataFile.print("");
dataFile.print(" Temperature4: ");
dataFile.print(sht3.getTemperature(),2);
//dataFile.print(" RH5: ");
//dataFile.print(sht4.getHumidity(), 2);
//dataFile.print("");
//dataFile.print(" Temperature5: ");
//dataFile.print(sht4.getTemperature(),2);
//
//dataFile.print(" RH6: ");
//dataFile.print(sht5.getHumidity(), 2);
//dataFile.print("");
//dataFile.print(" Temperature6: ");
//dataFile.print(sht5.getTemperature(),2);
//
//dataFile.print(" RH7: ");
//dataFile.print(sht6.getHumidity(), 2);
//dataFile.print("");
//dataFile.print(" Temperature7: ");
//dataFile.print(sht6.getTemperature(),2);
//
//dataFile.print(" RH8: ");
//dataFile.print(sht7.getHumidity(), 2);
//dataFile.print("");
//dataFile.print(" Temperature8: ");
//dataFile.print(sht7.getTemperature(),2);
////////////////// BEGIN PRINTING THE RTC TIME STAMPS OF SAMPLES///////////////////////////////////////
dataFile.print(' ');
dataFile.print(now.year(), DEC);
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.day(), DEC);
dataFile.print(' ');
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.println();
dataFile.close();
}
delay(1000);
}