Arduino LCD and DS3231 RTC sharing I2C line

Hello everyone, I am trying to connect a 16x2 LCD screen using a lcm1602, along with a DS3132 to tell the time. I have both the devices connected to the scl and sda line, sharing it. Now, once the connection was finished I coded it in order to display the time on the LCD. When I uploaded the code, however, the display only sometimes showed some random symbols that would refresh and get pushed along the screen every second. The ds3231 seems to be working normally though.

Any thoughts on why this is? I have no Idea how to fix this. Thanks in advanced for the help.

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


//initialze DS3231
DS3231  rtc(SDA, SCL);

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //0x3F is the address for the LCD

void setup() {
  // put your setup code here, to run once:
  //init. RTC object
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("hello");
  rtc.begin();
  pinMode(2, INPUT_PULLUP);
  pinMode(12, OUTPUT);
  Serial.begin(9600);
  lcd.clear();
  delay(1000); 
}


void loop(){    
  lcd.print(rtc.getTimeStr());
  Serial.println(rtc.getTimeStr());
  lcd.clear();
  delay(1000);
 }

I tried to put a simple "hello" during the setup function, but even that doesn't work. And when the "hello" is placed in the loop, all it does is flash parts of it faintly. Upon taking off the ds3231, the display works fine.

You print to the LCD and to Serrial, then clear the display, then delay. How long is the data actually on the LCD? It may work better if you delay then clear the LCD so the data is displayed longer that a few milliseconds.

I suggest that you look into the blink without delay method using millis() for timing the display instead of using the, blocking, delay().

groundFungus:
You print to the LCD and to Serrial, then clear the display, then delay. How long is the data actually on the LCD? It may work better if you delay then clear the LCD so the data is displayed longer that a few milliseconds.

I suggest that you look into the blink without delay method using millis() for timing the display instead of using the, blocking, delay().

Oh goodness, I can't believe I didn't see that. Anyhow, thanks for the help, it worked. And thanks for the suggestion too, that will be very useful for what I need to do.