Skip to content

Instantly share code, notes, and snippets.

@ariesmcrae
Created September 4, 2022 10:11
Show Gist options
  • Save ariesmcrae/cf03f8e457e62923991cf7230deda1da to your computer and use it in GitHub Desktop.
Save ariesmcrae/cf03f8e457e62923991cf7230deda1da to your computer and use it in GitHub Desktop.
Arduino IDE: M5Stack Core 2 with ENVIII Temperature / Humidity sensor and battery level
#include <M5Core2.h>
#include <M5_ENV.h>
SHT3X sht30;
float temperature = 0.0;
float humidity = 0.0;
void setup() {
M5.begin(); // Init M5Core2.
M5.lcd.setTextSize(3);
Wire.begin(); // Wire init, adding the I2C bus.
M5.lcd.println(F("Master Bed\r\n"));
}
void loop() {
if (sht30.get() == 0) { // Obtain the data of shT30
temperature = sht30.cTemp; // Store the temperature obtained from shT30.
humidity = sht30.humidity; // Store the humidity obtained from the SHT30.
} else {
temperature = 0;
humidity = 0;
}
M5.lcd.fillRect(0, 20, 100, 60, BLACK); // Fill the screen with black (to clear the screen).
M5.lcd.setCursor(0, 20);
float batVoltage = M5.Axp.GetBatVoltage();
float batPercentage = ( batVoltage < 3.2 ) ? 0 : ( batVoltage - 3.2 ) * 100;
M5.Lcd.printf("\r\n\r\nTemp: %2.1f C \r\n\r\nHumidity: %2.0f %% \r\n\r\nPower: %2.0f %%", temperature, humidity, batPercentage);
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment