🛠 Simple Connected Weather Station with ToughC5

M5Stack ToughC5 Weatherproof IoT Dev Kit (ESP32-C5) · debutant · Apprenez à afficher l'heure et la température sur l'écran tactile du ToughC5 en utilisant le RTC intégré et un capteur externe.

Objectives

This tutorial aims to create a standalone desktop weather station. You will learn to initialize the ILI9342C touchscreen, read the Real-Time Clock (RTC RX8130CE) to display the time, and simulate or read a temperature for display. This is an ideal introduction to user interfaces and power management on the M5Stack ToughC5.

Required Hardware

Steps

  1. Environment Setup: Open Arduino IDE. Go to Tools > Manage Libraries. Search for and install M5Unified and M5GFX. These libraries greatly simplify screen and touch control.
  1. Port Selection: Connect the ToughC5 via USB. In Tools > Port, select the corresponding serial port.
  1. Base Code: Create a new sketch. Copy the following code which initializes the display and RTC:
#include <M5Unified.h>

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  M5.Display.setTextSize(2);
  M5.Display.setTextColor(WHITE, BLACK);
  M5.Display.fillScreen(BLACK);
  M5.Display.setCursor(10, 10);
  M5.Display.println("ToughC5 IoT");
}

void loop() {
  M5.update();
  // Get RTC time
  auto rtc = M5.Rtc.getDateTime();
  M5.Display.fillRect(0, 50, 320, 100, BLACK);
  M5.Display.setCursor(10, 60);
  M5.Display.printf("Time: %02d:%02d:%02d\\n", rtc.hour, rtc.minute, rtc.second);
  M5.Display.setCursor(10, 90);
  M5.Display.println("Temp: 22.5 C"); // Simulation
  delay(1000);
}
  1. Upload: Click the 'Upload' button. Wait for compilation and flashing to finish.
  1. Touch Test: Once the device starts, the screen displays the time. You can add code in loop() to react to touches with M5.Touch.getDetail().

Verification

The screen should light up with a black background. The text "ToughC5 IoT" appears at the top. Below it, the time should increment every second, proving the RX8130CE RTC is working. The simulated temperature remains fixed. If the screen is off, check that the USB cable provides 5V.

Further Reading

Replace the simulated temperature with a real reading via a DS18B20 sensor connected to the HY2.0-4P ports (GPIO). Configure the passive buzzer to emit a beep on each hour change.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials