-
Notifications
You must be signed in to change notification settings - Fork 4
/
CCS811_OLED.ino
80 lines (64 loc) · 1.88 KB
/
CCS811_OLED.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* This demo shows how to display the CCS811 readings on an Adafruit I2C OLED.
* (We used a Feather + OLED FeatherWing)
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;
Adafruit_SSD1306 display = Adafruit_SSD1306();
void setup() {
Serial.begin(9600);
if(!ccs.begin()){
Serial.println("Failed to start sensor! Please check your wiring.");
while(1);
}
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(500);
// Clear the buffer.
display.clearDisplay();
display.display();
//calibrate temperature sensor
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
Serial.println("IO test");
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop() {
display.setCursor(0,0);
if(ccs.available()){
display.clearDisplay();
float temp = ccs.calculateTemperature();
if(!ccs.readData()){
display.print("eCO2: ");
Serial.print("eCO2: ");
float eCO2 = ccs.geteCO2();
display.print(eCO2);
Serial.print(eCO2);
display.print(" ppm\nTVOC: ");
Serial.print(" ppm, TVOC: ");
float TVOC = ccs.getTVOC();
display.print(TVOC);
Serial.print(TVOC);
Serial.print(" ppb Temp:");
display.print(" ppb\nTemp: ");
Serial.println(temp);
display.println(temp);
display.display();
}
else{
Serial.println("ERROR!");
while(1);
}
}
delay(500);
}