I am using a XIAO. However when I was trying to request time from a DS3231 and display it on a 1.5 inch OLED(SSD1327 128x128) via IIC, the program would stuck after first loop, i.e. the time displayed is always the very moment I upload the prgram. This is very confusing but I cannot test my program on UNO because the memory consumption. Is there any solution? Here is my code:
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
U8G2_SSD1327_EA_W128128_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ U8X8_PIN_NONE);
uint8_t m = 0;
uint8_t h = 0;
void setup(void) {
if (! rtc.begin()) {
abort();
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
u8g2.begin();
}
void loop(void) {
char m_str[3];
char h_str[3];
DateTime now = rtc.now();
strcpy(m_str, u8x8_u8toa(m, 2)); /* convert m to a string with two digits */
strcpy(h_str, u8x8_u8toa(h, 2)); /* convert m to a string with two digits */
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_logisoso42_tn);
u8g2.drawStr(0,50,h_str);
u8g2.drawStr(55,50,":");
u8g2.drawStr(70,50,m_str);
} while ( u8g2.nextPage() );
delay(1000);
m++;
if ( m == 60 )
m = 0;
}