Hey there, im new and got a question regarding displays used for micro controllers.
I usa a arduino nano esp32 board which is connected to multiple sensors (BMP180, SGP30 & GY302) and the values should be printed on the display.
Till yet everything works like it should beside one thing: If one of the printed values on the display extends its digits (e.g. 300 ppb => 3000 ppb) and afterwards decreases the digits again (3000 ppb => 300 ppb) i get the correct repond for 300 ppb inside the serial monitor. On the display the last digit remains and does not dissapear again. Did anybody had this issue as well and has a solution ? ![]()
Please see my code below. Maybe there is an issue?
#include <LiquidCrystal.h>
#include <Wire.h>
#include <SimpleDHT.h>
#include <BMP180I2C.h>
#include <SGP30.h>
#include <BH1750.h>
#define I2C_ADDRESS 0x77
//create an BMP180 object using the I2C interface
BMP180I2C bmp180(I2C_ADDRESS);
// Variable SGP innerhalb SGP30 Klasse definieren
SGP30 SGP;
// Variable light Meter innerhalb BH1750 Klasse definieren
BH1750 lightMeter;
//Bytezähler auf 0 setzen
uint8_t count = 0;
// Pin Belegung des LCD Displays definieren.
const int rs=7, en=8, d4=9, d5=10, d6=11, d7=12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// Displaygrösse definieren.
lcd.begin(16, 2);
// Baudrate auf 9600 setzen zur unviersellen Kommunikation.
Serial.begin(9600);
//wait for serial connection to open (only necessary on some boards)
while (!Serial);
// Wire ĂĽbertragung aktivieren
Wire.begin();
// SGP30 Sensor aktivieren
SGP.begin();
//begin() initializes the interface, checks the sensor ID and reads the calibration parameters.
if (!bmp180.begin()){
Serial.println("begin() failed. check your BMP180 Interface and I2C Address.");
while (1);
}
//reset sensor to default parameters.
bmp180.resetToDefaults();
//enable ultra high resolution mode for pressure measurements
bmp180.setSamplingMode(BMP180MI::MODE_UHR);
// Lichtsensor starten
lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Start Temperaturmessung BMP180 Sensor
if (!bmp180.measureTemperature()){
return;
}
//wait for the measurement to finish. proceed as soon as hasValue() returned true.
do {
delay(100);
} while (!bmp180.hasValue());
//wait for the measurement to finish. proceed as soon as hasValue() returned true.
Serial.print("Temperature: ");
Serial.print(bmp180.getTemperature());
Serial.println(" °C");
//start a pressure measurement BMP180. pressure measurements depend on temperature measurement, you should only start a pressure measurement immediately after a temperature measurement.
if (!bmp180.measurePressure()){
return;
}
//wait for the measurement to finish. proceed as soon as hasValue() returned true.
do {
delay(100);
} while (!bmp180.hasValue());
Serial.print("Pressure: ");
Serial.print(bmp180.getPressure()/100);
Serial.println(" hPa");
// Start SGP30 Sensor Messung fĂĽr TVOC, CO2, H2, ETOH
SGP.measure(true);
Serial.print("TVOC = ");
Serial.print(SGP.getTVOC());
Serial.print(" ppb");
Serial.print("\t");
Serial.print("CO2 = ");
Serial.print(SGP.getCO2());
Serial.print(" ppm");
Serial.print("\t");
Serial.print("H2 = ");
Serial.print(SGP.getH2());
Serial.print(" ppm");
Serial.print("\t");
Serial.print("ETOH = ");
Serial.print(SGP.getEthanol());
Serial.print(" ppm");
Serial.println();
// Lichtsensor zur ausgabe der aktuelle Lichtintensität
while (!lightMeter.measurementReady(true)) {
yield();
}
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
lightMeter.configure(BH1750::ONE_TIME_HIGH_RES_MODE);
// Displayanzeige definieren
lcd.setCursor(0, 0);
// Position setzen von wo aus der näcchste input kommen soll. column 0, line 0 (note: line 1 is the second row, since counting begins with 0)
lcd.print(round(bmp180.getTemperature()), 1); // Ausgabe der Temperatur des BMP180 Sensors
lcd.setCursor(4, 0);
lcd.print("C");
lcd.setCursor(8, 0);
lcd.print(round(bmp180.getPressure()/100), 1);
lcd.print("hPa");
lcd.setCursor(0, 1);
lcd.print(SGP.getTVOC());
lcd.setCursor(4, 1);
lcd.print("ppb");
lcd.setCursor(8, 1);
lcd.print(SGP.getCO2());
lcd.setCursor(13, 1);
lcd.print("ppm");
delay(2000);
}