Problem showing a lcd screen message

Hi, I bought this: https://wiki.keyestudio.com/KS0457_keyestudio_CCS811_Carbon_Dioxide_Air_Quality_Sensor
and it works.

#include <CCS811.h>

//CCS811 sensor(&Wire, /*IIC_ADDRESS=*/0x5A);
CCS811 sensor;

void setup(void)
{
    Serial.begin(115200);
    /*Wait for the chip to be initialized completely, and then exit*/
    while(sensor.begin() != 0){
        Serial.println("failed to init chip, please check if the chip connection is fine");
        delay(1000);
    }
    /**
     * @brief Set measurement cycle
     * @param cycle:in typedef enum{
     *                  eClosed,      //Idle (Measurements are disabled in this mode)
     *                  eCycle_1s,    //Constant power mode, IAQ measurement every second
     *                  eCycle_10s,   //Pulse heating mode IAQ measurement every 10 seconds
     *                  eCycle_60s,   //Low power pulse heating mode IAQ measurement every 60 seconds
     *                  eCycle_250ms  //Constant power mode, sensor measurement every 250ms
     *                  }eCycle_t;
     */
    sensor.setMeasCycle(sensor.eCycle_250ms);
}
void loop() {
  delay(1000);
    if(sensor.checkDataReady() == true){
        Serial.print("CO2: ");
        Serial.print(sensor.getCO2PPM());
        Serial.print("ppm, TVOC: ");
        Serial.print(sensor.getTVOCPPB());
        Serial.println("ppb");
        
    } else {
        Serial.println("Data is not ready!");
    }
    /*!
     * @brief Set baseline
     * @param get from getBaseline.ino
     */
    sensor.writeBaseLine(0x847B);
    //delay cannot be less than measurement cycle
    //delay(1000);
}

But I would like to add a lcd screen so i can watch the monitor without Arduino IDE. I don't know how to to the code because i tried but it didn't work:

Hello,
Magic, what is not working ?
Post your sketch and a wiring diagram of the complete hardware in use.

lcd.print() instead of Serial.print() probably (after setting the right coordinates on where you want to print the information with lcd.setCursor())

For what it's worth, I used to use that interface for talking to LCD screens and found it to be extremely messy and prone to issues with any poor connections.

Of recent I switched to using the 4 wire I2C interface for controlling my screens (and other peripherals -- you can add many devices all at once to the same serial bus) (I have one project working just fine with an LCD screen, OLED screen, and RTC module all controlled from the same 4 wires) and never looked back; it makes for a FAR less cluttered and far more reliable interface ... and programming it is much the same.

You can get converters that allow the typical 16 x 2 LCD to talk to the I2C bus for a few bucks.

Let me know if you need more info.

Here's a quick sketch that's currently displaying on my LCD:

#include <Wire.h>                                                                 // I2C library
#include <LiquidCrystal_I2C.h>                                          // LCD library

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);   //

// SETUP CODE

void setup()                                                                            // Setup code starts here (runs once)
{
  Serial.begin(57600);                                                            //
  
  lcd.init();                                                                                // Prep LCD
  lcd.backlight();                                                                     // Backlight on
  
  lcd.print("Hello fedezsuper");                                           // Display line 1
  lcd.setCursor(0,1);                                                              // Reposition cursor
  lcd.print("How you doin?");                                               // Display line 2
}
        
// MAIN CODE

void loop()                                                                       // Main code starts here
{
}

Hi, no. With this post i asked how to print the first code (u can see that there's a serial print meaning it write something in the monitor) and i would like to print these monitor messages to a lcd screen

"No" what ??... I don't get what you object to.

I'm saying that instead of

        Serial.print("CO2: ");
        Serial.print(sensor.getCO2PPM());
        Serial.print("ppm, TVOC: ");
        Serial.print(sensor.getTVOCPPB());
        Serial.println("ppb");

you replace Serial by lcd (and get rid of the ln at the end and use setCursor instead to position your text at the right position)

(you'll have other things to solve like clearing the screen or not, optimising when you display etc but that will get you going)

Ohh sorry! I didn't understand

PS: I just had a closer look that the sensor and see that it has an I2C bus - in which case it's an absolute no-brainer to just hook an LCD screen up to the same bus (just put it in parallel) - in which case my sample code I gave you above will get you started in the right direction.

To convert your LCD to I2C just get one of these:

They can be found pretty much everywhere. Soooo much easier.

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