Reference

Last revision 2025/12/17

This blog post explains how to install and utilize the CCS811 library for Arduino IDE, covering IIC communication protocol and API functions for measuring CO2 and TVOC concentrations, along with links to essential supplementary materials.

Library

Communication Protocol Description

  • Communication method: IIC (Inter-Integrated Circuit)
  • IIC Address: 0x5A (default) / 0x5B (if ADDR_SEL is soldered)
  • Note: The chip uses clock stretching in IIC, which is incompatible with some controllers (e.g., Raspberry Pi).

API Description

 /**
   * @brief Judge if the data can be read 
   * @return true when the reading is successful, false means it fails to read.
   */
  bool checkDataReady();
  
    /**
   * @brief Set environment parameter 
   * @param temperature Input temperature value, unit: centigrade, range (-40~85℃)
   * @param humidity    Input humidity value, unit: RH, range (0~100)
   */
  void setInTemHum(float temperature, float humidity);
  
  /**
   * @brief Measurement parameter configuration 
   * @param mode: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 1xx: Reserved modes (For future use)
   *          }eCycle_t;
   * @param thresh:0 for Interrupt mode operates normally; 1 for interrupt mode only asserts the nINT signal (driven low) if the new
   * @param interrupt:0 for Interrupt generation is disabled; 1 for the nINT signal is asserted (driven low) when a new sample is ready in
   */
  setMeasurementMode(eCycle_t mode, uint8_t thresh = 0, uint8_t interrupt = 0),
  
  /**
   * @brief Get the current carbon dioxide concentration 
   * @return current carbon dioxide concentration, unit:ppm
   */
  uint16_t  getCO2PPM();

  /**
   * @brief Get current TVOC concentration
   * @return Return current TVOC concentration, unit: ppb
   */
  uint16_t getTVOCPPB();
  
  /**
   *@brief get the current baseline number
   *@return a Hexadecimal number of the current baseline number
   */
  uint16_t readBaseLine();
  
  /**
   *@brief write a baseline number into register
   *@param a Hexadecimal number get from getBaseLine.ino
   */
  void writeBaseLine(uint16_t baseLine);

Other Supplementary Information

Was this article helpful?

TOP