MKR-WIFI-1010, MK-ENV-SHIELD-R2 and LCD 1602

Hello,
I am having a problem with using LCD 1602 with the MK-ENV-SHIELD-R2. The issue is I wrote code to dispay text to the LCD (wire connection is made via sensor Shield) and that works. The moment I try to write code listening the the sensors (MK-ENV-SHIELD-R2), then I can't write to the LCD screen. The code I'm using for gathering sensor data is based on documentation in https://www.arduino.cc/en/Guide/MKRENVShield.
I would appreciate it if anyone has an idea of what can be the issue. Thanks.
Code I'm running

#include <Arduino_MKRENV.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(0,1, 5, 4, 3, 2);
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2); // Set up the number of columns and rows on the LCD.
  lcd.clear();
  lcd.print("ROOM TEMP:");
}

void loop() {
  float temperature = ENV.readTemperature();

  float humidity    = ENV.readHumidity();

  float pressure    = ENV.readPressure();

  float illuminance = ENV.readIlluminance();

  float uva         = ENV.readUVA();

  float uvb         = ENV.readUVB();

  float uvIndex     = ENV.readUVIndex();
  lcd.clear();
  //lcd.setCursor(0,0);
  lcd.print("TEMP: ");
  lcd.setCursor(6,0);
  //lcd.print(String(temperature, 1));
  lcd.setCursor(0,1);
  lcd.print("HUMIDITY: ");
  lcd.setCursor(10,1);
  //lcd.print(String(humidity));

  // wait 1 second to print again

  delay(1000);
}

I think I may have solve the issue. How I solve it was putting a delay between reading the sensor and writing to LCD

#include <Arduino_MKRENV.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(0,1, 5, 4, 3, 2);
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2); // Set up the number of columns and rows on the LCD.
  lcd.clear();
  lcd.print("ROOM TEMP:");
     while (!Serial);

  if (!ENV.begin()) {

    Serial.println("Failed to initialize MKR ENV shield!");

    while (1);

  }
}

void loop() {

  float temperature = ENV.readTemperature();

  float humidity    = ENV.readHumidity();

  float pressure    = ENV.readPressure();

  float illuminance = ENV.readIlluminance();

  float uva         = ENV.readUVA();

  float uvb         = ENV.readUVB();

  float uvIndex     = ENV.readUVIndex();
  delay(1000);
  lcd.clear();
  //lcd.setCursor(0,0);
  lcd.print("TEMP: ");
  lcd.setCursor(6,0);
  lcd.print(String(temperature, 1));
  lcd.setCursor(0,1);
  lcd.print("HUMIDITY: ");
  lcd.setCursor(10,1);
  lcd.print(String(humidity));

  // wait 1 second to print again

  delay(1000);

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.