Aide à la programation ds1302=ecran2.4

bonjour à tous et meilleurs voeux,

j'essaie de faire une horloge avec date et heure en partant d'un rtc1302 et un écran tftlcd2.4".
Le problème est que je n'arrive pas à enregistrer la date et l'heure sur ds1302, à chaque fois que je coupe l'alimentation , ça repart à zéro.Texte préformaté
quelqu'un pourrait m'aider SVP?
je joint le code que j'ai pioché sur le net et modifié (assemblé) pour que ce soit compatible avec mon matériel(arduino uno,écran2.4" (ili9341),rtc1302).
Merci et bonne journée

// Example heure et date arduino uno ecran2.4 szdelivry

#include <Adafruit_GFX.h>    // Core graphics library
#include <TftSpfd5408.h> // Hardware-specific library
#include <TouchScreen.h>
#include <DS1302.h>
#include "Wire.h"
#include <TimeLib.h>

DS1302_RAM buffer ;  


DS1302 rtc(10 ,11, 12); // RST, DAT , CLK
Time t;
//#define SET_DATE_TIME_JUST_ONCE

// CONNECTIONS:
// DS1302 CLK/SCLK --> 10
// DS1302 DAT/IO --> 11
// DS1302 RST/CE --> 12
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif



#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


TftSpfd5408 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup() {
  
  rtc.halt(false);
  rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(MERCREDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime(11, 48, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(5, 1, 2022);   // Set the date to August 6th, 2010
  
 
  tft.reset(); 
  tft.begin(0x9341);  //Or replace it with 0x9341, 0x9328 etc..
  tft.setRotation(1); // 
  tft.fillScreen(BLACK); 


    Serial.begin(9600);

    Serial.print("compiled:  ");
    Serial.print(__DATE__);
    Serial.println(__TIME__);

    
    Serial.println();

    Serial.print(rtc.getTimeStr());

    
}

  void loop(){
    Serial.println(rtc.getTimeStr());
  Serial.println(rtc.getDateStr());

    
    
    tft.setCursor(90, 100);
    tft.setTextSize (5);
    tft.setTextColor ( RED , BLACK);
    tft.print(int(t.hour));

    tft.setCursor(190, 100);
    tft.setTextSize (5);
    tft.setTextColor ( BLUE , BLACK);
    tft.print(int(t.min));

    tft.setCursor(150, 100);
    tft.setTextSize (5);
    tft.setTextColor ( GREEN , BLACK);
    tft.print(":");

    

    tft.setCursor(80, 170);
    tft.setTextSize (3);
    tft.setTextColor ( YELLOW , BLACK);
    tft.print(rtc.getDOWStr());

    tft.setCursor(70, 20);
    tft.setTextSize (3);
    tft.setTextColor ( WHITE , BLACK);
    tft.print(rtc.getDateStr()); 

    tft.setCursor(10, 220);
    tft.setTextSize (1);
    tft.setTextColor ( CYAN , BLACK);
    tft.print("Horloge TFT LCD avec DS1302 et ILI9341 IC"); 

    delay (1100);
 
   // recup donnees DS1302
 t = rtc.getTime();
  
 
}

Avec cette série de commandes, en les décommentant et en les modifiant de manière appropriée, vous le définissez à temps.

rtc.halt(false);
  rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(MERCREDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime(11, 48, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(5, 1, 2022);   // Set the date to August 6th, 2010

Certain?.
Faire une autre compilation avec l'ora exacte. IMMÉDIATEMENT , commentez à nouveau les lignes utilisées, recompilez et téléchargez à nouveau sur le tableau. n'a sûrement pas fait ce processus et dans le programme qui est chargé sur la carte ces lignes sont actives et chaque fois que vous redémarrez est auto reprogrammé au moment que vous avez fixé.

bonjour et merci de votre aide,
Je ne suis pas sûr d'avoir bien compris votre solution.
Je dois recompiler avec l'heure réelle et recompiler en décommentant les 3 lignes de paramétrage"heure,date,jour"?
le problème est, que le module ne garde pas l'heure en mémoire.
est il utile d' ajouter : rtc;gettime(); dans le setup avant "rtc.halt(false); ?

void setup() {
  rtc.getTime();
  rtc.halt(false);
  rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(JEUDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime( 7, 15, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate( 6, 1, 2022);   // Set the date

Bonjour,
Quelle librairie as-tu installé pour le DS1302?
Quel module DS1302 utilises-tu (lien vers le produit)?
A priori faire un getTime() avant d'activer la librairie semble inutile. Le plus simple est de se référer aux exemples qui sont installés avec la librairie.
Tu as bien installé une batterie pour assurer la sauvegarde?

Bonjour et merci de vos réponses,
j'ai réussi à trouver. il faut compiler avec les bonnes données(date et heure), ensuite il faut recompiler en mettant // devant

//rtc.halt(false);
  //rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(JEUDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime( 8, 34, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate( 6, 1, 2022);   // Set the date

là pour l'instant cela fonctionne et garde en mémoire. merci a vous de votre intérêt.
bonne journée

voici le programme complet et un peu nettoyé!! Il y a surement plus simple et plus propre. Il ne me reste plus qu'à trouver comment mettre les minutes à l'écran tftlcd correctement.

// Example heure et date arduino uno ecran2.4 szdelivry

#include <Adafruit_GFX.h>    // Core graphics library
#include <TftSpfd5408.h> // Hardware-specific library
#include <TouchScreen.h>
#include <DS1302.h>


DS1302_RAM buffer ;  


DS1302 rtc(12 ,11, 10); // RST, DAT , CLK
Time t;
//#define SET_DATE_TIME_JUST_ONCE

// CONNECTIONS:
// DS1302 CLK/SCLK --> 10
// DS1302 DAT/IO --> 11
// DS1302 RST/CE --> 12
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif



#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


TftSpfd5408 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup() {
  
  //rtc.halt(false);
  //rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(JEUDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime( 8, 34, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate( 6, 1, 2022);   // Set the date 
    Serial.begin(9600);
 
  tft.reset(); 
  tft.begin(0x9341);  //Or replace it with 0x9341, 0x9328 etc..
  tft.setRotation(1); // 
  tft.fillScreen(BLACK); 


    

    
}

  void loop(){

     // Ecriture date sur console serie
  Serial.print("Jour : ");
  Serial.print(t.date, DEC);
  Serial.print(" - Mois : ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" - Annee : ");
  Serial.print(t.year, DEC);
  Serial.println(" -");
  
  // Ecriture heure sur console serie
  Serial.print("C est le ");
  Serial.print(t.dow, DEC);
  Serial.print(" ieme jour de la semaine (avec lundi le premier), et il est ");
  Serial.print(t.hour, DEC);
  Serial.print(" heures, ");
  Serial.print(t.min, DEC);
  Serial.print(" minutes ");
  Serial.print(t.sec, DEC);
  Serial.println(" secondes.");

  // Affichage d un separateur
  Serial.println("------------------------------------------");


     // recup donnees DS1302
    t = rtc.getTime();
   
    //affichage sur lcdtft
    tft.setCursor(90, 100);
    tft.setTextSize (5);
    tft.setTextColor ( RED , BLACK);
    tft.print(int(t.hour));

    tft.setCursor(190, 100);
    tft.setTextSize (5);
    tft.setTextColor ( BLUE , BLACK);
    tft.print(int(t.min));
   
    //éfacer les dizaines
   // tft.setCursor(190, 100);
    //tft.setTextSize (5);
    //tft.setTextColor ( BLACK , BLACK);
    //tft.print(int(t.min));

   // tft.setCursor(190, 100);
   // tft.setTextSize (5);
    //tft.setTextColor ( BLUE , BLACK);
    //tft.print(int(t.min));
    




    tft.setCursor(150, 100);
    tft.setTextSize (5);
    tft.setTextColor ( GREEN , BLACK);
    tft.print(":");

    //tft.setCursor(220, 100);
    //tft.setTextSize (5);
    //tft.setTextColor ( MAGENTA , BLACK);
    //tft.print(int(t.sec));

    //tft.setCursor(190, 100);
    //tft.setTextSize (5);
    //tft.setTextColor ( GREEN , BLACK);
    //tft.print(":");

    tft.setCursor(80, 170);
    tft.setTextSize (3);
    tft.setTextColor ( YELLOW , BLACK);
    tft.print(rtc.getDOWStr());

    tft.setCursor(70, 20);
    tft.setTextSize (3);
    tft.setTextColor ( WHITE , BLACK);
    tft.print(rtc.getDateStr()); 

    tft.setCursor(10, 220);
    tft.setTextSize (1);
    tft.setTextColor ( CYAN , BLACK);
    tft.print("Horloge TFT LCD avec DS1302 et ILI9341 IC"); 

    
    
    delay (1000);
 
  
  
 
}

OUP's ,j'ai crié victoire trop vite. J'ai fait une coupure d'alimentation plus longue . les données étaient perdues?? La Librairie utilisée est "ds1302", j'ai essayé d'abbord les exemples de la librairie. testé des tutos ,cela ne fonctionne pas. Pas de mise en mémoire?? j'ai essayé 3 modules 1302 différents ,piles bonnes...donc je suis quand même perdu..
bonne journée

alors si je mets ce programme de mise à l'heure seul, cela fonctionne très bien.

// Nom script : phm_ds1302_serial_hard 
// Creation : Le 03 06 2016
// Description : Initialisation date/heure puis boucle affichage
// Inspiré du script suivant :
// DS1302_Serial_Hard (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// Les connections suivantes doivent être effectuées DS1302.
// DS1302 patte RST  -> Arduino Digital 12
// DS1302 patte DATA -> Arduino Digital 11
// DS1302 patte CLK  -> Arduino Digital 10

#include <DS1302.h>

// Init DS1302
DS1302 rtc(12, 11, 10);

// Init structure Time-data
Time t;

void setup()
{
  // Positionnement horloge a run-mode et desactive protection en ecriture
  rtc.halt(false);
 //rtc.writeProtect(false);
  
  // Init connection serie
  Serial.begin(9600);

  // Initialisation de l'horloge
  // A mettre a jour avec les bones valeurs pour initialiser l horloge RTC DS1302
  //rtc.setDOW(JEUDI);        // Jour a FRIDAY
  //rtc.setTime(11, 55, 0);    // Heure a 19:10:00 (format sur 24 heure)
  //rtc.setDate(6, 1, 2022);   // Date  au 3 juin 2016
}

void loop()
{
  // recup donnees DS1302
  t = rtc.getTime();
  
  // Ecriture date sur console serie
  Serial.print("Jour : ");
  Serial.print(t.date, DEC);
  Serial.print(" - Mois : ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" - Annee : ");
  Serial.print(t.year, DEC);
  Serial.println(" -");
  
  // Ecriture heure sur console serie
  Serial.print("C est le ");
  Serial.print(t.dow, DEC);
  Serial.print(" ieme jour de la semaine (avec lundi le premier), et il est ");
  Serial.print(t.hour, DEC);
  Serial.print(" heures, ");
  Serial.print(t.min, DEC);
  Serial.print(" minutes ");
  Serial.print(t.sec, DEC);
  Serial.println(" secondes.");

  // Affichage d un separateur
  Serial.println("------------------------------------------");
  
  // Attente d une seconde avant lecture suivante :)
  delay (1000);
}

mais des que je l'intègre dans le programme avec l'écran ,les données ne restent pas en mémoire?? quelqu'un aurait il une idée? SVP

// Example heure et date arduino uno ecran2.4 szdelivry

#include <Adafruit_GFX.h>    // Core graphics library
#include <TftSpfd5408.h> // Hardware-specific library
#include <TouchScreen.h>
#include <DS1302.h>


//DS1302_RAM buffer ;  


DS1302 rtc(12 ,11, 10); // RST, DAT , CLK
Time t;


// CONNECTIONS:
 //DS1302 CLK/SCLK --> 10
// DS1302 DAT/IO --> 11
// DS1302 RST/CE --> 12
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif



#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


TftSpfd5408 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup() {
  
  rtc.halt(false);
  //rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(JEUDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime( 10, 40, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate( 6, 1, 2022);   // Set the date 
    Serial.begin(9600);
 
  tft.reset(); 
  tft.begin(0x9341);  //Or replace it with 0x9341, 0x9328 etc..
  tft.setRotation(1); // 
  tft.fillScreen(BLACK); 


    

    
}

  void loop(){
    
 // recup donnees DS1302
  t = rtc.getTime();
   
     // Ecriture date sur console serie
  Serial.print("Jour : ");
  Serial.print(t.date, DEC);
  Serial.print(" - Mois : ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" - Annee : ");
  Serial.print(t.year, DEC);
  Serial.println(" -");
  
  // Ecriture heure sur console serie
  Serial.print("C est le ");
  Serial.print(t.dow, DEC);
  Serial.print(" ieme jour de la semaine (avec lundi le premier), et il est ");
  Serial.print(t.hour, DEC);
  Serial.print(" heures, ");
  Serial.print(t.min, DEC);
  Serial.print(" minutes ");
  Serial.print(t.sec, DEC);
  Serial.println(" secondes.");

  // Affichage d un separateur
  Serial.println("------------------------------------------");


     
   
    //affichage sur lcdtft
    tft.setCursor(90, 100);
    tft.setTextSize (5);
    tft.setTextColor ( RED , BLACK);
    tft.print(int(t.hour));

    tft.setCursor(190, 100);
    tft.setTextSize (5);
    tft.setTextColor ( BLUE , BLACK);
    tft.print(int(t.min));
   
    //éfacer les dizaines
   // tft.setCursor(190, 100);
    //tft.setTextSize (5);
    //tft.setTextColor ( BLACK , BLACK);
    //tft.print(int(t.min));

   // tft.setCursor(190, 100);
   // tft.setTextSize (5);
    //tft.setTextColor ( BLUE , BLACK);
    //tft.print(int(t.min));
    




    tft.setCursor(150, 100);
    tft.setTextSize (5);
    tft.setTextColor ( GREEN , BLACK);
    tft.print(":");

    //tft.setCursor(220, 100);
    //tft.setTextSize (5);
    //tft.setTextColor ( MAGENTA , BLACK);
    //tft.print(int(t.sec));

    //tft.setCursor(190, 100);
    //tft.setTextSize (5);
    //tft.setTextColor ( GREEN , BLACK);
    //tft.print(":");

    tft.setCursor(80, 170);
    tft.setTextSize (3);
    tft.setTextColor ( YELLOW , BLACK);
    tft.print(rtc.getDOWStr());

    tft.setCursor(70, 20);
    tft.setTextSize (3);
    tft.setTextColor ( WHITE , BLACK);
    tft.print(rtc.getDateStr()); 

    tft.setCursor(10, 220);
    tft.setTextSize (1);
    tft.setTextColor ( CYAN , BLACK);
    tft.print("Horloge TFT LCD avec DS1302 et ILI9341 IC"); 

    
    
    delay (1000);
 
  
  
 
}

Bonne soirée

Essayez d'essayer une autre bibliothèque et il semble qu'il y ait des problèmes avec certains écrans et que vous deviez ajouter une résistance à la ligne i/o pour le résoudre. Regardez ICI

L'écran c'est une interface parallèle ou SPI?

bonjour et merci de vos réponses.
c'est un " Module de bouclier d'affichage tactile LCD TFT 2.4 pouces SPI TFT 240x320 ILI9341 5V compatible avec Arduino UNO ]".
Avec la librairie virtuabotixRTC.h c'est exactement la même chose.
je vais refaire les branchements ,au cas ou???? c'est vraiment un problème de mise en mémoire, peut être l'alimentation de la carte uno?? je suis en usb pour la carte arduino uno avec ecran et alim 5v séparée pour le module ds1302..
bonne journée

Alors , en simplifiant le code ci joint et en mettant l'écran et le module ds1302 sur une alim 5v à part. Cela fonctionne. Je soupçonne une ligne de programme "tft",qui créait le problème.
merci à tous et bonne journée :blush:

``
`

// Example heure et date arduino uno ecran2.4 szdelivry

#include <Adafruit_GFX.h>    // Core graphics library
#include <TftSpfd5408.h> // Hardware-specific library
//#include <TouchScreen.h>
#include <DS1302.h>


DS1302 rtc(12 ,11, 10); // RST, DAT , CLK
Time t;

// CONNECTIONS:
// DS1302 CLK/SCLK --> 10
// DS1302 DAT/IO --> 11
// DS1302 RST/CE --> 12
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
//TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


TftSpfd5408 tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

int oldcolor, currentcolor;

void setup() {
  
  rtc.halt(false);
  //rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(SAMEDI);        // Set Day-of-Week to FRIDAY
  //rtc.setTime( 8, 37, 00);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate( 8, 1, 2022);   // Set the date 
    //Serial.begin(9600);
 
  tft.reset(); 
  tft.begin(0x9341);  //Or replace it with 0x9341, 0x9328 etc..
  tft.setRotation(1); // 
  tft.fillScreen(BLACK); 

   // recup donnees DS1302
    t = rtc.getTime();  
}

  void loop(){

  /*   // Ecriture date sur console serie
  Serial.print("Jour : ");
  Serial.print(t.date, DEC);
  Serial.print(" - Mois : ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" - Annee : ");
  Serial.print(t.year, DEC);
  Serial.println(" -");
  
  // Ecriture heure sur console serie
  Serial.print("C est le ");
  Serial.print(t.dow, DEC);
  Serial.print(" ieme jour de la semaine (avec lundi le premier), et il est ");
  Serial.print(t.hour, DEC);
  Serial.print(" heures, ");
  Serial.print(t.min, DEC);
  Serial.print(" minutes ");
  Serial.print(t.sec, DEC);
  Serial.println(" secondes.");

  // Affichage d un separateur
  Serial.println("------------------------------------------");

*/
     // recup donnees DS1302
    t = rtc.getTime();
   
    //affichage sur lcdtft
    tft.setCursor(90, 100);
    tft.setTextSize (5);
    tft.setTextColor ( RED , BLACK);
    tft.print(int(t.hour));

    tft.setCursor(190, 100);
    tft.setTextSize (5);
    tft.setTextColor ( BLUE , BLACK);
    tft.print(int(t.min));
   
    tft.setCursor(150, 100);
    tft.setTextSize (5);
    tft.setTextColor ( GREEN , BLACK);
    tft.print(":");
 
    tft.setCursor(80, 170);
    tft.setTextSize (3);
    tft.setTextColor ( YELLOW , BLACK);
    tft.print(rtc.getDOWStr());

    tft.setCursor(70, 20);
    tft.setTextSize (3);
    tft.setTextColor ( WHITE , BLACK);
    tft.print(rtc.getDateStr()); 

    tft.setCursor(10, 220);
    tft.setTextSize (1);
    tft.setTextColor ( CYAN , BLACK);
    tft.print("Horloge TFT LCD avec DS1302 et ILI9341 IC"); 

    
    
    delay (1000);
 
  
  
 
}

Si l'écran est en interface SPI, le SPI utilise les pin 10, 11, 12, 13 or les signaux d'interface de la RTC sont les mêmes que ceux de l'écran. Je ne suis pas certain que ce soit une bonne idée.

bonjour ,
non ,les pin 10,11,12 ne sont utilisé que par le rtc 1302. L'écran utilise les pin: de 0 à 9 et A0 à A5.
Le problème persiste en coupant l'alimentation plusieurs heures ,tout compte fait.. c'est à n'y plus rien comprendre , :frowning_face: quelque chose m'échappe...

j'ai adapté ce programme déjà existant(pas de mérite pour moi :flushed:), que je trouve super.
cela ne fonctionne pas ,les données ne restent pas en mémoires de La rtcds1302.

/************************************************************************************************************************
i used an mcufriend tftlcd 2.8 + arduino mega + ds3231 
here is a link for  the   ds 3231 library  and how to use it                                                   /
https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-real-time-clock-module-ds3231-bc90fe                    /
                                                                                                                         /
for the analog clk i use this link for clock without RTC                                                               /
https://basicarduinotutorial.blogspot.com/2017/08/project-v-28-analog-clock-on-tft-lcd-24.html?showComment=1606362619219#/
for the analog clk + rtc i i use this link                                                                                        /
https://www.youtube.com/watch?v=mFB5HJ-a60g                                                                              /

                                                                  / 
                                                                                                                         /
*************************************************************************************************************************/
#include <config.h>

#include <Wire.h>
#include <SPFD5408_Adafruit_TFTLCD.h>
#include <DS1302.h>
DS1302 rtc(12 ,11, 10); // RST, DAT , CLK
Time t;

//TFT  & Arduino pins affectation 
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

//  color
#define TFT_BLACK   0x0000
#define TFT_BLUE    0x001F
#define TFT_RED     0xF800
#define TFT_GREEN   0x07E0
#define TFT_CYAN    0x07FF
#define TFT_MAGENTA 0xF81F
#define TFT_YELLOW  0xFFE0
#define TFT_WHITE   0xFFFF
#define TFT_GREY    0x5AEB
// TFT object 
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
float sx = 0, sy = 1;int scx ,scy ,mx , my , hx , hy ; //saved s ,m , h x, y    
float sdeg , mdeg, hdeg;
int oscx = 90, oscy = 90, omx = 90, omy = 90, ohx = 90, ohy = 90; //saved s , m , h *********
int16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0, x00 = 0, yy00 = 0;                   
uint16_t xpos; // x pos 
boolean initial = 1 ;
char d;
struct  t; 
unsigned  long prev , interval =1000;
uint8_t hh=t.hour , mm= t.min , ss= t.sec ;


void setup(void) {

  //DS1302_RAM();
  //rtc.halt(false);
  //rtc.writeProtect(false);  
  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(DIMANCHE);        // Set Day-of-Week to FRIDAY
  //rtc.setTime( 7,03, 00);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate( 9, 1, 2022);   // Set the date 
  
  Serial.begin (9600);
  
  Wire.begin(); 
  tft.reset();  
  tft.begin(0x9341); 
  tft.setRotation(1);
  tft.setTextColor(TFT_WHITE);// text color
  tft.fillScreen(TFT_BLACK);// background color
  
//face horloge 
  xpos = tft.width() / 2; 
  tft.drawCircle(xpos, 120, 117, TFT_YELLOW);
  tft.fillCircle(xpos, 120, 100, TFT_BLUE); 
  tft.fillCircle(xpos, 120, 92, TFT_BLACK); 
  
 //12 lines
  for (int i = 0; i < 360; i += 30) {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 90 + xpos;
    yy0 = sy * 90 + 120;
    x1 = sx * 100 + xpos;
    yy1 = sy * 100 + 120;
    tft.drawLine(x0, yy0, x1, yy1, TFT_YELLOW);
  }

//60 dot 
  for (int i = 0; i < 360; i += 6) {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 102 + xpos;
    yy0 = sy * 102 + 120;
    x00 = sx * 92 + xpos;
    yy00 = sy * 92 + 120;

// Draw minute markers
    tft.drawPixel(x0, yy0, TFT_GREEN); 

// Draw main quadrant dots
    if (i == 0 || i == 180) tft.fillCircle(x0, yy0, 2, TFT_WHITE); 
    if (i == 90 || i == 270) tft.fillCircle(x0, yy0, 2, TFT_WHITE); 
  }
  tft.fillCircle(xpos, 121, 3, TFT_WHITE);
}

void loop() {  
            // recup donnees DS1302
    t = rtc.getTime();
                       
            unsigned long now = millis ();//local var set to current value of arduino unternal 

//deaw & update screen evry refresh T=100ms
           if ((now - prev> interval))
              {
//determine wether to start a time & refresh display
//computing hand mvt   
    sdeg = (t.sec   * 6/57.29577951);         // 1 Radian = 57.29577951 degrees         
    mdeg = (t.min   * 6/57.29577951); 
    hdeg = (t.hour  * 30 + int (t.min/12)*6);
    hdeg = (hdeg/57.29577951);

    scx = ( xpos+(sin(sdeg)*(117-33)));//sec
    scy = (120-(cos(sdeg)*(117-33)));
    
    mx  = (xpos+(sin(mdeg)*(117-32)));//min
    my=   (120-(cos (mdeg)*(117-32)));    //min hand pos

    hx=   (xpos+(sin (hdeg)*(117-54)));//hr
    hy=   (120- (cos(hdeg)*(117-54)));  //hr hand pos
    
    if (t.sec == 0 || initial) {
      initial = 0;
      // Erase hour and minute hand positions every minute
      tft.drawLine(xpos, 120,omx,omy, TFT_BLACK);
      omx = mx ;
      omy = my ;
     
      tft.drawLine(xpos, 120,ohx,ohy, TFT_BLACK);
      ohx = hx ;
      ohy = hy ;
    }
    // Redraw new hand positions, hour and minute hands not erased here to avoid flicker
    tft.drawLine(xpos, 120, oscx , oscy, TFT_BLACK);
    oscx = scx;
    oscy = scy;
    
    tft.drawLine(xpos, 120, oscx,oscy, TFT_RED);
    tft.drawLine(xpos, 120, omx,omy, TFT_CYAN);
    tft.drawLine(xpos, 120, ohx,ohy,TFT_CYAN);
    tft.fillCircle(xpos, 120, 3, TFT_RED);
    tft.setCursor(xpos-30, 50);
    tft.setTextSize(2);
    tft.print("H-Ah");
 
  // Draw MINI clock face "SECOND"
  tft.drawCircle(xpos, 155, 20, TFT_YELLOW);
  tft.drawCircle(xpos, 155, 18, TFT_BLUE);
  tft.drawCircle(xpos, 155, 17, TFT_CYAN);
  tft.drawCircle(xpos, 155, 16, TFT_CYAN);
  tft.fillRect(xpos-10, 149,22,15,TFT_BLACK); //erase
  if(t.sec<10){tft.setCursor(xpos-10, 149); tft.setTextSize(2);
  tft.print('0'); tft.setCursor(xpos+2, 149);}
  else{
  tft.setCursor(xpos-10, 149);}
  tft.setTextSize(2);
  tft.print(t.sec);
  
  // Draw MINI clock face "Minutes"
  tft.drawCircle(xpos+35, 117, 20, TFT_YELLOW);
  tft.drawCircle(xpos+35, 117, 18, TFT_BLUE);
  tft.drawCircle(xpos+35, 117, 17, TFT_CYAN);
  tft.drawCircle(xpos+35, 117, 16, TFT_CYAN);
  tft.fillRect(xpos+25, 111,22,15,TFT_BLACK); //erase
  if(t.min<10){tft.setCursor(xpos+25, 111); tft.setTextSize(2);
  tft.print('0'); tft.setCursor(xpos+37, 111);}
  else{
  tft.setCursor(xpos+25, 111);}
  tft.println(t.min);
  
  // Draw MINI clock face "Hour"
  tft.drawCircle(xpos-35, 117, 20, TFT_YELLOW);
  tft.drawCircle(xpos-35, 117, 18, TFT_BLUE);
  tft.drawCircle(xpos-35, 117, 17, TFT_CYAN);
  tft.drawCircle(xpos-35, 117, 16, TFT_CYAN);
  tft.fillRect(xpos-45, 111,22,15,TFT_BLACK); //erase
  if(t.hour<10){tft.setCursor(xpos-45, 111); tft.setTextSize(2);
  tft.print('0'); tft.setCursor(xpos-33, 111);}
  else{
  tft.setCursor(xpos-45, 111);}
  tft.setTextSize(2);
  tft.print(t.hour);
  
  if (t.hour>=0 && t.hour<12) d='A'; else {d='P';}
  tft.drawRoundRect(xpos-14,72,29,21,5,TFT_CYAN);
  tft.fillRect(xpos-11, 75,23,15,TFT_BLACK); //erase
  tft.setCursor(xpos-11, 75);
  tft.setTextSize(2);
  tft.print(d);
  tft.println('M');
  prev = now;
  }
}

bonjour,
J'ai vraiment honte :flushed: :frowning_face:....cela fonctionne très bien...il s'agissait de la pile qui ,pourtant ,au voltmetre est encore bonne(2.5volts).. mais bon..le principale est que cela fonctionne maintenant.Merci encore à ceux qui m'ont aidés..
bonne journée

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