This project used a Seeed Studio XIAO ESP32-C3 with the XIAO Expansion Base v1.1.
The built-in OLED display was used to show:
Current date and time
Room temperature from a PCT2075 sensor
The project demonstrates use of I2C communication, sensor reading, and OLED display output.
System Connections (Temperature Sensor PCT2075)
VCC -> 3V3
GND -> GND
SDA -> I1C SDA4
SCL -> I1C SCL5
GPIO6 = SDA
GPIO7 = SCL
Arduino Ide
Libraries
Wire.h
Adafruit_GFX
Adafruit_SSD1306
PCT2075
Feature 1: Date and Time Display
The OLED screen was programmed to show date and time in real time.
Functions:
Real - time clock display
Finnish timezone support
Automatic updates every second
//Connecting libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <time.h>
//Define screen size
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
//Defining screen
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
//Defining WiFi SSIF and password
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
//Website from where time will be imported
const char* ntpServer = "pool.ntp.org";
void setup() {
Serial.begin(115200);
//Connecting to WiFi
WiFi.begin(ssid);
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED){
delay(300);
Serial.print(".");
}
Serial.println("\nWiFi connected!");
//Setting time to Finnish timezone
configTime(0, 0, ntpServer);
setenv("TZ", "EET-2EEST,M3.5.0/3,M10.5.0/4", 1);
tzset();
//Connecting to screen
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)){
Serial.println("Time fail");
return;
}
//Getting time from NTP Server
char timeStr[16];
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo);
//Getting datefrom NTP Server
char dateStr[20];
strftime(dateStr, sizeof(dateStr), "%d.%m.%Y", &timeinfo);
//Writting time on display
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(15, 20);
display.print(timeStr);
//Writing date on display
display.setTextSize(1);
display.setCursor(30, 45);
display.print(dateStr);
display.display();
//Reloading every 10 milliseconds
delay(100);
}
Feature 2: Temperature display
The PCT2075 sensor measures room temperature and sends it to ESP32-C3.
Functions:
Measuring the room temperature
Reloading every 1 second
//Connecting the libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <PCT2075.h>
//Defininf screen size
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
//Defining display and sensor
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
PCT2075 sensor(0x37, &Wire);
void setup() {
Serial.begin(115200);
//Wire 6 and 7 = SDA and SCL
Wire.begin(6,7);
delay(200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED fail");
while(1);
}
//Starting the display
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(20,25);
display.println("Starting...");
display.display();
delay(1000);
if(!sensor.begin()) {
Serial.println("Sensor fail");
display.clearDisplay();
display.setCursor(0,20);
display.println("Sensor Fail");
display.display();
while(1);
}
Serial.println("Ready");
}
void loop() {
//Getting the temperature
float t = sensor.getTemperature();
display.clearDisplay();
//Printing temperature
display.setTextSize(1);
display.setCursor(28,0);
display.println("ROOM TEMP");
display.setTextSize(3);
display.setCursor(12,28);
display.print(t,1);
display.print("C");
display.display();
//Waiting for 1 second
delay(1000);
}
Troubleshooting Process
During development, several problems appered and were solved:
Sensor not found
After research of the documentation of ESP32-C3, I found right addressed:
OLED = 0x3C
RTC = 0x51
PCT2075 = 0x37
Display blank
Solved by initializing display before sensor
Skills Learned
This project helped develop skills in:
Microcontroller programming
I1C communication
OLED display control
Sensor integration
Debugging hardware connections
Arduino programming
Future improvements
Possible future upgrades:
Show WiFi weather data
Add graphs for temperature history
Web dashboard with live data
Conclusion
The project was successful.
The XIAO ESP32-C3 and Expansion Base can be used to build smart embedded systems that show live data on a screen.
This project combines electronics, programming, and sensor technology into a practical real-world solution.