Arduino Uno program freeze

Hello everyone,

I am a beginner in Programming and Arduino so please excuse me for my questions.

I am trying to make a digital clock (later on use a LM35 for temperature measurement as well) using Arduino Uno (clone) , LED Matrix display and DS1307 I2C module and use some animations in between the display of time and date.( In future temperature as well if the basic program works properly.)

LED Matrix model : https://www.aliexpress.com/item/MAX7219-Dot-Matrix-Module-For-Arduino-Microcontroller-4-In-One-Display-with-5P-Line/32633910582.html?spm=a2g0s.9042311.0.0.6xgZW8

I am able to get the time displayed in the matrix display and on the serial output. But the clock runs for a few minutes or around an hour sometimes and the whole program stops(even the Serial monitor) Maybe the code pauses and display is turned off and there is no blinking light from the Arduino.

But the RTC is keeping the time in the background and if I press the reset button on the Arduino board it shows the correct time and again turns off after some time.

I feel that the program is causing the Arduino to freeze and LED Matrix to turn off but RTC runs in the background. As from the screen capture the time froze at 16:4:38 26/12 and after I pressed Reset button it ran again at 16:7:7 26/12

Please guide me in understanding and fix the issues which I am facing. I am stuck at the starting stage itself and hence I am unable to modify my program further because whatever functions I try to add further the clock turns off so I am stuck.

Please find the code attached. Its not my code because I am a newbie !!!

Capture2.JPG

LEDCLOCK.txt (1.19 KB)

Hi vijithcv and welcome to the forum.

Before we go further, you should read the forum guidelines, because you have posted incorrectly. You should not post images of the serial monitor. You can simply copy the text from serial monitor and paste it into your post between code tags. That way, you can show more text than can fit on your screen. When you post your sketch, you should paste it into your post between code tags, not attach it as a file. See how I did it below. Many forum members read the forum on phones and tablets and may not be able to open attachments.

I will take a look at your code.


Capture2.JPG

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib



#include <Wire.h>
#include <MD_DS1307.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <RTClib.h>




#define MAX_DEVICES 4
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10


RTC_DS1307 rtc;

MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
//MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);



void setup () 
{

  Wire.begin();
  Serial.begin(57600);
  
 if (! rtc.begin()) 
  {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 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(F(__DATE__), F(__TIME__)));
    
  }

  
   
}

void loop () 

{
 

DateTime now = rtc.now();
     
char timeStamp[15];
char dateStamp[15];

sprintf(timeStamp, "%d:%d:%d", now.hour() ,now.minute(), now.second());
Serial.println(timeStamp);

     
sprintf(dateStamp, "%2d/%2d",  now.day(),now.month());   
  
Serial.println(dateStamp);

 
  P.begin();
  P.print(timeStamp);

delay(1000);

 
}

I'm not sure if this is the problem, but I suspect this line should be in setup(), not in loop().

  P.begin();

Its possible that having this line in loop() is consuming ever more ram memory, until there is no ram left, then the program freezes.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering your digital array?

OPs array.
ledarray.jpg

Thanks.. Tom.. :slight_smile:

PaulRB:
Hi vijithcv and welcome to the forum.

Before we go further, you should read the forum guidelines, because you have posted incorrectly. You should not post images of the serial monitor. You can simply copy the text from serial monitor and paste it into your post between code tags. That way, you can show more text than can fit on your screen. When you post your sketch, you should paste it into your post between code tags, not attach it as a file. See how I did it below. Many forum members read the forum on phones and tablets and may not be able to open attachments.

I will take a look at your code.


Capture2.JPG

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include <MD_DS1307.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <RTClib.h>

#define MAX_DEVICES 4
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

RTC_DS1307 rtc;

MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
//MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);

void setup ()
{

Wire.begin();
 Serial.begin(57600);
 
if (! rtc.begin())
 {
   Serial.println("Couldn't find RTC");
   while (1);
 }

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(F(DATE), F(TIME)));
   
 }

}

void loop ()

{

DateTime now = rtc.now();
   
char timeStamp[15];
char dateStamp[15];

sprintf(timeStamp, "%d:%d:%d", now.hour() ,now.minute(), now.second());
Serial.println(timeStamp);

sprintf(dateStamp, "%2d/%2d",  now.day(),now.month());  
 
Serial.println(dateStamp);

P.begin();
 P.print(timeStamp);

delay(1000);

}

Hi

Thanks for the quick reply.

I am sorry for posting like that. I was very much frustrated over this hurdle .Hence I didn't read the guidelines and I was in a hurry to get quick help.

PaulRB:
I'm not sure if this is the problem, but I suspect this line should be in setup(), not in loop().

  P.begin();

Its possible that having this line in loop() is consuming ever more ram memory, until there is no ram left, then the program freezes.

Yes I think that was the mistake. It has solved the issue which I am facing I guess.
Thanks sir for the help.

vijithcv:
I was in a hurry to get quick help.

But that does not work. No-one can help you unless you give all the information they need. The forum guidelines will tell you most of the things needed, and how to post them. Its not about bad language and intolerance (although we don't accept that either, of course!).

Next request: please do not quote entire posts when you reply. It just takes up space and adds nothing. If you want to respond to a particular question or comment, just quote that part, as I did above. Otherwise, just use "Reply".

vijithcv:
It has solved the issue which I am facing I guess.

So it runs for longer without freezing now? Let it run overnight. If it is still running, problem solved.

You don't need to call me "sir". If you want to thank me, give a karma point by clicking "[add]" under my name.

Yes the issue is resolved now.
Thanks.