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();
}