My first project

Hello,

Im kinda new to this arduino stuff so please be patient =)

So here it goes. Im having problems with my RTC DS3231. When it comes to 59 minuts it just wont display 00 or it will go up and show like 85 minuts insted of starting from 0. But when i restart my arduino it goes to show 8minuts like its suposed to, same with hours it will go to 24 and then the first digit will go from start or 0 but the second digit wont reset unless i reset my board.

I dont know how to describe it more detailed sorry. =/

i really hope someone can help me im troubleshooting the rtc for about a month now and i dont seem to make any progress.

fifi_terarij.ino (3.51 KB)

The OP's code posted in the recommended way

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <ds3231.h>
#include <DallasTemperature.h>
#include <OneWire.h>


#define DS3231
#define ONE_WIRE_BUS 53 //podatkovni pin za senzorja

// nastavimo tako da komuniciramo z digitalnim portom 33 ali senzorjim
OneWire oneWire(ONE_WIRE_BUS);


// pošljemo našo referenco v onewire
DallasTemperature sensors(&oneWire);

// Adresa mojih senzorjev
uint8_t T1[8] = { 0x28, 0x68, 0xBE, 0xC5, 0x08, 0x00, 0x00, 0x0C }; //topla stran
uint8_t T2[8] = { 0x28, 0x7F, 0xC1, 0xC5, 0x08, 0x00, 0x00, 0xD0 }; //hladna stran

struct ts t;


const int LED = 6;
const int jutro = 9;
const int vecer = 10;
const int G1 = 2;//topla stran
const int G2 = 4; //hladna stran





LiquidCrystal_I2C lcd1 = LiquidCrystal_I2C(0x27, 20, 4); // addressa lcd1
LiquidCrystal_I2C lcd2 = LiquidCrystal_I2C(0x26, 20, 4); //addressa lcd2

void setup()
{
  Wire.begin(); //zaženemo i2c komunikacijo
  pinMode(LED, OUTPUT); //osvetlitev
  pinMode(G1, OUTPUT); //grelec 1
  pinMode(G2, OUTPUT); //grelec 2
  //tukaj nastavimo začetni čas
  t.hour = 8;
  t.min = 48;
  t.mday = 28;
  t.mon = 9;
  t.year = 2020;
  DS3231_set(t);
  //"pripravimo" lcd1 in lcd2:
  lcd1.init();
  lcd2.init();
  lcd1.backlight();
  lcd2.backlight();
  sensors.begin();
}

void loop()
{
  DS3231_get(&t);//dobimo čas od rtc
  sensors.requestTemperatures();//dobimo temperaturi topla/hladna stran
  //napišemo datum d/m/l v prvo vrstico lcd1
  lcd1.setCursor(0, 0);
  lcd1.print( "Danes smo " );
  lcd1.setCursor(10, 0);
  lcd1.print(t.mday);
  lcd1.setCursor(12, 0);
  lcd1.print( "/" );
  lcd1.setCursor(13, 0);
  lcd1.print(t.mon);
  lcd1.setCursor(14, 0);
  lcd1.print( "/" );
  lcd1.setCursor(15, 0);
  lcd1.print(t.year);
  //druga vrstica lcd1 napišemo uro u:m
  lcd1.setCursor(0, 1);
  lcd1.print( "Ura je " );
  lcd1.setCursor(7, 1);
  lcd1.print(t.hour);
  lcd1.setCursor(9, 1);
  lcd1.print( ":" );
  lcd1.setCursor(10, 1);
  lcd1.print(t.min);
  //četrta vrstica lcd1 pa ostane "prosta" =D
  lcd1.setCursor(0, 3);
  lcd1.print("Fifi se ima lepo :P");
  //lcd 2
  //prva vrstica lcd2
  lcd2.setCursor(0, 0);
  lcd2.print( "Topla stran " );
  lcd2.setCursor(12, 0);
  lcd2.print(sensors.getTempC(T1));
  lcd2.setCursor(18, 0);
  lcd2.print( "C");
  //druga vrstica lcd2
  lcd2.setCursor(0, 1);
  lcd2.print( "Hladna stran " );
  lcd2.setCursor(13, 1);
  lcd2.print(sensors.getTempC(T2));
  lcd2.setCursor(19, 1);
  lcd2.print( "C");
  //tretja vrstica lcd2
  lcd2.setCursor(0, 2);
  lcd2.print( "G1: " );
  lcd2. setCursor(10, 2);
  lcd2.print( "G2: " );
  //osvetlitev terarija med 8 uro zjutraj in 8uro zvecer
  if (t.hour <= vecer)
  {
    digitalWrite(LED, HIGH); //kdaj se prizge osvetlitv
  }
  if (t.hour >= jutro)
  {
    digitalWrite(LED, LOW); //kdaj se vgasne osvetlitev
  }
  //if stavki za dvo consko kontroliranje hladne in tople strani
  sensors.requestTemperatures();// ponovno zahtevamo branje stopinj
  // Topla stran terarija
  if (sensors.getTempC(T1) >= 29)
  {
    digitalWrite(G1, HIGH); // kdaj izklopimo grelec 1
  }
  if (sensors.getTempC(T1) <= 27)
  {
    digitalWrite(G1, LOW); //kdaj vklopimo grelec 1
  }
  // Hladna stran terarija
  if (sensors.getTempC(T2) >= 26)
  {
    digitalWrite(G2, HIGH);//kdaj izklopimo grelec 2
  }
  if (sensors.getTempC(T2) <= 24)
  {
    digitalWrite(G2, LOW);//kdaj vklopimo grelec 2
  }
  delay(1000);
}

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here

When a number is less than 10, only a single digit will be printed to the display, with no leading zero. When you go from 59 to 0, the 0 will overwrite the 5 from the previous time, but leave the 9 as it is, resulting in a display that shows 09 instead of 00. The common solution for this is to check if the number to be printed is less than ten, and if so print an extra zero before the number.

download and use

#include <MD_DS3231.h>
MD_DS3231 MD_RTC;

very simplified and he has samples in there that will load the zero in front when less than 10 for example. the only ds3231 helper you need imo. good luck.

sevenoutpinball:
download and use

#include <MD_DS3231.h>
MD_DS3231 MD_RTC;

?

I think it's easier

sevenoutpinball:
I think it's easier

What do you think is easier ?

using the MD_ code for the DS3231.

I think you need something like this. If this is wrong I amsuresomeone will correct me.

If (minutes = 60, minutes = 0);

If (Hours =24, hours = 0);

Yes, sorry... it should be == not =...

but anyway...

if (minutes >= 60) minutes = 0;
if (hours >= 24) hours = 0;

It offers greater protection, for example from incorrect initialization.

sevenoutpinball:
using the MD_ code for the DS3231.

I assume that you are recommending a particular library. If so then why not just say so and explain where it can be obtained from ?