Example8_Core.ino (3115B)
1 /****************************************************************************** 2 Core 3 4 Marshall Taylor @ SparkFun Electronics 5 6 April 4, 2017 7 8 https://github.com/sparkfun/CCS811_Air_Quality_Breakout 9 https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library 10 11 This example shows how the normally hidden core class operates the wire interface. 12 13 The class 'CCS811Core' abstracts the wire library and contains special hardware 14 functions, and is normally not needed. 15 16 Use this sketch to test the core of the library, or inherit it with your own 17 functions for performing CCS811 operations. 18 19 Hardware Connections (Breakoutboard to Arduino): 20 3.3V to 3.3V pin 21 GND to GND pin 22 SDA to A4 23 SCL to A5 24 25 26 Resources: 27 Uses Wire.h for i2c operation 28 29 Development environment specifics: 30 Arduino IDE 1.8.1 31 32 This code is released under the [MIT License](http://opensource.org/licenses/MIT). 33 34 Please review the LICENSE.md file included with this example. If you have any questions 35 or concerns with licensing, please contact techsupport@sparkfun.com. 36 37 Distributed as-is; no warranty is given. 38 ******************************************************************************/ 39 #include <Wire.h> 40 41 #include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811 42 43 #define CCS811_ADDR 0x5B //Default I2C Address 44 //#define CCS811_ADDR 0x5A //Alternate I2C Address 45 46 CCS811Core mySensor(CCS811_ADDR); 47 48 void setup() 49 { 50 Serial.begin(115200); 51 Serial.println(); 52 Serial.println("CCS811 Core Example"); 53 54 Wire.begin(); 55 56 //This setup routine is similar to what is used in the subclass' .begin() function 57 CCS811Core::CCS811_Status_e returnCode = mySensor.beginCore(Wire); //Pass in the Wire port you want to use 58 Serial.print("beginCore exited with: "); 59 switch (returnCode) 60 { 61 case CCS811Core::CCS811_Stat_SUCCESS: 62 Serial.print("SUCCESS"); 63 break; 64 case CCS811Core::CCS811_Stat_ID_ERROR: 65 Serial.print("ID_ERROR"); 66 break; 67 case CCS811Core::CCS811_Stat_I2C_ERROR: 68 Serial.print("I2C_ERROR"); 69 break; 70 case CCS811Core::CCS811_Stat_INTERNAL_ERROR: 71 Serial.print("INTERNAL_ERROR"); 72 break; 73 case CCS811Core::CCS811_Stat_GENERIC_ERROR: 74 Serial.print("GENERIC_ERROR"); 75 break; 76 default: 77 Serial.print("Unspecified error."); 78 } 79 80 //Write to this register to start app 81 Wire.beginTransmission(CCS811_ADDR); 82 Wire.write(CSS811_APP_START); 83 Wire.endTransmission(); 84 } 85 86 void loop() 87 { 88 uint8_t arraySize = 10; 89 uint8_t tempData[arraySize]; 90 91 tempData[0] = 0x18; 92 tempData[1] = 0x27; 93 tempData[2] = 0x36; 94 tempData[3] = 0x45; 95 96 mySensor.multiWriteRegister(0x11, tempData, 2); 97 98 tempData[0] = 0x00; 99 tempData[1] = 0x00; 100 tempData[2] = 0x00; 101 tempData[3] = 0x00; 102 103 mySensor.multiReadRegister(0x11, tempData, 3); 104 105 for (int i = 0; i < arraySize; i++) 106 { 107 if (i % 8 == 0) 108 { 109 Serial.println(); 110 Serial.print("0x"); 111 Serial.print(i, HEX); 112 Serial.print(":"); 113 } 114 115 Serial.print(tempData[i], HEX); 116 Serial.print(" "); 117 } 118 119 Serial.println("\n"); 120 delay(1000); //Wait for next reading 121 }