Hello there,
I hope it’s okay to post here and that someone can help me
I am currently working on my first project, where I try to display sensor values onto a small LCD (uno shield). The sensor and the display work fine when running them in isolation. When combining the code the problem starts: In my setup function I initialize the screen to be black and display a string, which works fine. But as soon as I request data from the sensor, in the loop function, the screen turns white and doesn’t recover after that.
Additional Information:
Sensor Sensiron SCD41 (Datasheet: https://cdn-reichelt.de/documents/datenblatt/A300/SENSIRION_CO2_SENSORS_SCD4X_DATASHEET.pdf)
Display Uno Shield MAR2808 2.8" TFT (8bit, Driver:ILI9341) (Datasheet https://cdn-reichelt.de/documents/datenblatt/A300/TF028%20SPECIFICATION.pdf )
My Code:
#include <MCUFRIEND_kbv.h>
#include <Arduino.h>
#include <SensirionI2CScd4x.h>
#include <Wire.h>
MCUFRIEND_kbv tft;
SensirionI2CScd4x scd4x;
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GRAY 0x8410
uint16_t version = MCUFRIEND_KBV_H_;
void setup()
{
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Wire.begin();
scd4x.begin(Wire);
scd4x.startPeriodicMeasurement();
uint16_t ID = tft.readID();
tft.reset();
tft.begin(ID);
tft.setRotation(1); // "PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
tft.fillScreen(BLACK);
tft.print("Waiting for first measurement...");
delay(10000);
}
void loop()
{
uint16_t ID = tft.readID();
uint16_t co2 = 0;
float temperature = 0.0f;
float humidity = 0.0f;
bool isDataReady = false;
uint16_t error;
error = scd4x.getDataReadyFlag(isDataReady);
if (error) {
Serial.print("Error trying to execute getDataReadyFlag()");
return;
}
if (!isDataReady) {
delay(5000);
return;
}
scd4x.readMeasurement(co2, temperature, humidity);
Serial.print("Co2:");
Serial.print(co2);
Serial.print("\t");
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print("\t");
Serial.print("Humidity:");
Serial.println(humidity);
tft.fillScreen(BLACK);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(40, 40);
tft.print("C02: ");
tft.print(co2);
tft.println("ppm");
delay(10000);
}