K
K
kesha156142021-06-16 13:38:32
Arduino
kesha15614, 2021-06-16 13:38:32

Why is the screen flickering?

Hello. I am trying to display the temperature on the lcd 1602 i2c screen from the bme280 sensor, but when I try to do this, the screen starts to flicker. As soon as I remove the line of code with the output of the temperature, everything starts working fine.

here is the code

#include <iarduino_RTC.h>
iarduino_RTC time(RTC_DS1307);       
#include <Wire.h>                             
#include <LiquidCrystal_I2C.h>      
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;
LiquidCrystal_I2C LCD(0x27,16,2); 

void setup() {
   delay(300);
   LCD.init();            
   LCD.backlight();  
   time.begin();
   time.settime(0, 30, 18, 12, 6, 20, 5); 
}

void loop() {
   if (millis() % 1000 == 0) {
      LCD.setCursor(0,0);
      LCD.print(bme.readTemperature());
      LCD.setCursor(4,1);
      LCD.print(time.gettime("H:i:s"));
      
      delay(1);
   }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Zaitsev, 2021-06-16
@KonstantineZ

bme.readTemperature() takes some time, long enough for the eye to notice the delay. Try to read the temperature into a variable, and then display it on the screen:

float temp = bme.readTemperature();
LCD.setCursor(0,0);
LCD.print(temp );
LCD.setCursor(4,1);
LCD.print(time.gettime("H:i:s"));

K
kalapanga, 2021-06-16
@kalapanga

You have two devices on the I2C bus. What are their addresses? Most likely they are in conflict.
BME280 also seems to work via SPI. Try like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question