Problems with RTC DS3231 and LCD

I’m using an arduino UNO, LCD 16x2, RFID RFC-522 and RTC DS3231.
After all tests in protoboard, everything works fine.

But on the real board, when I put a RTC DS3231 + LCD code, the lcd doesn’t work.
That is the only problem on my board.

A basic code of RFID + LCD = works.
A basic code of RTC DS3231 + LCD = LCD doesn’t turn on.

(The both are two very BASIC codes, only to see if the RTC or RFID works.)

After several tests, I noticed that when I put the line: rtc.begin() on setup.
That error begin.

Any help?

My code:

#include <LiquidCrystal.h>     
#include <Wire.h>        
#include <DS3231.h>      

DS3231 rtc;            
RTCDateTime dataehora;   
 
LiquidCrystal lcd(0,1,2,3,4,5);
int backlight = 6;
int backlightValor = 255;
int ldrPin = A0; 
int ldrValor = 0; 

void setup(){
  pinMode(backlight, OUTPUT);
  lcd.begin(16,2);            
  lcd.home();
  rtc.begin();           
  //rtc.setDateTime(__DATE__, __TIME__);  

}
 
void loop()
{
    dataehora = rtc.getDateTime(); 
    ldrValor = analogRead(ldrPin);

    backlightValor=255-(ldrValor/4);
    analogWrite(backlight, backlightValor);    
    
    //Serial.print("LdrValor:");
    //Serial.println(ldrValor); 

    //Serial.print("BackLightValor:");
    //Serial.println(backlightValor) 

    lcd.setCursor(0,0);  
    lcd.print(dataehora.year); 
    lcd.setCursor(4,0);     
    lcd.print("-");
    lcd.setCursor(5,0); 
    lcd.print(dataehora.month);
    lcd.setCursor(7,0); 
    lcd.print("-");
    lcd.setCursor(8,0); 
    lcd.print(dataehora.day);     
    ///////////////////////////////////////
    lcd.setCursor(0,1); 
    lcd.print(dataehora.hour);     
    lcd.setCursor(2,1); 
    lcd.print(":");
    lcd.setCursor(3,1); 
    lcd.print(dataehora.minute); 
    lcd.setCursor(5,1); 
    lcd.print(":");
    lcd.setCursor(6,1); 
    lcd.print(dataehora.second); 
    //Serial.print(dataehora.second);
    delay(1000);
}

welcome to the Forum !

please read How to Use this Forum
it is a sticky post at the top of every forum
#6 speaks to subject lines of value.
we have a few RTC Guru's on here. who may never read your post.

if you want them to see your post, put in something like :

Problems with RTC DS3231

before your post any code please read #7
then post the code that does not work.

as for editing, the lower right of your post has an option to modify your post.

Ok, I changed, is all right now?

int backlight = 6;
...
DB6    6

Why did you change the default lcd library configuration? Using pins 0 and 1 is a bad idea (no serial monitor) and you duplicated pin 6 as shown. Go back to the library defaults shown below which allows you to leave the backlight on pin 6.

LiquidCrystal lcd(0,1,2,3,4,5);
int backlight = 6;

DB6 = Digital pin 4

I read that digital pins 0 and 1 can be used as long as the serial monitor is not used.
And I'm not using the monitor anyway, it's already all soldered on the board.
I also read that 0 and 1 are used to send the sketch, but as I said, it is already on the board, so they do not use these functions in fact.

Everything works in the board, except for the RTC.
In a code without ONE rtc line, I inserted line by line of the functions of the RTC and when I inserted the line: rtc.begin in the Setup, the LCD did not turn on. I suspect it's right there.

Re-reading this leaves me confused and I thought you had duplicated pin 6 between the LCD data and backlight. I now do not see that in your program.

Could you please post your current program and please explain this comment:

In a code without ONE rtc line, I inserted line by line of the functions of the RTC and when I inserted the line: rtc.begin in the Setup, the LCD did not turn on. I suspect it's right there.

"The LCD did not turn on" is not clear to me, do you mean the entire display of the LCD, the time value of the just the clock or the LCD backlight?

Yes. The entire display of the LCD.

What I mean about the code is:

(A basic code of RFID + LCD)

#include <LiquidCrystal.h>     
#include <SPI.h>
#include <MFRC522.h>
 
#define SDA_PIN 8
#define RST_PIN 15
char st[20];

MFRC522 mfrc522(SDA_PIN, RST_PIN);
 
