RTC.h: No such file or directory' Error

// include the library code:
#include <LiquidCrystal.h>
#include <RTC.h>

// time variables
int year;
int month;
int day;
int hour;
int minutes;
int seconds;

// LED pins
const int led1 = 6;
const int led2 = 7;
const int led3 = 8;

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // LED pin modes
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
  digitalWrite(led3,LOW);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // initialize the RTC and set the current date and time
  RTC.begin();
  RTCTime startTime(28, Month::MARCH, 2024, 9, 13, 50, DayOfWeek::THURSDAY, SaveLight::SAVING_TIME_ACTIVE);
  RTC.setTime(startTime);
}

void loop() {
  // get the current time from RTC
  RTCTime currentTime;
  RTC.getTime(currentTime);
 
  // store current time variables
  year = currentTime.getYear();
  month = Month2int(currentTime.getMonth());
  day = currentTime.getDayOfMonth();
  hour = currentTime.getHour();
  minutes = currentTime.getMinutes();
  seconds = currentTime.getSeconds();

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  // print month/day/year
  // add leading spaces if month or day are less than 10 to keep spacing consistent
  // (always use 2 characters for month and day)
  if(month<10){
    lcd.print(" ");
  }
  lcd.print(month);
  lcd.print("/");
  if(day<10){
    lcd.print(" ");
  }
  lcd.print(day);
  lcd.print("/");
  lcd.print(year);

  // print time in hh:mm:ss format
  // add leading zeroes if minutes or seconds are less than ten to keep spacing consistent
  lcd.setCursor(0, 1);
  if(hour<10){
    lcd.print(" ");
  }
  lcd.print(hour);
  lcd.print(":");
  if(minutes<10){
    lcd.print("0");
  }
  lcd.print(minutes);
  lcd.print(":");
  if(seconds<10){
    lcd.print("0");
  }
  lcd.print(seconds);

  // control LEDs based on time
  if(seconds == 0){
    digitalWrite(led1,HIGH);
    digitalWrite(led2,LOW);
    digitalWrite(led3,LOW);
  }
  if(seconds == 20){
    digitalWrite(led1,LOW);
    digitalWrite(led2,HIGH);
    digitalWrite(led3,LOW);
  }
  if(seconds == 40){
    digitalWrite(led1,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led3,HIGH);
  }

 
}

Good afternoon,
I am new to Arduino and was trying to compile this code i got in one of the forums. It is giving a 'RTC.h: No such file or directory' error. I have reinstalled RTC libraries but the code is failing to run and compile. Kindly assist

Please post the full error message copied from the IDE using the button provided for the purpose. When posting the error please use code tags to make it easier to read and manage

What is the full path to the RTC,h file on your PC and how did you install the library ?

you need to find the right library for this

are you on a UNO R4 ?

Using Arduino UNO R4 Minima :

WARNING: library Servo claims to run on avr, megaavr, sam, samd, nrf52, stm32f4, mbed, mbed_nano, mbed_portenta, mbed_rp2040 architecture(s) and may be incompatible with your current board which runs on renesas_uno architecture(s).

In file included from C:\Users\ejack\Downloads\pill_dispenser_demonstration-1\pill_dispenser_demonstration-1.ino:13:0:

C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:77:2: error: #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."

#error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."

^~~~~

exit status 1

Error compiling for board Arduino UNO R4 Minima.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The RTC library is built in. Did you select the right board?

Something very strange is happening here, I think. Either your installation is corrupted, or the information you've given us is incorrect.

  1. You're getting an error that the Servo library doesn't exist. Fair enough; install it. But nowhere in the sketch you showed in post #1 is Servo.h included.
  2. Your topic title is "RTC.h: No such file or directory' error". Yet nowhere in your error messages do I see that error.
  3. Your sketch included in post #1 compiles just fine for me with an R4 Minima selected.
arduino-cli compile -b arduino:renesas_uno:minima --warnings all --output-dir ~/tmp --no-color (in directory: /home/me/Documents/sketchbook/Uno_R4_Minima/test)
Sketch uses 57208 bytes (21%) of program storage space. Maximum is 262144 bytes.
Global variables use 4684 bytes (14%) of dynamic memory, leaving 28084 bytes for local variables. Maximum is 32768 bytes.
Used library  Version Path
LiquidCrystal 1.0.7   /home/me/Documents/sketchbook/libraries/LiquidCrystal
RTC           1.0     /home/me/.arduino15/packages/arduino/hardware/renesas_uno/1.1.0/libraries/RTC
Used platform       Version Path
arduino:renesas_uno 1.1.0   /home/me/.arduino15/packages/arduino/hardware/renesas_uno/1.1.0
Compilation finished successfully.

There are Servo libraries in some cores (though, notably, not in any of the Arduino cores I have installed, including the renesas_uno core). The non core Servo library is likely what the OP has installed. That's what they'd need to run servos on an R4 (though they'd also need to manually install the Github source as the fix to make servos work properly on the R4 still isn't in the released version, last I looked). However, where this applies to the OP's posted code is entirely unclear.

That turns out not to be the case. See below for the renesas_uno core. No Servo library.

See below for the the AVR core. No Servo library.

I stand ready to be corrected.

I am aware it's the error that the TO quoted. I simply stated that it has no... oh forget it.

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