🛠 Simple Connected Weather Station with ToughC5
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
- M5Stack ToughC5 IoT Dev Kit
- USB Type-C cable for power and flashing
- Computer with Arduino IDE installed
- M5GFX and M5Unified libraries (via Library Manager)
Steps
- Environment Setup: Open Arduino IDE. Go to
Tools>Manage Libraries. Search for and installM5UnifiedandM5GFX. These libraries greatly simplify screen and touch control.
- Port Selection: Connect the ToughC5 via USB. In
Tools>Port, select the corresponding serial port.
- 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);
}
- Upload: Click the 'Upload' button. Wait for compilation and flashing to finish.
- Touch Test: Once the device starts, the screen displays the time. You can add code in
loop()to react to touches withM5.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
toughc5_gpio_button_buzzer.inoC++ (Arduino)toughc5_wifi6_scanner.inoC++ (Arduino)toughc5_rtc_battery_log.inoC++ (Arduino)toughc5_ili9342c_touch_ui.inoC++ (Arduino)toughc5_rs485_modbus_master.inoC++ (Arduino)toughc5-rs485-modbus-master.inoArduino C++