Created
January 16, 2022 15:30
-
-
Save maxpromer/d03a5a92ff6e5e6fb2cfda6a058baf1d to your computer and use it in GitHub Desktop.
AHT20 + BMP280 test code arduino
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
/* Dev by Artron Shop Co.,Ltd. */ | |
#include <Wire.h> | |
#include <Adafruit_BMP280.h> | |
#include <AHT10.h> | |
Adafruit_BMP280 bmp; | |
AHT10 myAHT20(AHT10_ADDRESS_0X38, AHT20_SENSOR); | |
void setup() { | |
Serial.begin(115200); | |
Serial.println(F("AHT20+BMP280 test")); | |
while (myAHT20.begin() != true) { | |
Serial.println(F("AHT20 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free | |
delay(5000); | |
} | |
Serial.println(F("AHT20 OK")); | |
if (!bmp.begin()) { | |
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); | |
while (1); | |
} | |
/* Default settings from datasheet. */ | |
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ | |
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ | |
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ | |
Adafruit_BMP280::FILTER_X16, /* Filtering. */ | |
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ | |
} | |
void loop() { | |
Serial.printf("Temperature: %.02f *C\n", myAHT20.readTemperature()); | |
Serial.printf("Humidity: %.02f %RH\n", myAHT20.readHumidity()); | |
Serial.printf("Pressure: %.02f hPa\n", bmp.readPressure()); | |
delay(1000); | |
} |
for sensor aht20+bmp280 you must add wire.h library
#include <Wire.h> // Asta salvează tot!
#include <Adafruit_AHTX0.h>
#include <Adafruit_BMP280.h>
#define SDA_PIN 4
#define SCL_PIN 5
Adafruit_AHTX0 aht;
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(115200);
delay(500);
Wire.begin(SDA_PIN, SCL_PIN); // Salvatorul tăcut
aht.begin();
bmp.begin(0x77);
}
void loop() {
sensors_event_t humidity, temperature;
aht.getEvent(&humidity, &temperature);
float bmpTemp = bmp.readTemperature();
float pressure = bmp.readPressure() / 100.0;
Serial.printf("AHT20 - Temp: %.2fC Humidity: %.2f%%\n", temperature.temperature, humidity.relative_humidity);
Serial.printf("BMP280 - Temp: %.2fC Pressure: %.2f hPa\n\n", bmpTemp, pressure);
delay(3000);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
are this code can be use directly connect to sensor? me use esp32