TEENSY 4.1 RTC battery

Boris_25

Member
Hello every one,
I have a project needed IO, RTC and SD to store data, so the TENNSY 4.1 is for me the choice.
I need to use RTC and have RTC reference, so I weld wires to connect a CR2032, like descibe on the documentation, but when I disconnect the power and restart again, the RTC restart at 01/01/1970 00:00:00.

Montage_CR2032_w.jpg

How to test the good use of the bat?
Regards.
 
I've had success using a 0.5F capacitor tied to VBAT. I charge the capacitor using a schottky diode tied to the Teensy's 3.3v pin. The capacitor keeps the RTC running for over a day without power.
I've not tried a coin cell.
 
Thanks,
So I tried to use an external power supply 3.3V instead of CR2032. I unplug the usb cable and plug it again, and nothing change, the RTC restart from zero.
Is there a way to check the good operationg of external supply?
 
I assume that you are calling SetSyncProvider(getTeensy3Time) to synchronize the time functions with the RTC. I have to make that assumption because you haven't followed the rule about posting source code with your question.
 
Ok here is what I do :
First I use this code to set date and time :

Code:
#include <TimeLib.h>

void setup() {
  setTime(19, 36, 00, 15, 02, 2023);

}

void loop() {

}

Then I put this code to show date and time on OLED :


Code:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <Wire.h>
#include <TimeLib.h>
#define OLED_RESET 4
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &Wire, OLED_RESET);
String Jour = "";
String Mois = "";
String Annee = "";
String heure = "";
String Minute = "";
String seconde = "";


void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Adressierung beachten, hier 0x3C!
}

void loop() {
  if (day() < 10) { //Jour
    Jour = "0";
    Jour += day();
  }
  else {
    Jour = String(day());
  }
  if (month() < 10) { //Mois
    Mois = "0";
    Mois += month();
  }
  else {
    Mois = String(month());
  }
  Annee = String(year()); //Année
  String heure = hour();
    if (hour() < 10) {
    heure = "0";
    heure += hour();
  }
  else {
    heure = String(hour());
  }
  if (minute() < 10) {
    Minute = "0";
    Minute += minute();
  }    
  else {
    Minute = String(minute());
  }
  if (second() < 10) {
    seconde = "0";
    seconde += second();
  }
  else {
    seconde = String(second());
  }
  display.clearDisplay(); //Ecran 128 x 64 ! 42-1-42-1-42 ! 21-1-21-21
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(5, 1);
  display.println(Jour);
  display.setCursor(30, 1);
  display.println("/");
  display.setCursor(44, 1);
  display.println(Mois);
  display.setCursor(69, 1);
  display.println("/");
  display.setCursor(80, 1);
  display.println(Annee);
  display.setTextSize(2);
  display.setCursor(5, 30);
  display.println(heure);
  display.setCursor(35, 30);
  display.println(":");
  display.setCursor(50, 30);
  display.println(Minute);
  display.setCursor(80, 30);
  display.println(":");
  display.setCursor(95, 30);
  display.println(seconde);
  display.display();
  delay(1000);
}

And on the screen I have 01/01/1970 00:00:01 and count every second.
 
I think you need to add:

SetSyncProvider(getTeensy3Time);

to the setup() functions in your code. I think that call is needed to synchronize the time library functions with the hardware real-time clock.

(Interesting mix of French and German in the code! Are you in Belgium or Alsace-Lorraine?)
 
Thanks for your help.
I will try this as soon as possible.

I am French and live in France, Doubs (25). If there's German in this code, it is because I copy code from German OLED provider and don't translate comment!
 
Ref post above see: ...\hardware\teensy\avr\libraries\Time\examples\TimeTeensy3\TimeTeensy3.ino

Code:
#include <TimeLib.h>

void setup()  {
  // set the Time library to use Teensy 3.0's RTC to keep time
  setSyncProvider(getTeensy3Time);

// ...
 
Thank for your help.
I tried to test your code above, but it doesn't work.
So I tested the code below which is working but I'm not sure that is academic.

Code:
#include <TimeLib.h>
unsigned long MAJtemps;


void setup() {
  MAJtemps = Teensy3Clock.get();
  setTime(MAJtemps);
}
 
Back
Top