/****************************************************************************** Core.ino Marshall Taylor @ SparkFun Electronics April 4, 2017 https://github.com/sparkfun/CCS811_Air_Quality_Breakout https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library This example shows how the normally hidden core class operates the wire interface. The class 'CCS811Core' abstracts the wire library and contains special hardware functions, and is normally not needed. Use this sketch to test the core of the library, or inherit it with your own functions for performing CCS811 operations. Hardware Connections (Breakoutboard to Arduino): 3.3V to 3.3V pin GND to GND pin SDA to A4 SCL to A5 Resources: Uses Wire.h for i2c operation Development environment specifics: Arduino IDE 1.8.1 This code is released under the [MIT License](http://opensource.org/licenses/MIT). Please review the LICENSE.md file included with this example. If you have any questions or concerns with licensing, please contact techsupport@sparkfun.com. Distributed as-is; no warranty is given. ******************************************************************************/ #include #include "SparkFunCCS811.h" #include "SoftwareSerial.h" #define CCS811_ADDR 0x5B //Default I2C Address //#define CCS811_ADDR 0x5A //Alternate I2C Address SoftwareSerial mySerial(2, 8); // RX, TX CCS811Core mySensor(CCS811_ADDR); void setup() { mySerial.begin(9600); while(1){ mySerial.println(); mySerial.println("CCS811 Core Example"); delay(500); } //This setup routiene is similar to what is used in the subclass' .begin() function CCS811Core::status returnCode = mySensor.beginCore(); mySerial.print("beginCore exited with: "); switch ( returnCode ) { case CCS811Core::SENSOR_SUCCESS: mySerial.print("SUCCESS"); break; case CCS811Core::SENSOR_ID_ERROR: mySerial.print("ID_ERROR"); break; case CCS811Core::SENSOR_I2C_ERROR: mySerial.print("I2C_ERROR"); break; case CCS811Core::SENSOR_INTERNAL_ERROR: mySerial.print("INTERNAL_ERROR"); break; case CCS811Core::SENSOR_GENERIC_ERROR: mySerial.print("GENERIC_ERROR"); break; default: mySerial.print("Unspecified error."); } //Write to this register to start app Wire.beginTransmission(CCS811_ADDR); Wire.write(CSS811_APP_START); Wire.endTransmission(); } void loop() { uint8_t arraySize = 10; uint8_t tempData[arraySize]; tempData[0] = 0x18; tempData[1] = 0x27; tempData[2] = 0x36; tempData[3] = 0x45; mySensor.multiWriteRegister(0x11, tempData, 2); tempData[0] = 0x00; tempData[1] = 0x00; tempData[2] = 0x00; tempData[3] = 0x00; mySensor.multiReadRegister(0x11, tempData, 3); for ( int i = 0; i < arraySize; i++) { if (i % 8 == 0) { mySerial.println(); mySerial.print("0x"); mySerial.print(i, HEX); mySerial.print(":"); } mySerial.print(tempData[i], HEX); mySerial.print(" "); } mySerial.println("\n"); delay(1000); //Wait for next reading }