The CH32V203 QT Py has Arduino support, which means that you can use the Arduino libraries that you know and love for your projects. You can either compile the code with the Arduino IDE after installing the necessary libraries or upload the precompiled .BIN file with the WCHISP tool.
Arduino IDE - Install the Libraries
You can install the libraries for this project using the Library Manager in the Arduino IDE.
Click the Manage Libraries... menu item, search for Adafruit EPD, and select the Adafruit EPD library:
If asked about dependencies, click "Install all".
Then install the RTC library. Click the Manage Libraries... menu item again, search for RTClib, and select the RTClib library fork by Adafruit:
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Arduino.h> #include <SPI.h> #include "Adafruit_TinyUSB.h" #include "Adafruit_ThinkInk.h" #include "RTClib.h" #include <Wire.h> #include <Fonts/FreeSans24pt7b.h> #include <Fonts/FreeSans18pt7b.h> #include <Fonts/FreeSans12pt7b.h> #define EPD_DC PA3 #define EPD_CS PA2 #define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay) #define SRAM_CS PA1 #define EPD_RESET -1 // can set to -1 and share with microcontroller Reset! #define EPD_SPI &SPI // primary SPI // 1.54" Monochrome displays with 200x200 pixels and SSD1681 chipset ThinkInk_154_Mono_D67 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY, EPD_SPI); RTC_DS3231 rtc; char daysOfTheWeek[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; char monthsOfYear[13][4] = {"NULL", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; bool start = true; String lastTimeStr = "00:00"; void setup() { Serial.begin(115200); /*while (!Serial) { delay(10); }*/ Serial.println("eInk Calendar & Clock with CH32V203"); SPI.begin(); Serial.println("SPI started"); pinMode(EPD_CS, OUTPUT); digitalWrite(EPD_CS, HIGH); Wire.begin(); Serial.println("Wire started"); Serial.println("starting display, might take a bit.."); display.begin(THINKINK_MONO); Serial.println("display started"); while (! rtc.begin()) { Serial.println("Couldn't find RTC"); delay(10); } } void loop() { Serial.println("we did it!"); DateTime now = rtc.now(); Serial.println("read rtc"); char timeChar[6]; sprintf(timeChar, "%02d:%02d", now.hour(), now.minute()); String timeStr = String(timeChar); String monthStr = monthsOfYear[now.month()]; String dateStr = String(now.day()); String yearStr = String(now.year()); String dayOfWeekStr = daysOfTheWeek[now.dayOfTheWeek()]; Serial.println(timeStr); int16_t x1, y1; uint16_t w, h; if (lastTimeStr != timeStr) { display.clearBuffer(); display.fillRect(0, 0, 200, 60, EPD_BLACK); display.drawRect(0, 0, 200, 170, EPD_BLACK); display.setTextColor(EPD_WHITE); display.setFont(&FreeSans24pt7b); display.getTextBounds(dayOfWeekStr.c_str(), 0, 0, &x1, &y1, &w, &h); display.setCursor((200 - w) / 2, (60 - h) / 2 + h); display.println(dayOfWeekStr); display.setTextColor(EPD_BLACK); display.getTextBounds(dateStr.c_str(), 0, 0, &x1, &y1, &w, &h); display.setCursor((200 - w) / 2, (170 - h) / 2 + h + 28); display.println(dateStr); display.setFont(&FreeSans18pt7b); display.getTextBounds(monthStr.c_str(), 0, 0, &x1, &y1, &w, &h); display.setCursor((200 - w) / 2, (60 + h) + 3); display.println(monthStr); display.getTextBounds(yearStr.c_str(), 0, 0, &x1, &y1, &w, &h); display.setCursor((200 - w) / 2, (170 - h) - 5 + h); display.println(yearStr); display.setFont(&FreeSans12pt7b); display.getTextBounds(timeStr.c_str(), 0, 0, &x1, &y1, &w, &h); display.setCursor((200 - w) / 2, (200 - h) - 5 + h); display.println(timeStr); display.display(); lastTimeStr = timeStr; } delay(30000); }
Upload the sketch to your board. The QT Py will initialize the RTC and eInk display. In the loop, the RTC will be read and the eInk display will be updated when the time has changed.
If you need to set the time on your RTC breakout, check out the DS3231 Learn Guide.
BIN File
If you prefer to skip the Arduino IDE, you can upload the precompiled .BIN file to your board with the WCHISP command line tool. The .BIN file is available for download below. If you aren't familiar with the WCHISP tool, there is a page available in the CH32V203 Learn Guide.
Text editor powered by tinymce.