Hi friends
I want to use Co2 sensor Sensirion I2C SCD4x, I used the sample code after adding library of sensor and connect Liquid crystal LCD with I2C to MKR1010. It shows Co2, Humidity and temp every 5 seconds on LCD, but after closing Arduino software (closing serial monitor), it stops working and showing updates on LCD.
it not working just with power supply and needs to connect PC and running serial monitor software.
Can you please help me,
Code is in below , or you can see sample code of Sensirion I2C SCD4x here
my code
#include <SensirionI2CScd4x.h>
#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
SensirionI2CScd4x scd4x;
void printUint16Hex(uint16_t value) {
}
void setup() {
lcd.init(); // initialize the lcd
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Wire.begin();
uint16_t error;
char errorMessage[256];
scd4x.begin(Wire);
// stop potentially previously started measurement
error = scd4x.stopPeriodicMeasurement();
if (error) {
errorToString(error, errorMessage, 256);
}
uint16_t serial0;
uint16_t serial1;
uint16_t serial2;
error = scd4x.getSerialNumber(serial0, serial1, serial2);
if (error) {
errorToString(error, errorMessage, 256);
}
// Start Measurement
error = scd4x.startPeriodicMeasurement();
if (error) {
errorToString(error, errorMessage, 256);
}
}
void loop() {
uint16_t error;
char errorMessage[256];
delay(5000);
// Read Measurement
uint16_t co2;
float temperature;
float humidity;
error = scd4x.readMeasurement(co2, temperature, humidity);
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0, 0); //position
lcd.print("Co2: T: H:%");
lcd.setCursor(0, 1);
lcd.print(co2);
lcd.setCursor(5, 1);
lcd.print(temperature);
lcd.setCursor(11, 1);
lcd.print(humidity);
}