Created
November 13, 2023 01:29
-
-
Save paulohenriquesn/123e01c69eb1b0d927046f9df66cec99 to your computer and use it in GitHub Desktop.
eco2 reader
This file contains 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 <DFRobot_ENS160.h> | |
#include "DFRobot_AHT20.h" | |
#define I2C_COMMUNICATION | |
#ifdef I2C_COMMUNICATION | |
DFRobot_ENS160_I2C ENS160(&Wire, /*I2CAddr*/ 0x53); | |
#else | |
uint8_t csPin = D3; | |
DFRobot_ENS160_SPI ENS160(&SPI, csPin); | |
#endif | |
DFRobot_AHT20 aht20; | |
float temperatura_C; | |
float umidade_R; | |
int ECO2; | |
int TVOC; | |
void setup(void) { | |
Serial.begin(9600); | |
while (NO_ERR != ENS160.begin()) { | |
Serial.println("Communication with device failed, please check connection"); | |
delay(3000); | |
} | |
Serial.println("Begin ok!"); | |
uint8_t status; | |
while ((status = aht20.begin()) != 0) { | |
Serial.print("AHT20 sensor initialization failed. error status : "); | |
Serial.println(status); | |
delay(1000); | |
} | |
ENS160.setPWRMode(ENS160_STANDARD_MODE); | |
ENS160.setTempAndHum(/*temperature=*/25.0, /*humidity=*/50.0); | |
} | |
void loop() { | |
ECO2 = ENS160.getECO2(); | |
Serial.println(ECO2); | |
if (aht20.startMeasurementReady(/* crcEn = */ true)) { | |
temperatura_C = aht20.getTemperature_C(); | |
umidade_R = aht20.getHumidity_RH(); | |
} | |
ENS160.setTempAndHum(/*temperature=*/temperatura_C, /*humidity=*/umidade_R); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment