Created
January 11, 2022 10:05
-
-
Save hollyhockberry/2e83cc0e3c22545480f4b165f21d022c to your computer and use it in GitHub Desktop.
SCD30 sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SparkFun_SCD30_Arduino_Library.h> | |
SCD30 airSensor; | |
void setup() { | |
Serial.begin(115200); | |
Wire.begin(1, 0); | |
if (airSensor.begin() == false) { | |
ESP_LOGE("", "Failed to begin SCD30."); | |
::esp_restart(); | |
for (;;) {} | |
} | |
} | |
void loop() { | |
if (!airSensor.dataAvailable()) { | |
return; | |
} | |
const auto co2 = airSensor.getCO2(); | |
const auto temper = airSensor.getTemperature(); | |
const auto humidity = airSensor.getHumidity(); | |
if (co2 <= 0 || temper <= 0.f || humidity <= 0.f) { | |
// たまにオール0の時があるので読み捨てる | |
return; | |
} | |
Serial.printf("CO2: %d ppm, ", co2); | |
Serial.printf("Temperature: %f C, ", temper); | |
Serial.printf("Humidity: %f %\r\n", humidity); | |
::delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment