DS3231 problem

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

#define BACKLIGHT_PIN 3

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
DS3231 clock;
RTCDateTime dt;

void setup()
{
Serial.begin(9600);
lcd.begin (16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
// Inicjalizacja DS3231
Serial.println(“Initialize DS3231”);;
clock.begin();

// Ustawiany date i godzine kompilacji szkicu
clock.setDateTime(DATE, TIME);
}

void loop()
{
// Odczytujemy i wyswietlamy czas
dt = clock.getDateTime();
clock.forceConversion();

lcd.setCursor(0,1);
lcd.print(dt.year); lcd.print("-");
lcd.print(dt.month); lcd.print("-");
lcd.print(dt.day); lcd.print(" “);
lcd.setCursor(0,0);
lcd.print(dt.hour); lcd.print(”:");
lcd.print(dt.minute); lcd.print(":");
lcd.print(dt.second); lcd.print("");
lcd.setCursor(10,0);
lcd.print(clock.readTemperature());
lcd.print(“C”);
delay(1000);
}

Yup, that's a problem.

gregor36:
problem

is what.......?

1/time displays badly

after the addition of the thermometer

2/ how to change formatczasu of
9:5:30 na
09:05:30

3/seconds 2,4,6 not 2,3,4.

sory translator

if (dt.hour < 10)
{
  lcd.print("0");
}
lcd.print(dt.hour);   lcd.print(":");

etc.

You can improve this skit :*
please

seconds 2,4,6 not 2,3,4.

https://gist.github.com/gregor36/fb9a95e594eec9e36350
revised sketch
only how to change the time format
1.1.1
01.01.01

char timeString[10];
sprintf ( timeString , "%02d:%02d:%02d",dt.hour,dt.minute,dt.second);
lcd.print(timeString);

seconds 2,4,6 not 2,3,4.

Lose the delay() and only update the display when seconds change.

char timeString[10];
sprintf ( timeString , “%02d:%02d:%02d”,dt.hour,dt.minute,dt.second);
lcd.print(timeString);

where is paste

Into your sketch.

AWOL:

seconds 2,4,6 not 2,3,4.

Lose the delay() and only update the display when seconds change.

already found
clock.forceConversion();
caused an error

AWOL:
Into your sketch.
[/void loop()
{
// Odczytujemy i wyswietlamy czas
dt = clock.getDateTime();
char timeString[10];
sprintf ( timeString , "%02d:%02d:%02d",dt.hour,dt.minute,dt.second);
lcd.print(timeString);

lcd.setCursor(0,1);
lcd.print(dt.year); lcd.print("-");
lcd.print(dt.month); lcd.print("-");
lcd.print(dt.day); lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(dt.hour); lcd.print(":");
lcd.print(dt.minute); lcd.print(":");
lcd.print(dt.second); lcd.print("");
lcd.setCursor(10,0);
lcd.print(clock.readTemperature());
lcd.print("C");
delay(1000);
}quote]

void loop()
{
  // Odczytujemy i wyswietlamy czas
  dt = clock.getDateTime();
  char timeString[10];

  lcd.setCursor(0,1);
  sprintf ( timeString , "%02d-%02d-%02d",dt.year,dt.month,dt.day);
  lcd.print(timeString);
  lcd.setCursor(0,0);
  sprintf ( timeString , "%02d:%02d:%02d",dt.hour,dt.minute,dt.second);
  lcd.print(timeString);
 
//    REMOVE THIS STUFF
//    vvvvvvvvvvvvvvvvv
//  lcd.print(dt.year);   lcd.print("-");
//  lcd.print(dt.month);  lcd.print("-");
//  lcd.print(dt.day);    lcd.print(" ");
//  lcd.setCursor(0,0);
//  lcd.print(dt.hour);   lcd.print(":");
//  lcd.print(dt.minute); lcd.print(":");
//  lcd.print(dt.second); lcd.print("");
//    ^^^^^^^^^^^^^^^^^

  lcd.setCursor(10,0);
  lcd.print(clock.readTemperature());
  lcd.print("C");
  delay(1000);
}

KenF:

void loop()

{
 // Odczytujemy i wyswietlamy czas
 dt = clock.getDateTime();
 char timeString[10];

lcd.setCursor(0,1);
 sprintf ( timeString , "%02d-%02d-%02d",dt.year,dt.month,dt.day);
 lcd.print(timeString);
 lcd.setCursor(0,0);
 sprintf ( timeString , "%02d:%02d:%02d",dt.hour,dt.minute,dt.second);
 lcd.print(timeString);

//    REMOVE THIS STUFF
//    vvvvvvvvvvvvvvvvv
//  lcd.print(dt.year);   lcd.print("-");
//  lcd.print(dt.month);  lcd.print("-");
//  lcd.print(dt.day);    lcd.print(" ");
//  lcd.setCursor(0,0);
//  lcd.print(dt.hour);   lcd.print(":");
//  lcd.print(dt.minute); lcd.print(":");
//  lcd.print(dt.second); lcd.print("");
//    ^^^^^^^^^^^^^^^^^

lcd.setCursor(10,0);
 lcd.print(clock.readTemperature());
 lcd.print("C");
 delay(1000);
}

great thanks :slight_smile:

Not that this is related to your DS3231 problem but you are improperly
using the LiquidCrystal library API.

This call:

 lcd.setBacklight(HIGH);

is asking the library to set the backlight at 1/255 of its brightness which is VERY dim.
In this particular case, it is accidentally working because the library will set the display
to full intensity or on, if dimming is not supported.

setBacklight(intensity);

takes an intensity value not a HIGH/LOW value to indicate on/off.

 lcd.setBacklightPin(pin, polarity);

has been deprecated. The pin an polarity can be specified in the constructor as follows in your case:

LiquidCrystal_I2C	lcd(0x27,2,1,0,4,5,6,7, BACKLIGHT_PIN, POSITIVE);

This will allow lcd.begin() to turn on the backlight which means
you can remove these lines:

 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);

--- bill

bperrybap:
Not that this is related to your DS3231 problem but you are improperly
using the LiquidCrystal library API.

This call:

 lcd.setBacklight(HIGH);

is asking the library to set the backlight at 1/255 of its brightness which is VERY dim.
In this particular case, it is accidentally working because the library will set the display
to full intensity or on, if dimming is not supported.

setBacklight(intensity);

takes an intensity value not a HIGH/LOW value to indicate on/off.

 lcd.setBacklightPin(pin, polarity);

has been deprecated. The pin an polarity can be specified in the constructor as follows in your case:

LiquidCrystal_I2C	lcd(0x27,2,1,0,4,5,6,7, BACKLIGHT_PIN, POSITIVE);

This will allow lcd.begin() to turn on the backlight which means
you can remove these lines:

 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

lcd.setBacklight(HIGH);




--- bill

lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH)
Delete this and goes out LCD

gregor36:
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH)
Delete this and goes out LCD