LiquidCrystal lcd(0,1,2,3,4,5);
int backlight = 6;
int backlightValue = 255;
int ldrPin = A0;  
int ldrValue = 0; 
 
void setup(){
  //Serial.begin(9600);
  pinMode(backlight, OUTPUT);
  lcd.begin(16,2);           
  lcd.home();
  SPI.begin();  
  mfrc522.PCD_Init();  
  message();
}
 
void loop()
{
    ldrValue = analogRead(ldrPin);

    backlightValue=255-(ldrValue/4);
    analogWrite(backlight, backlightValue);     

    if ( ! mfrc522.PICC_IsNewCardPresent()) 
    {
        return;
    }
    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) 
    {
        return;
    }  
    String content= "";
    byte letter;
    for (byte i = 0; i < mfrc522.uid.size; i++) 
    {
        content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
        content.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    content.toUpperCase();
    if (content.substring(1) == "05 11 F1 2B") 
    {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Correct");
        delay(3000);
        message();
    }
    else 
    {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Incorrect");
        delay(3000);
        message();
    }      
}

void message()
{
  lcd.clear();
  lcd.print("Waiting tag");
}

Let’s slowly add the functions of the RTC.

When I only enter the RTC library, it works.
When I create the following objects underneath the libraries:

DS3231 rtc;
RTCDateTime dateandhour;

And I add:

rtc.begin();

… On void setup, the LCD does not work. Note that I barely put functions, I just initialized the RTC and the LCD does not turn on.

The DS3231 is connected to which pins? Have you run the I2C scanner to see if the RTC is found by the processor?

#define SDA_PIN 8
#define RST_PIN 15

what pins to you have your RTC connected to ?
with your renaming so many pins from the default settings, it would be a really good idea to hand sketch your pin connections.

have you ever been able to get your RTC to work ?

can you post that sketch ?

WattsThat:
The DS3231 is connected to which pins? Have you run the I2C scanner to see if the RTC is found by the processor?

A4 - SDA
A5 - SCL

Default connections.
No, I don't, my components are all welded.

dave-in-nj:

#define SDA_PIN 8

#define RST_PIN 15




what pins to you have your RTC connected to ?
with your renaming so many pins from the default settings, it would be a really good idea to hand sketch your pin connections.

have you ever been able to get your RTC to work ?

can you post that sketch ?

These pins definitions are from RFID.
My RTC pins is default: SCL (A5) and SDA (A4)
Yes, before weld, I have done all tests on the board and everything worked fine.

Lessa157:

#define SDA_PIN 8

#define RST_PIN 15




These pins definitions are from RFID.
My RTC pins is default: SCL (A5) and SDA (A4)
Yes, before weld, I have done all tests on the board and everything worked fine.

check again
I think the MFRC522 board is labeled SDA, not the Arduino #define pin.
and on my UNO, I run out of pins after 13.

[color=blue]#define SS_PIN 10 // Arduino UNO pin 10 connects to MFRC522 pin RST 
#define RST_PIN 9 // Arrduino UNO pin 9 connects to MFRD522 pin SDA
MFRC522 mfrc522(SS_PIN, RST_PIN):
[/color]

and on my UNO, I run out of pins after 13

You can run out if you want to but pins A1 through A5 are also known as digital pins 14 through 19.

Based on what the OP has said, I’d guess he has a solder bridge somewhere. Cannot do more than guess due to the lack of useful information.

Have you run the I2C scanner to see if the RTC is found by the processor?

What does this code show for output.

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

WattsThat:
You can run out if you want to but pins A1 through A5 are also known as digital pins 14 through 19.

Based on what the OP has said, I’d guess he has a solder bridge somewhere. Cannot do more than guess due to the lack of useful information.

too funny, but you're right, but I never think of them as D pins.
btw, what does A0 come up as ? I'm pretty sure it is not 13-1/2 ... LOL
I have to agree that we are missing the OP posting his pin connections.

This data appears in some versions of the pretty pinout pictures. For example, shown in purple or light violet below:

WattsThat:
This data appears in some versions of the pretty pinout pictures. For example, shown in purple or light violet below:

I was just laughing at myself that I did not think of the Analog pins as digital.
with the error of the OP renaming the I2C pin for use with the SPI device, my focus was in that error.
so you caught my error, but then, as can happen, you said A1-A5 as D14-D19…
but it should have been A0 to A5 = D14-D19…

I was wondering is D13 is just that… and A1 = D14… then…
A0 must be