pdf-icon

Arduino Quick Start

2. Devices & Examples

Paper SHT30 Temperature and Humidity Sensor

API references and example programs related to the Paper SHT30 temperature and humidity sensor.

Example Program

Compilation Requirements

  • M5Stack Board Manager version >= 2.1.4
  • Board selection = M5Paper
  • M5Unified library version >= 0.2.5
  • M5GFX library version >= 0.2.7
  • M5Unit-ENV library version >= 1.2.1
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include <M5Unified.h>
#include <M5GFX.h>
#include <M5UnitENV.h>
// #include <M5UnitUnifiedENV.h>

float temp, humi;
SHT3X sht3x;

void setup() {
  M5.begin();
  M5.Display.setRotation(0);
  M5.Display.setFont(&fonts::FreeMonoBold24pt7b);
  M5.Display.setEpdMode(epd_fast);  // epd_quality, epd_text, epd_fast, epd_fastest

  Serial.begin(115200);
  Serial.println("SHT30 Sensor");

  M5.Display.clear();
  M5.Display.setCursor(80, 100);
  M5.Display.print("SHT30 Sensor");

  if (!sht3x.begin(&Wire, SHT3X_I2C_ADDR, 21, 22, 400000U)) {
    Serial.println("SHT30 not found");
    M5.Display.setCursor(60, 300);
    M5.Display.print("SHT30 not found");
    while (1) delay(1);
  }
}

void loop() {
  M5.update();
  sht3x.update();

  temp = sht3x.cTemp;
  humi = sht3x.humidity;

  Serial.printf("Temp:%6.2f C", temp);
  Serial.println();
  Serial.printf("Humi:%6.2f %%", humi);
  Serial.println("\n");

  M5.Display.setCursor(60, 300);
  M5.Display.printf("Temp:%6.2f C", temp);
  M5.Display.setCursor(60, 360);
  M5.Display.printf("Humi:%6.2f %%", humi);

  delay(800);

  // refresh the whole display every 60 seconds
  int refreshTimer = millis() % 60000;
  if (refreshTimer >= 58200 && refreshTimer < 60000) {
    M5.Display.clear();
    M5.Display.setCursor(80, 100);
    M5.Display.print("SHT30 Sensor");
    Serial.println("\nscreen refreshed\n");
  }
}

This program will display the real-time temperature (in Celsius ℃) and relative humidity (%) detected by the sensor on the screen.

API

The Paper SHT30 temperature and humidity sensor section uses the SHT3X class from the M5Unit-ENV library. For more related APIs, refer to the library source file on GitHub:

On This Page