Pages: [1]   Go Down
Author Topic: Arduino hangs?  (Read 707 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Posting here as I think this is not related to the project but to the Arduino: I made my own word clock and noted that sometimes, very irregular, the system decides to 'hang'. This means that no time will be updated any more. As this is a standalone Arduino project I can't verify any other (serial) output. When I turn it off and on again it works and it stays working all night long...

Any experience?

Thanks!
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34230
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Any decoupling on the external electronics?
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have a spare pin you could attach an LED+resistor to show that the Arduino is still running, and if you have two spare pins you could use SoftwareSerial to send debug output to another Arduino which can relay the output back to your PC.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2316
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could try posting your code for us to look at!. But I'll put my money on you having used the String class.

Mark
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all

There is already one 100 uF condensator attached between ground and 5V where it enters, I hope this is enough for the decoupling or am I misunderstanding this? (sorry pretty new to electronics!)

The extra LED might be a good idea but will take some time to implement as it's a closed system... I'll check how I can do this! Adding an extra arduino is not feasible at this time.

I didn't use any Strings so no string class afaik but I'm using 3 includes: #include <LedControl.h> (matrix), #include <Wire.h> and #include <DS1307.h> (time).

Posting code would be fine for me but than it doesn't feel like solving the issue any more but just (ab)using you guys smiley
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3701
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A fairly common way of hanging an arduino sketch (or other C code for that matter) is writing on inappropriate memory locations. Check that you're not writing off the end of an array, or using a return value from a function that doesn't always explicitly return one. Really though, for any more focused assistance, you'll need to post your code.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is too simple for memory writing I believe. Please have a look below. I'm going to add a second 100uF capacitator today.

Thanks for any ideas!

Code:
#include <LedControl.h>
#include <Wire.h>
#include <DS1307.h>
int buttonMinUpdate = 0, buttonHourUpdate = 0;   
char dateTime[22];
int minuteNow, minuteOld = 0;
int RTCValues[7], i = 0, year, month, dayOfMonth, dayOfWeek, hour, minute, second, intStatus = 1, oldStatus = 1;
const int buttonPinMinute = 3, buttonPinHour = 4, buttonShutdown = 5;

// inputs: DIN pin, CLK pin, LOAD pin. number of chips
LedControl mydisplay = LedControl(9, 10, 11, 2);


void setup()
{
 //setTime();
  DS1307.begin();
  pinMode(buttonPinMinute, INPUT);
  pinMode(buttonPinHour, INPUT);
  pinMode(buttonShutdown, INPUT);   
  intStatus = digitalRead(buttonShutdown);
  if(intStatus == 0)
  {
     mydisplay.shutdown(0, false);  // turns on display
     mydisplay.shutdown(1, false);  // turns on display
  }
  else
  {
    mydisplay.shutdown(0, true);  // turns on display
    mydisplay.shutdown(1, true);  // turns on display
  }
  oldStatus = intStatus;
  mydisplay.setIntensity(0, 15); // 15 = brightest
  mydisplay.setIntensity(1, 15); // 15 = brightest
}

void loop()
{
  DS1307.getDate(RTCValues);
  buttonMinUpdate = digitalRead(buttonPinMinute);
  buttonHourUpdate = digitalRead(buttonPinHour);
  sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d", RTCValues[0], RTCValues[1], RTCValues[2], RTCValues[4], RTCValues[5], RTCValues[6]);       
  minuteNow = RTCValues[5];
  intStatus = digitalRead(buttonShutdown);
  if(oldStatus != intStatus)
   {
       oldStatus = intStatus;
      if(intStatus == 0)
      {
         mydisplay.shutdown(0, false);  // turns on display
         mydisplay.shutdown(1, false);  // turns on display
      }
      else
      {
        mydisplay.shutdown(0, true);  // turns on display
        mydisplay.shutdown(1, true);  // turns on display
      }
   }

  if(buttonMinUpdate == 0)
  {
    updateTimeMin();
  }
  if(buttonHourUpdate == 0)
  {
    updateTimeHour();
  }   
  if(minuteNow != minuteOld)
  {
      minuteOld = minuteNow;
      VisualizeTime();
  }

  delay(750);
}

void VisualizeTime()
{
    mydisplay.clearDisplay(0);
    mydisplay.clearDisplay(1);
    enableHetIs();
    int intMinutes = RTCValues[5];
    int intExtraMin = intMinutes % 5;
    enableMinutes(intExtraMin);
    int intFunction = RTCValues[5] / 5;
    int intHour = RTCValues[4];
    if(intFunction >= 4)
    {
      intHour++;
    }
     enableFunction(intFunction);
   
    enableHour(intHour);
}

void enableHour(int intHour)
{
  while(intHour >= 12)
  {
     if(intHour >= 12)
     {
      intHour -= 12;
     }
  }
   switch (intHour)
   {
    case 0:   
      mydisplay.setLed(0, 0, 6, true);
      mydisplay.setLed(0, 1, 6, true);
      mydisplay.setLed(0, 2, 6, true);
      mydisplay.setLed(0, 3, 6, true);
      mydisplay.setLed(0, 4, 6, true);
      mydisplay.setLed(0, 5, 6, true);
      break;
    case 1:   
      mydisplay.setLed(1, 4, 5, true);
      mydisplay.setLed(1, 5, 5, true);
      mydisplay.setLed(1, 6, 5, true);
      break;
   }
}

void enableHetIs()
{
   mydisplay.setLed(1, 4, 0, true);
   mydisplay.setLed(1, 5, 0, true);   
   mydisplay.setLed(1, 6, 0, true);
   
   mydisplay.setLed(0, 6, 0, true);
   mydisplay.setLed(0, 5, 0, true);   
}

void enableMinutes(int intExtraMin)
{
  //there is no break in thise case intentionally
  switch (intExtraMin)
   {
    case 4:   
      mydisplay.setLed(1, 2, 4, true);
    case 3:   
      mydisplay.setLed(1, 2, 3, true);
    case 2:   
      mydisplay.setLed(1, 3, 4, true);
    case 1:   
      mydisplay.setLed(1, 3, 3, true);
      break;
   }
}

void enableFunction(int intFunction)
{
  switch (intFunction)
   {
    case 0:   
      enableUur();
      break;
    case 1:   
      enableVijf();
      enableOver();
      break;
   }
}

void enableUur()
{
  mydisplay.setLed(1, 1, 5, true);
  mydisplay.setLed(1, 1, 6, true);
  mydisplay.setLed(1, 1, 7, true);
}

void enableVijf()
{
  mydisplay.setLed(0, 0, 0, true);
  mydisplay.setLed(0, 1, 0, true);
  mydisplay.setLed(0, 2, 0, true);
  mydisplay.setLed(0, 3, 0, true);
}

void enableOver()
{
  mydisplay.setLed(0, 0, 0, true);
  mydisplay.setLed(0, 1, 0, true);
  mydisplay.setLed(0, 2, 0, true);
  mydisplay.setLed(0, 3, 0, true);
}

void updateTimeMin()
{
   minute = RTCValues[5] + 1;
  if(minute == 60)
  {
    minute = 0;
  }
  hour = RTCValues[4];
  completeUpdate();
}

void updateTimeHour()
{
   minute = RTCValues[5];
   hour = RTCValues[4] + 1;
   if(hour == 24)
   {
    hour = 0;
   }
   completeUpdate();
}

void completeUpdate()
{
  second = 0;
  dayOfMonth = RTCValues[2] ;
  dayOfWeek = RTCValues[3] ;
  year = RTCValues[0];
  month = RTCValues[1];
  DS1307.setDate(year, month, dayOfMonth, dayOfWeek, hour, minute, second);
  DS1307.getDate(RTCValues);
  VisualizeTime();
}
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3701
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On a first glance, I can't see an issue in the code. Can you add some more serial prints to zero on on where it crashes?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, but I can't add any serial output as there is no way to attach it at the moment. It is a standalone situation with no breakout for USB.

I added a 2nd capacitor, getting my hopes up!
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, but I can't add any serial output as there is no way to attach it at the moment. It is a standalone situation with no breakout for USB.

I added a 2nd capacitor, getting my hopes up!

No spare I/O pins available?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: