Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Required Parts
- - ESP8266 V3 Module (https://amzn.to/3jvniw0)(https://s.click.aliexpress.com/e/_Ak3Lem)
- - BME680 Module (https://amzn.to/36ShuYg)(https://s.click.aliexpress.com/e/_AEkwT4)
- - 0.96" OLED Module (https://amzn.to/36ShuYg)(https://s.click.aliexpress.com/e/_AK5W8m)
- - Dupont Wires (Included w/ OLED)(https://s.click.aliexpress.com/e/_AXslsa)
- Print the case:
- https://www.thingiverse.com/thing:4755364
- 1. Download & install the Arduino IDE
- https://www.arduino.cc/en/software
- 2. Install the ESP8266 Board
- 2.1. In your Arduino IDE, go to File> Preferences
- 2.2. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into the “Additional Boards Manager URLs”. Click OK.
- 2.3. Open the Boards Manager. Go to "Tools > Board > Boards Manager…".
- 2.4. Search for ESP8266 and press install button for the “ESP8266 by ESP8266 Community“.
- 2.5. Select "NodeMCU 1.0 (ESP-12E Module)" under "Tools > Board: "XXXX""
- 2.6. Select the correct COM port under "Tools > Port: "XXXX""
- 3. Install Oled & BME Libraries
- 3.1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.
- 3.2. Search for "SSD1306", and install "Adafruit SSD1306" library.
- 3.3. Search for "BSEC", and install "BSEC Software Library" library.
- 4. Wire the modules. Both modules will connect to the same headers on the ESP board.
- SCL (or SCK or C)> D1
- SDA (or D) > D2
- VCC (or 3V or +) > 3V3
- GND (or -) > GND
- 5. Paste the code, compile & test!
- My code: (based on Adafruit example (which was based on Bosch example), modified for my OLED module)
- #include <Wire.h>
- #include <Adafruit_SSD1306.h>
- #include "bsec.h"
- #define SEALEVELPRESSURE_HPA (1013.25)
- Bsec iaqSensor;
- String output;
- void checkIaqSensorStatus(void);
- void errLeds(void);
- Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- Wire.begin();
- Serial.println(F("Starting..."));
- if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
- Serial.println(F("SSD1306 allocation failed"));
- for(;;);
- }
- Serial.println("OLED begun");
- display.display();
- delay(100);
- display.clearDisplay();
- display.display();
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- display.setRotation(0);
- iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire);
- output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
- Serial.println(output);
- checkIaqSensorStatus();
- bsec_virtual_sensor_t sensorList[10] = {
- BSEC_OUTPUT_RAW_TEMPERATURE,
- BSEC_OUTPUT_RAW_PRESSURE,
- BSEC_OUTPUT_RAW_HUMIDITY,
- BSEC_OUTPUT_RAW_GAS,
- BSEC_OUTPUT_IAQ,
- BSEC_OUTPUT_STATIC_IAQ,
- BSEC_OUTPUT_CO2_EQUIVALENT,
- BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
- BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
- BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
- };
- iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
- checkIaqSensorStatus();
- // Print the header
- output = "Timestamp [ms], raw temperature [°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, temperature [°C], relative humidity [%], Static IAQ, CO2 equivalent, breath VOC equivalent";
- Serial.println(output);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- display.setCursor(0,0);
- display.clearDisplay();
- unsigned long time_trigger = millis();
- if (iaqSensor.run()) { // If new data is available
- output = String(time_trigger);
- output += ", " + String(iaqSensor.rawTemperature);
- output += ", " + String(iaqSensor.pressure);
- output += ", " + String(iaqSensor.rawHumidity);
- output += ", " + String(iaqSensor.gasResistance);
- output += ", " + String(iaqSensor.iaq);
- output += ", " + String(iaqSensor.iaqAccuracy);
- output += ", " + String(iaqSensor.temperature);
- output += ", " + String(iaqSensor.humidity);
- output += ", " + String(iaqSensor.staticIaq);
- output += ", " + String(iaqSensor.co2Equivalent);
- output += ", " + String(iaqSensor.breathVocEquivalent);
- Serial.println(output);
- } else {
- checkIaqSensorStatus();
- }
- Serial.print("Temperature = "); Serial.print(iaqSensor.temperature); Serial.println(" *C");
- display.print("Temperature: "); display.print(iaqSensor.temperature); display.println(" *C");
- Serial.print("Pressure = "); Serial.print(iaqSensor.pressure / 100.0); Serial.println(" hPa");
- display.print("Pressure: "); display.print(iaqSensor.pressure / 100); display.println(" hPa");
- Serial.print("Humidity = "); Serial.print(iaqSensor.humidity); Serial.println(" %");
- display.print("Humidity: "); display.print(iaqSensor.humidity); display.println(" %");
- Serial.print("IAQ = "); Serial.print(iaqSensor.staticIaq); Serial.println("");
- display.print("IAQ: "); display.print(iaqSensor.staticIaq); display.println("");
- Serial.print("CO2 equiv = "); Serial.print(iaqSensor.co2Equivalent); Serial.println("");
- display.print("CO2eq: "); display.print(iaqSensor.co2Equivalent); display.println("");
- Serial.print("Breath VOC = "); Serial.print(iaqSensor.breathVocEquivalent); Serial.println("");
- display.print("VOC: "); display.print(iaqSensor.breathVocEquivalent); display.println("");
- Serial.println();
- display.display();
- delay(2000);
- }
- // Helper function definitions
- void checkIaqSensorStatus(void)
- {
- if (iaqSensor.status != BSEC_OK) {
- if (iaqSensor.status < BSEC_OK) {
- output = "BSEC error code : " + String(iaqSensor.status);
- Serial.println(output);
- for (;;)
- errLeds(); /* Halt in case of failure */
- } else {
- output = "BSEC warning code : " + String(iaqSensor.status);
- Serial.println(output);
- }
- }
- if (iaqSensor.bme680Status != BME680_OK) {
- if (iaqSensor.bme680Status < BME680_OK) {
- output = "BME680 error code : " + String(iaqSensor.bme680Status);
- Serial.println(output);
- for (;;)
- errLeds(); /* Halt in case of failure */
- } else {
- output = "BME680 warning code : " + String(iaqSensor.bme680Status);
- Serial.println(output);
- }
- }
- }
- void errLeds(void)
- {
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, HIGH);
- delay(100);
- digitalWrite(LED_BUILTIN, LOW);
- delay(100);
- }
- References used:
- https://randomnerdtutorials.com/esp8266-0-96-inch-oled-display-with-arduino-ide/
- https://learn.adafruit.com/adafruit-bme680-humidity-temperature-barometic-pressure-voc-gas/bsec-air-quality-library
Advertisement
Add Comment
Please, Sign In to add comment