Skip to content

Instantly share code, notes, and snippets.

@paulohenriquesn
Created November 23, 2023 00:35
Show Gist options
  • Save paulohenriquesn/b42cece8fa64517c587fcc53b49c825e to your computer and use it in GitHub Desktop.
Save paulohenriquesn/b42cece8fa64517c587fcc53b49c825e to your computer and use it in GitHub Desktop.
#include <DFRobot_ENS160.h>
#include "DFRobot_AHT20.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x38,16,2);
#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);
lcd.init();
lcd.print("0");
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);
lcd.clear();
lcd.print(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