How to selectArduino

C3 - DFR0868 - Default RTC?

userHead Jenne45 2024-06-18 19:00:25 106 Views3 Replies

The DFR0868  has an external Crystal RTC included on the dev board. Is this setup for use by default or must it be selected?

A guide to select it would be great ;-)

2024-06-21 18:51:01

Have you checked this wiki? https://wiki.dfrobot.com/SKU_DFR0868_Beetle_ESP32_C3

userHeadPic lia.ifat
2024-06-21 17:34:17

The DFR0868 board, which includes an external Crystal RTC (Real-Time Clock), typically comes with the RTC module pre-installed and ready to use. However, you may need to configure and initialize it in your code to make use of its timekeeping capabilities.

Here’s a step-by-step guide to ensure the RTC is selected and properly used in your project:

### Step 1: Verify the RTC Module Presence

1. **Inspect the Board**: Look for a small square chip near the edge of the DFR0868 board labeled with markings such as "RTC" or "DS3231" (common for RTC modules using the DS3231 chip). This indicates the presence of the RTC module.

2. **Crystal and Battery**: Ensure there is a small crystal oscillator and a backup battery (usually a coin cell battery like CR2032) on the RTC module. These components are essential for accurate timekeeping and maintaining the RTC's time when the main power is off.

### Step 2: Library Installation (if needed)

1. **Download Necessary Libraries**: If you haven’t already, download the necessary RTC library for Arduino. Popular libraries for DS3231 RTC include the "RTClib" and "Adafruit RTClib" libraries.

  - **RTClib**: This library supports DS3231 RTC modules and provides easy-to-use functions for reading and setting time.

    You can install it via the Arduino Library Manager:
    - Open Arduino IDE.
    - Go to **Sketch > Include Library > Manage Libraries...**.
    - Search for "RTClib" and install the library by Adafruit.

  - **Adafruit RTClib**: Another option if you prefer Adafruit’s implementation of the RTC library.

2. **Include the Library**: In your Arduino sketch, include the RTC library at the beginning of your code:

  ```cpp
  #include <RTClib.h>
  ```

### Step 3: Initialize and Use the RTC

1. **Setup Code**: In your Arduino setup function, initialize the RTC and any necessary components (like serial communication for debugging).

  ```cpp
  #include <Wire.h>  // Include Wire library for I2C communication
  #include <RTClib.h>  // Include RTC library

  RTC_DS3231 rtc;  // Create an instance of the RTC

  void setup() {
      Serial.begin(9600);  // Initialize serial communication
      Wire.begin();  // Initialize I2C communication

      if (!rtc.begin()) {
          Serial.println("Couldn't find RTC");
          while (1);
      }

      if (rtc.lostPower()) {
          Serial.println("RTC lost power, let's set the time!");
          // Following line sets the RTC to the date & time this sketch was compiled
          rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
      }

      // Uncomment below line to set the RTC with an explicit date & time
      // rtc.adjust(DateTime(2024, 6, 21, 12, 0, 0));
  }

  void loop() {
      // Example usage: read and print current time
      DateTime now = rtc.now();
      Serial.print(now.year(), DEC);
      Serial.print('/');
      Serial.print(now.month(), DEC);
      Serial.print('/');
      Serial.print(now.day(), DEC);
      Serial.print(' ');
      Serial.print(now.hour(), DEC);
      Serial.print(':');
      Serial.print(now.minute(), DEC);
      Serial.print(':');
      Serial.print(now.second(), DEC);
      Serial.println();

      delay(1000);  // Delay for 1 second
  }
  ```

2. **Function Explanation**:
  - `rtc.begin()`: Initializes communication with the RTC module over the I2C interface.
  - `rtc.lostPower()`: Checks if the RTC lost power (e.g., due to the backup battery being depleted), prompting a reset of the time.
  - `rtc.adjust()`: Sets the initial time on the RTC if it has lost power or needs to be synchronized.

3. **Testing**:
  - Upload the sketch to your DFR0868 board https://www.oemstron.com/.
  - Open the Serial Monitor (set to 9600 baud rate) to view the current time being printed by the sketch.

### Additional Tips:

- Ensure proper wiring of the RTC module to the DFR0868 board if you are using an external RTC module that requires connection.
- Verify the correct I2C address of your RTC module if you encounter communication issues.

By following these steps, you should be able to effectively use the external Crystal RTC included on your DFR0868 development board with your Arduino projects. This setup will enable accurate timekeeping even when the main power is turned off.

userHeadPic JAMES.JACK
Jenne45 wrote:

Excellent! Thanks very much. I did not want to be messing with the RTC_Config files this early in the game! I can suck up the 1uA extra in deep sleep to keep time accurately.

2024-06-21 23:11:23
1 Replies