Hello everyone.
I’m trying to read from a CCS811 sensor. Unfortunately I keep getting error code 2 whenever I try to read.
Here is my code:
/***************************************************************************
This is a library for the CCS811 air
This sketch reads the sensor
Designed specifically to work with the Adafruit CCS811 breakout
----> http://www.adafruit.com/products/3566
These sensors use I2C to communicate. The device's I2C address is 0x5A
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Dean Miller for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
#define CCS811_WAKE C2
#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;
void setup() {
Serial.begin(115200);
delay(5000);
pinMode(CCS811_WAKE, OUTPUT);
digitalWrite(CCS811_WAKE, LOW);
Serial.println("CCS811 test");
if(!ccs.begin()){
Serial.println("Failed to start sensor! Please check your wiring.");
while(1);
}
//calibrate temperature sensor
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
}
void loop() {
if(ccs.available()){
float temp = ccs.calculateTemperature();
int ret = ccs.readData();
if(ret == 0){
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.print(ccs.getTVOC());
Serial.print("ppb Temp:");
Serial.println(temp);
}
else{
Serial.printlnf("ERROR! %d", ret);
//while(1);
}
}
delay(500);
}
Output received over serial:
CCS811 test
ERROR! 2
ERROR! 2
ERROR! 2
ERROR! 2
ERROR! 2
...
EDIT:
I might be seeing this error because I didn’t give the sensor enough time to heat up. I’ll do more testing.