Adafruit CCS811 library won't include in Photon

On a 0.6.3 Photon, in the Web IDE after doing

#include <Adafruit_CCS811.h>

(using the bookmark tab in the IDE to include it) I get an error:

bme280test.ino:15:29: Adafruit_CCS811.h: No such file or directory

Full code here:

    // This #include statement was automatically added by the Particle IDE.
    #include <SparkFunMicroOLED.h>

    // Code from:

    // This #include statement was automatically added by the Particle IDE.
    #include <Adafruit_Sensor.h>

    // This #include statement was automatically added by the Particle IDE.
    #include <Adafruit_BME280.h>

    // This #include statement was automatically added by the Particle IDE.
    #include <Adafruit_CCS811.h>

    /*    MicroOLED ------------- Photon
          GND ------------------- GND
          VDD ------------------- 3.3V (VCC)
        D1/MOSI ----------------- A5 (don't change)
        D0/SCK ------------------ A3 (don't change)
          D/C ------------------- D6 (can be any digital pin)
          RST ------------------- D7 (can be any digital pin)
          CS  ------------------- A2 (can be any digital pin)
    Adafruit_BME280 bme;
    MicroOLED oled;

    #define BME_MOSI D0
    #define BME_SCK D1

    #define SEALEVELPRESSURE_HPA (1013.25)

    // setup() runs once, when the device is first turned on.
    void setup() {
      oled.begin();    // Initialize the OLED
      oled.clear(ALL); // Clear the display's internal memory
      oled.display();  // Display what's in the buffer (splashscreen)
      delay(1000);     // Delay 1000 ms
      oled.clear(PAGE); // Clear the buffer.

      // randomSeed(analogRead(A0) + analogRead(A1));
      oled.setFontType(1);  // Set font to type 1 (display can show 3 lines of 7 chars.)
      oled.clear(PAGE);     // Clear the page
      oled.setCursor(0, 0); // Set cursor to top-left (x,y)
      // Print can be used to print a string to the screen:
      oled.print("OLED OK");

     if (bme.begin())  // had arg = 0x76
          Particle.publish("BME280 sensor works!",PRIVATE);
          oled.setCursor(0, 16);
          oled.print ("BME OK");
      delay (1000) ;


    // loop() runs over and over again, as quickly as it can execute.
    void loop() {
      // The core of your code will likely live here.

      float t = bme.readTemperature() * 9 / 5 + 32 ; // *F
      float h = bme.readHumidity(); // %
      float p = bme.readPressure() / 100.0F; // hPa
      float a = bme.readAltitude(SEALEVELPRESSURE_HPA);

      // Get some data - measure battery voltage
      String data = String::format("%.2f",t) + "*C:" + String::format("%.2f",h) + "%:"
       + String::format("%.2f",p) + "hPa:" + String::format("%.2f",a) + "m";

      // Publish data to Particle Cloud
      // Particle.publish("data", data,PRIVATE);
      oled.clear(PAGE) ; 
      oled.setCursor(0, 16); // Set cursor to top-left (x,y)
      // Print can be used to print a string to the screen:
      oled.print ("T=") ;
      oled.print (t) ;
      oled.setCursor(0, 32);
      oled.print ("H=") ; 
      oled.print (h) ;



I have seen this problem before and it seems to be a glitch in the Web IDE (with several other libraries too).
For me just changing #include <Adafruit_CCS811.h> to #include "Adafruit_CCS811.h" usually cures the problem. Once you have changed that, you can even change it back and the build still works.

It might be, that the omitted “stub-header” ./Adafruit_CCS811/Adafruit_CCS811.h may cause that behaviour in Web IDE, but having it there usually created other issues with Particle Dev Desktop IDE and CLI, so I decided to not include it (and it’s not used in Arduino libraries either).

1 Like

Well this is very odd. If I create a new app with nothing other than

#include "Adafruit_CCS811.h"

in it, it compiles just fine. But when I try that line in the code I posted in the OP, it still gives that NSF error. I tried removing the original CCS811 library using the “X” button in the IDE and then reincluding it using the bookmark icon and changing the name from <> to “”, but it still won’t find it.

Just out of curiosity, are you able to get the program I posted to compile with the library in quotes?

Because if you look at what the compiler/linker is actually doing, it’s like it doesn’t even see that include line. (Note there’s no entry for “Checking library Adafruit_CCS811.h”)

Processing  bme280test.ino
Checking library Adafruit_BME280...
Checking library Adafruit_Sensor...
Checking library SparkFunMicroOLED...
Installing library Adafruit_Sensor 1.0.2 to lib/Adafruit_Sensor ...
Installing library Adafruit_BME280 1.1.4 to lib/Adafruit_BME280 ...
Installing library SparkFunMicroOLED 1.3.0 to lib/SparkFunMicroOLED ...
Library Adafruit_BME280 1.1.4 installed.
Library SparkFunMicroOLED 1.3.0 installed.
Library Adafruit_Sensor 1.0.2 installed.
make -C ../modules/photon/user-part all
make[1]: Entering directory '/firmware/modules/photon/user-part'
make -C ../../../user 
make[2]: Entering directory '/firmware/user'
Building cpp file: src/bme280test.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DPARTICLE_NO_ARDUINO_COMPATIBILITY=0 -DSYSTEM_VERSION_STRING=0.6.1 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -Isrc -I./libraries -Isrc -Isrc -Isrc -Isrc -Ilib/Adafruit_Sensor/src -Ilib/SparkFunMicroOLED/src -Ilib/Adafruit_BME280/src -I. -MD -MP -MF ../build/target/user/platform-6-msrc/bme280test.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSE_THREADING=0 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSE_THREADING=0 -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=4 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,105 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-6-msrc/bme280test.o src/bme280test.cpp
bme280test.ino:2:29: fatal error: Adafruit_CCS811.h: No such file or directory
compilation terminated.
../build/ recipe for target '../build/target/user/platform-6-msrc/bme280test.o' failed
make[2]: Leaving directory '/firmware/user'
make[2]: *** [../build/target/user/platform-6-msrc/bme280test.o] Error 1
../../../build/ recipe for target 'user' failed
make[1]: *** [user] Error 2
make[1]: Leaving directory '/firmware/modules/photon/user-part'
../build/ recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2

UPDATE: I tried copying the body of the non-compiling code from the OP into the blank app that did work and compiling that. Now that works. Go figure.

Anyway, thanks @ScruffR. You had the answer, as always.

Oh and for the benefit of anyone else trying to get this sensor running, there are a number of contradictory examples out there. I found that I had to start the sensor with the line


or it wouldn’t work. (0x5B is the default I2C address for the CCS811 on the Sparkfun CCS811+BME280 combo board I’m using).

1 Like