[resolu] horloge rtc et lcd

Il m arrive un truc etrange, j essaye d afficher l heure sur un lcd et ca foire ...
J arrive a afficher ce que je veux sur un lcd (txt, decimal)
J arrive a afficher l heure de mon shield rtc ds1307 dans la console
Mais si je combine les deux, ca marche pas, meme si j essaye de n afficher que les secondes, j ai 2 caracteres bizarres, du genre chinois ou japonnais
Il y a des conflits entre la lib rtc et lcd ?

Ps: je teste mon module rtc sur un leonardo, car sur mon mega avec un tft, le sketch jarduino recupere pas l heure

Mon module rtc est foireux ?

Peux-tu nous dire quel matériel tu utilise et comment tout ça est câblé? Voir même le code? Par expérience, caractères bizarres sur LCD=mauvais ordre de branchement.

Bonjour,

Sans les deux codes fonctionnels et ton code final + détails du branchement ont ne peut pas t'aider ...

Oui donne nous ton code qu'on puisse t'aider !

:slight_smile:

Sans code difficile de t'aider...

Matériel :
LCD Serial 16x2 http://www.evola.fr/product_info.php/lcd-16x2-liaison-serie-grove-p-238
Horloge RTC DS1307 http://www.evola.fr/product_info.php/horloge-temps-reel-ds1307-p-156

Les branchements c'est ceux des tutos ...

1er test , branchement :
LCD Res.Var. 10K Leonardo
pin 1 GND pin milieu -
pin 2 VCC pin droite -
pin 3 V0 pin milieu -
pin 4 RS - pin 13
pin 5 R/W pin gauche
pin 6 E - pin 12
pin 7 - -
pin 8 - -
pin 9 - -
pin 10 - -
pin 11 D4 - pin 5
pin 12 D5 - pin 4
pin 13 D6 - pin 3
pin 14 D7 - pin 2
pin 15 - -
pin 16 - -

  • pin droite 5V
    pin gauche GND
    code :
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

=> ca marche nickel

2ième test (en laissant branché le LCD) :

RTC Leonardo
SCL SCL
SDA SDA
VCC 5V
GND GND

code:

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop () {
    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(3000);
}

=> ca marche nickel

3ième test on melange les 2 codes :

code:

#include <LiquidCrystal.h>

  #include <Wire.h>
  #include "RTClib.h"

  RTC_DS1307 RTC;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  
    Wire.begin();
    RTC.begin();
    if (! RTC.isrunning()) {
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis()/1000);
  
    DateTime now = RTC.now();
    lcd.print("sec=");
    lcd.print(now.second());
}

=> j'ai plus les milisec sur la 2ième ligne du LCD et j'ai des caractères japonnais à droite ...

Matériel :
LCD Serial 16x2 http://www.evola.fr/product_info.php/lcd-16x2-liaison-serie-grove-p-238
Horloge RTC DS1307 http://www.evola.fr/product_info.php/horloge-temps-reel-ds1307-p-156

Les branchements c'est ceux des tutos ...

1er test , branchement :
LCD Res.Var. 10K Leonardo
pin 1 GND pin milieu -
pin 2 VCC pin droite -
pin 3 V0 pin milieu -
pin 4 RS - pin 13
pin 5 R/W pin gauche
pin 6 E - pin 12
pin 7 - -
pin 8 - -
pin 9 - -
pin 10 - -
pin 11 D4 - pin 5
pin 12 D5 - pin 4
pin 13 D6 - pin 3
pin 14 D7 - pin 2
pin 15 - -
pin 16 - -

  • pin droite 5V
    pin gauche GND
    code :
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

=> ca marche nickel

2ième test (en laissant branché le LCD) :

RTC Leonardo
SCL SCL
SDA SDA
VCC 5V
GND GND

code:

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop () {
    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(3000);
}

=> ca marche nickel

3ième test on melange les 2 codes :

code:

#include <LiquidCrystal.h>

  #include <Wire.h>
  #include "RTClib.h"

  RTC_DS1307 RTC;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  
    Wire.begin();
    RTC.begin();
    if (! RTC.isrunning()) {
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis()/1000);
  
    DateTime now = RTC.now();
    lcd.print("sec=");
    lcd.print(now.second());
}

=> j'ai plus les milisec sur la 2ième ligne du LCD et j'ai des caractères japonnais à droite ...

Matériel :
LCD Serial 16x2 http://www.evola.fr/product_info.php/lcd-16x2-liaison-serie-grove-p-238
Horloge RTC DS1307 http://www.evola.fr/product_info.php/horloge-temps-reel-ds1307-p-156

Les branchements c'est ceux des tutos ...

1er test , branchement :
LCD Res.Var. 10K Leonardo
pin 1 GND pin milieu -
pin 2 VCC pin droite -
pin 3 V0 pin milieu -
pin 4 RS - pin 13
pin 5 R/W pin gauche
pin 6 E - pin 12
pin 7 - -
pin 8 - -
pin 9 - -
pin 10 - -
pin 11 D4 - pin 5
pin 12 D5 - pin 4
pin 13 D6 - pin 3
pin 14 D7 - pin 2
pin 15 - -
pin 16 - -

  • pin droite 5V
    pin gauche GND
    code :
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

=> ca marche nickel

2ième test (en laissant branché le LCD) :

RTC Leonardo
SCL SCL
SDA SDA
VCC 5V
GND GND

code:

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop () {
    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(3000);
}

=> ca marche nickel

3ième test on melange les 2 codes :

code:

#include <LiquidCrystal.h>

  #include <Wire.h>
  #include "RTClib.h"

  RTC_DS1307 RTC;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  
    Wire.begin();
    RTC.begin();
    if (! RTC.isrunning()) {
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis()/1000);
  
    DateTime now = RTC.now();
    lcd.print("sec=");
    lcd.print(now.second());
}

=> j'ai plus les milisec sur la 2ième ligne du LCD et j'ai des caractères japonnais à droite ...

désolé pour le muti post, ça lagggggggggg grave et je n arrive pas à effacer les doublons $)

Bonjour,

Essaye ça :

lcd.print("sec=");
lcd.print(now.second(), DEC);
delay(1000);

J ai compris ma boulette ... une histoire de branchement !
En fait sur le Leonardo, il ne faut pas utiliser SCL/SDA s'il y a le LCD sur les pin 2,3,4,5 car la lib RTC utilise les pin 2 & 3 !

Si je décale le LCD en 4,5,6,7 et que je branche le module RTC en 2,3, ca marche nickel !

Le bon code pour ceux qui veulent essayer :

#include <LiquidCrystal.h>

  #include <Wire.h>
  #include "RTClib.h"

  RTC_DS1307 RTC;

// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  
    Wire.begin();
    RTC.begin();
    if (! RTC.isrunning()) {
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis()/1000);
  
    DateTime now = RTC.now();
    lcd.print(now.year()-2000, DEC);
    lcd.print('/');
    lcd.print(now.month(), DEC);
    lcd.print('/');
    lcd.print(now.day(), DEC);
    lcd.print(' ');
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    lcd.print(now.second(), DEC);
    lcd.println();
}

yann44:
J ai compris ma boulette ... une histoire de branchement !
En fait sur le Leonardo, il ne faut pas utiliser SCL/SDA s'il y a le LCD sur les pin 2,3,4,5 car la lib RTC utilise les pin 2 & 3 !

J'avais complétement oublié cette histoire de broches différemment mappé sur la Leonardo ...
Le principal c'est que ça marche maintenant :grin: