Hi there,
I'm currently attempting to read data form a Davis Instruments temperature and relative humidity sensor. This instrument is powered by the Sensiron SHT31-LSS, which is a digital sensor that communicates using the Legacy Sensibus protocol. Sensiron provides an Arduino library on GitHub, which has allowed me to successfully read the temperature and humidity when connecting the SHT31-LSS by itself to an Adafruit Feather M0.
The problem I'm encountering is that when I add a DS3231 RTC to the I2C bus, the Arduino will crash after reading the Sensibus device. From what I've read, Senisbus and I2C devices should be able to coexist on the same bus, but I'm wondering if this isn't actually the case.
The code I'm using to read both devices is included below and I've noted at which point the code fails.
I hadn't heard of Legacy Sensibus before today, so I'd appreciate if anyone has some insight as to what could be going wrong. Should these two devices be able to play nicely? From what I can tell, the Sensibus protocol appears to be rendering I2C inoperable.
Cheers,
Adam
#include <DS3232RTC.h> // https://github.com/JChristensen/DS3232RTC
#include <sensirion.h> // https://github.com/HydroSense/sensirion
// Specify data and clock connections and instantiate sensirion object
#define dataPin 20
#define clockPin 21
#define ledPin 13
DS3232RTC myRTC(false); // Tell constructor not to initialize the I2C bus
sensirion sht(dataPin, clockPin);
time_t t;
tmElements_t tm;
void setup()
{
Serial.begin(9600); // Open serial connection to report values to host
while (!Serial);
pinMode(ledPin, OUTPUT);
myRTC.begin(); // Initialize the I2C bus
// Print current date and time
printDateTime(myRTC.get());
}
void loop()
{
readSht31();
Serial.println("readSHT31() complete"); // This print statement is seen in the serial console
printDateTime(myRTC.get());
Serial.println("printDateTime() complete"); // This print statement is never seen. Program crashes.
delay(2000);
}
void readSht31() {
// Blink
digitalWrite(ledPin, (digitalRead(ledPin) == HIGH) ^ 1);
// Read sensor
uint16_t status = sht.readStatus();
float temp_c = sht.readTemperatureC();
float temp_f = sht.readTemperatureF();
float humidity = sht.readHumidity();
// Print data to serial
Serial.print("Status: 0x"); Serial.println(status, HEX);
Serial.print("Temperature: "); Serial.print(temp_c, DEC); Serial.println(" C");
Serial.print("Temperature: "); Serial.print(temp_f, DEC); Serial.println(" F");
Serial.print("Humidity: "); Serial.print(humidity); Serial.println("%");
}
// Print current time and date
void printDateTime(time_t t)
{
Serial.print((day(t) < 10) ? "0" : ""); Serial.print(day(t), DEC); Serial.print('/');
Serial.print((month(t) < 10) ? "0" : ""); Serial.print(month(t), DEC); Serial.print('/');
Serial.print(year(t), DEC); Serial.print(' ');
Serial.print((hour(t) < 10) ? "0" : ""); Serial.print(hour(t), DEC); Serial.print(':');
Serial.print((minute(t) < 10) ? "0" : ""); Serial.print(minute(t), DEC); Serial.print(':');
Serial.print((second(t) < 10) ? "0" : ""); Serial.println(second(t), DEC);
}