That will be true, if the other required modification was not done,
which is to update the constructor as I showed.

bperrybap:
The pin an polarity can be specified in the constructor as follows in your case:

LiquidCrystal_I2C	lcd(0x27,2,1,0,4,5,6,7, BACKLIGHT_PIN, POSITIVE);

This will allow lcd.begin() to turn on the backlight which means
you can remove these lines:

 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

lcd.setBacklight(HIGH);

The constructor tells the library which output pin and the polarity needed
to turn on the backlight.
When using the full/proper constructor, you will no longer need to
do the calls to configure the output pin and turn on the backlight as begin() will turn on the backlight,
so these lines will not be needed and can be removed:

setBacklight(dimvalue) was not intended for turning the backlight on/off. It is for dimming the backlight.
backlight() and noBacklight() are for turning the backlight on/off.

To use setBacklight(dimvlue) to set the backlight to no dimming (full on) or full dimming (full off)
the proper dim values should be used:
for full on, the proper dimvalue is BACKLIGHT_ON
for full off the proper dim value is BACKLIGHT_OFF

So
backlight() is the same as setBacklight(BACKLIGHT_ON)
noBacklight() is the same as setBacklight(BACKLIGHT_OFF)

setBacklight(HIGH) is invalid/incorrect.
setBacklight(LOW) is invalid/incorrect.

--- bill

it is possible to program the system so that the 07-to 19 lcd shone brighter and from 19 to 07 darker

i2c backpacks do not have the circuitry to dim the backlight.
i2c backpacks can only turn the backlight on and off.

If you have a display with dark pixels and light background,
you could turn the backlight on/off depending on the time
so between 07 and 19 the backlight could be on and off between 19 and 07.
You will still be able to read the display if the room is lit but it will be darker.

If you have display with light pixels on a dark background, then the backlight
must always be on in order to see the pixels.

If you really want to do dimming of the backlight led,
it is possible, but it requires modifying
the i2c backpack board and then using an Arduino pin along with analogWrite() to control the intensity.

--- bill