When I use Adafruit SHT31 with Arduino and LCD(20X4)-I2C, Everything works actually but when I use Arduino MKR zero I have to click on the serial monitor to display the data on the LCD…Could you help me to solve that problem?.
#include <Arduino.h>[color=#2e8b57][/color]
#include <Wire.h>[color=#2e8b57][/color]
#include "Adafruit_SHT31.h"[color=#2e8b57][/color]
#include <LiquidCrystal_I2C.h>[color=#2e8b57][/color]
LiquidCrystal_I2C lcd(0x27, 20, 4);[color=#2e8b57][/color]
bool enableHeater = false;[color=#2e8b57][/color]
uint8_t loopCnt = 0;[color=#2e8b57][/color]
[color=#2e8b57][/color]
Adafruit_SHT31 sht31 = Adafruit_SHT31();[color=#2e8b57][/color]
[color=#2e8b57][/color]
void setup() { lcd.init();[color=#2e8b57][/color]
lcd.backlight();[color=#2e8b57][/color]
Serial.begin(9600);[color=#2e8b57][/color]
while (!Serial)[color=#2e8b57][/color]
delay(10); // will pause Zero, Leonardo, etc until serial console opens[color=#2e8b57][/color]
[color=#2e8b57][/color]
Serial.println("SHT31 test");[color=#2e8b57][/color]
if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr[color=#2e8b57][/color]
Serial.println("Couldn't find SHT31");[color=#2e8b57][/color]
while (1) delay(1);[color=#2e8b57][/color]
}[color=#2e8b57][/color]
[color=#2e8b57][/color]
Serial.print("Heater Enabled State: ");[color=#2e8b57][/color]
if (sht31.isHeaterEnabled())[color=#2e8b57][/color]
Serial.println("ENABLED");[color=#2e8b57][/color]
else[color=#2e8b57][/color]
Serial.println("DISABLED");[color=#2e8b57][/color]
}[color=#2e8b57][/color]
[color=#2e8b57][/color]
[color=#2e8b57][/color]
void loop() {[color=#2e8b57][/color]
float t = sht31.readTemperature();[color=#2e8b57][/color]
float h = sht31.readHumidity();[color=#2e8b57][/color]
if (! isnan(t)) { // check if 'is not a number'[color=#2e8b57][/color]
[color=#2e8b57][/color]
Serial.print("Temp *C = ");[color=#2e8b57][/color]
Serial.print(t);[color=#2e8b57][/color]
lcd.setCursor(0,0);[color=#2e8b57][/color]
lcd.print("Temp *C = ");[color=#2e8b57][/color]
lcd.print(t);[color=#2e8b57][/color]
[color=#2e8b57][/color]
} else {[color=#2e8b57][/color]
// Serial.println("Failed to read temperature");[color=#2e8b57][/color]
lcd.print("Failed to read temperature");[color=#2e8b57][/color]
[color=#2e8b57][/color]
}[color=#2e8b57][/color]
[color=#2e8b57][/color]
if (! isnan(h)) { // check if 'is not a number'[color=#2e8b57][/color]
[color=#2e8b57][/color]
Serial.print("Hum. % = ");[color=#2e8b57][/color]
Serial.println(h);[color=#2e8b57][/color]
lcd.setCursor(0, 1);[color=#2e8b57][/color]
lcd.print("Hum. % = ");[color=#2e8b57][/color]
lcd.print(h);[color=#2e8b57][/color]
} else {[color=#2e8b57][/color]
// Serial.println("Failed to read humidity");[color=#2e8b57][/color]
lcd.print("Failed to read humidity");[color=#2e8b57][/color]
[color=#2e8b57][/color]
}[color=#2e8b57][/color]
[color=#2e8b57][/color]
delay(1000);[color=#2e8b57][/color]
[color=#2e8b57][/color]
// Toggle heater enabled state every 30 seconds[color=#2e8b57][/color]
// An ~3.0 degC temperature increase can be noted when heater is enabled[color=#2e8b57][/color]
if (++loopCnt == 30) {[color=#2e8b57][/color]
enableHeater = !enableHeater;[color=#2e8b57][/color]
sht31.heater(enableHeater);[color=#2e8b57][/color]
Serial.print("Heater Enabled State: ");[color=#2e8b57][/color]
if (sht31.isHeaterEnabled())[color=#2e8b57][/color]
Serial.println("ENABLED");[color=#2e8b57][/color]
else[color=#2e8b57][/color]
Serial.println("DISABLED");[color=#2e8b57][/color]
[color=#2e8b57][/color]
loopCnt = 0;[color=#2e8b57][/color]
}[color=#2e8b57][/color]
}