Strange upload behavior R4 Minima, IDE 2.34, Win 10/64

My code works, but only on the second time I click on upload. Why do I have to click upload twice?

//  OLED LMT

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <RTC.h>

#define OLED_WIDTH 128
#define OLED_HEIGHT 32

#define OLED_ADDR   0x3C

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);

int counter = 0;

void setup() // splash screen
{
Serial.begin(9600);

  RTC.begin();
  RTCTime startTime(03, Month::MARCH, 2025, 23, 24, 00,    DayOfWeek::SATURDAY, SaveLight::SAVING_TIME_ACTIVE);
  RTC.setTime(startTime);



  //int counter = 1;
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  
  //display.setCursor(57, 13);
  //display.println(counter);
  //display.setCursor(5, 20);
  //display.println("HEINZIGHT");
  //display.setCursor(25, 45);
  //display.println("Artworks");
  
  delay(1000);
}

//int counter = 1;

void loop() {
RTCTime currentTime;
RTC.getTime(currentTime);

  counter ++;
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 12);
  display.print("LMT");
  display.display();
  display.setTextSize(1);
  display.setCursor(40, 13);
  
  //for (counter = 1; counter < 61; counter++);
  if (counter > 60) counter = 1;
  
  //if (currentTime.getHour() < 10){
     //currentTime.getHour() = "0" + currentTime.getHour();
     display.print(currentTime.getHour());
     display.print(":");
    //}
  //if (currentTime.getMinutes() < 10){
     //currentTime.getMinutes() = "0" + currentTime.getMinutes();
     display.print(currentTime.getMinutes());
     display.print(":");
    //}
  //if (currentTime.getSeconds() < 10){
     //currentTime.getSeconds() = "0" + currentTime.getSeconds();
     display.print(currentTime.getSeconds());
    //}
 /* 
  display.setCursor(40, 25);
  display.print(currentTime.getDayOfMonth());
  display.print("/");
  display.print(currentTime.getMonth());
  display.print("/");
  display.print(currentTime.getYear());
  */
 display.display();

    delay (1000);
 //
 
}

The Hours, Min, Sec print OK, but the time will not. R4 RTC. I was trying to use double digits for numbers less than 10 but I'll settle for single digits.

What is the time that you're referring to? I only see the printing of hours, minutes and seconds. Are you saying that it only prints those numbers after a second upload?

Note that something like below will not compile.

  if (currentTime.getHour() < 10)
  {
    currentTime.getHour() = "0" + currentTime.getHour();
    display.print(currentTime.getHour());
    display.print(":");
  }

Thanks sterretje. Well, I mistakenly said 'time' and not 'date' will not display. But yes, the first upload does nothing. I click upload again and it runs fine. Every-time, it takes 2 clicks.

I know that date portion of the code will not compile, but why? It would help if you posted a solution, as I'm new to this stuff. That's why it's commented out.

Here's the error msg if I remove the commented out block:

C:\Users\16508\Documents\Arduino\OLED_LST_128x32\OLED_LST_128x32.ino: In function 'void loop()':
C:\Users\16508\Documents\Arduino\OLED_LST_128x32\OLED_LST_128x32.ino:77:39: error: no matching function for call to 'Adafruit_SSD1306::print(Month)'
   display.print(currentTime.getMonth());
                                       ^
In file included from C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/ArduinoAPI.h:31:0,
                 from C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/Arduino.h:4,
                 from C:\Users\16508\AppData\Local\arduino\sketches\2EF8EEC2E3EAD90D4E0F6D3AF7E4EB9C\sketch\OLED_LST_128x32.ino.cpp:1:
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:64:12: note: candidate: size_t arduino::Print::print(const arduino::__FlashStringHelper*)
     size_t print(const __FlashStringHelper *);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:64:12: note:   no known conversion for argument 1 from 'Month' to 'const arduino::__FlashStringHelper*'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:65:12: note: candidate: size_t arduino::Print::print(const arduino::String&)
     size_t print(const String &);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:65:12: note:   no known conversion for argument 1 from 'Month' to 'const arduino::String&'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:66:12: note: candidate: size_t arduino::Print::print(const char*)
     size_t print(const char[]);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:66:12: note:   no known conversion for argument 1 from 'Month' to 'const char*'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:67:12: note: candidate: size_t arduino::Print::print(char)
     size_t print(char);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:67:12: note:   no known conversion for argument 1 from 'Month' to 'char'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:68:12: note: candidate: size_t arduino::Print::print(unsigned char, int)
     size_t print(unsigned char, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:68:12: note:   no known conversion for argument 1 from 'Month' to 'unsigned char'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:69:12: note: candidate: size_t arduino::Print::print(int, int)
     size_t print(int, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:69:12: note:   no known conversion for argument 1 from 'Month' to 'int'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:70:12: note: candidate: size_t arduino::Print::print(unsigned int, int)
     size_t print(unsigned int, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:70:12: note:   no known conversion for argument 1 from 'Month' to 'unsigned int'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:71:12: note: candidate: size_t arduino::Print::print(long int, int)
     size_t print(long, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:71:12: note:   no known conversion for argument 1 from 'Month' to 'long int'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:72:12: note: candidate: size_t arduino::Print::print(long unsigned int, int)
     size_t print(unsigned long, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:72:12: note:   no known conversion for argument 1 from 'Month' to 'long unsigned int'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:73:12: note: candidate: size_t arduino::Print::print(long long int, int)
     size_t print(long long, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:73:12: note:   no known conversion for argument 1 from 'Month' to 'long long int'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:74:12: note: candidate: size_t arduino::Print::print(long long unsigned int, int)
     size_t print(unsigned long long, int = DEC);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:74:12: note:   no known conversion for argument 1 from 'Month' to 'long long unsigned int'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:75:12: note: candidate: size_t arduino::Print::print(double, int)
     size_t print(double, int = 2);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:75:12: note:   no known conversion for argument 1 from 'Month' to 'double'
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:76:12: note: candidate: size_t arduino::Print::print(const arduino::Printable&)
     size_t print(const Printable&);
            ^~~~~
C:\Users\16508\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.3.2\cores\arduino/api/Print.h:76:12: note:   no known conversion for argument 1 from 'Month' to 'const arduino::Printable&'

exit status 1

Compilation error: no matching function for call to 'Adafruit_SSD1306::print(Month)'

getMonth() does not return an integer but an enum class member. the print() functions can't handle that.

Month RTCTime::getMonth() const         { return month; }

Month is one of the following:

enum class Month : uint8_t {
    JANUARY = 0,
    FEBRUARY,
    MARCH,
    APRIL,
    MAY,
    JUNE,
    JULY,
    AUGUST,
    SEPTEMBER,
    OCTOBER,
    NOVEMBER,
    DECEMBER
};

The above information can be found in C:\Users\yourUsername\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\libraries\RTC

You can change the problematic line to display.print((int)currentTime.getMonth()); which casts the enum to an integer.

To print leading zeroes the following

  if (currentTime.getHour() < 10)
  {
    currentTime.getHour() = "0" + currentTime.getHour();
    display.print(currentTime.getHour());
    display.print(":");
  }

getHour() etc is a function and you can not assign a value to a function. Further combining text ("0") and numbers does not work.
The simplest way to solve leading zeroes

  if (currentTime.getHour() < 10)
  {
    display.print("0");
  }
  display.print(currentTime.getHour());
  display.print(":");

If you want a leading zero for the month, see the earlier comment about the casting.

I don't have an Uno R4 Minima so I can not test the behaviour. What happens when you close the serial monitor, upload a sketch and next open the serial monitor? Is the behaviour the same?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.