problems with synchronization of arduino and chronodot

Hi,

I am using a arduino-1 and chronodot to control indipendently 3 different LEDs strips.
I connected the arduino-1 to chronodot as indicated in this link: http://zevenrodriguez.com/chronodot-and-arduino-1-0/
Then, I connected the 3 different LEDs to 3 different digital pins (9, 10 ,11) as indicated in this link: bildr High-Power Control: Arduino + TIP120 Transistor - bildr

I can set and read correctly the time on the serial port COM4.

As a first step, I am controlling the light ON and OFF only of the LED connected to pin 11 with TimeAlarms, and I set the intensity of the LEDs connected to pin 9 and 10 with analogWrite().

This is the sketch:

#include <Time.h>                  // include the library Time
#include <TimeAlarms.h>            // include the library TimeAlarms

void setup()
{
  Serial.begin(9600);     // initialize the serial port 
  setTime(8,30,0,1,1,11); // set actual time and date   (hours,minute, seconds, day, month, year)

  Alarm.alarmRepeat(9,0,0, MorningAlarm);  // create a first alarm to do an action every day at the same time
  Alarm.alarmRepeat(18,0,0, EveningAlarm);  // create a second alarm to do an action every day at the same time
}

void  loop(){  
  digitalClockDisplay(); //declare the function digital clock display
  Alarm.delay(1000); // wait one second between clock display (it is necessary to allow the alarms to work properly)
  int irLed = 9;     // declare that we have connected the Infrared LEDs to pin 9
  int redLed = 10;    // declare that we have connected the Red LEDs to pin 10
  analogWrite(irLed, 250);    // Switch on Infrared LEDs at the intensity (we can use values in the following range 0-250)
  analogWrite(redLed, 250);   // Switch on Red LEDs at the intensity (we can use values in the following range 0-250)
}


void MorningAlarm(){         // functions to be called when the first alarm triggers
 
  int whiteLed = 11;          // declare that we have connected the White LEDs to pin 11
 
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {       // sets the value (range from 0 to 255):

  analogWrite(whiteLed, fadeValue);    // start to fade in the LEDs   
     
  delay(1000);                  // wait for 1 second to see the dimming effect
 
   Serial.println("LIGHT ON");       // write on the serial port "LIGHT ON"                       
}
}

void EveningAlarm(){         // functions to be called when the first alarm triggers
 
  int whiteLed = 11;
   
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
   
  analogWrite(whiteLed, fadeValue);        
       
  delay(300);
 
  Serial.println("LIGHT OFF");        // the same as above but with fade out     
}
}



void digitalClockDisplay()         
{
 
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();          // digital clock display of the time on serial port
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);      // definitions of the format to write the time
  
}                            // END

I FOUND THE FOLLOWING PROBLEM:

  • after 10 days that arduino is running and controlling the light ON/OFF of the LEDs connected to the pin 11, I realized that there is a delay of 8 minutes (in the time printed in the serial port) accumulated in these 10 days. Consequently there is a delay in triggering the ON/OFF of the light (pin 11).

How is it possible with chronodot?

Is there something wrong in my sketch?

I really appreciate if someone could help me to find the solution.

Thank you

You don't put code in quote tags - you put them in code tags - How to post code properly

Pete

done. Sorry!

V

I don't see where you are actually using the Chronodot time. I think the Time library uses the Arduino's timer interrupt.

Pete

So the problem is at the beginning of the sketch when I set the time?

could you suggest me how is the best way to solve the problem?

Thank you

Valerio

How is it possible with chronodot?

Because you aren't using it?

The page you linked to has a link to the Adafruit RTC library ( GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library ) which you are not using.

Ok, thank you. :grin: :grin:

I will include the RTC library and modify the script.

I will write if everything will be OK.

Thank you

Hi,

I modified my sketch and now I am usign the time from chronodot.

However, the alarms I created (Alarm.alarmRepeat and Alarm.alarmRepeat) do not trigger the actions I want to.

Do you see something wrong in the sketch?

Thank you for your help and sorry for some stupid errors…

Valerio

#include <Wire.h>
#include <Chronodot.h>             // include the library Chronodot
#include <Time.h>                  // include the library Time
#include <TimeAlarms.h>            // include the library TimeAlarms


Chronodot RTC;


void setup()
{
  Serial.begin(9600);     // initialize the serial port 
  Serial.println("Initializing Chronodot.");

  Wire.begin();
  RTC.begin();

  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(2013,12,2,8,0,0));
  
  Alarm.alarmRepeat(9,0,0, MorningAlarm);     // create a first alarm to do an action every day at the same time
  Alarm.alarmRepeat(18,0,0, EveningAlarm);    // create a second alarm to do an action every day at the same time
}
}

void  loop(){  
  digitalClockDisplay(); //declare the function digital clock display
  Alarm.delay(1000); // wait one second between clock display (it is necessary to allow the alarms to work properly)
  int irLed = 9;     // declare that we have connected the Infrared LEDs to pin 9
  int redLed = 10;    // declare that we have connected the Red LEDs to pin 10
  analogWrite(irLed, 250);    // Switch on Infrared LEDs at the intensity (we can use values in the following range 0-250)
  analogWrite(redLed, 250);   // Switch on Red LEDs at the intensity (we can use values in the following range 0-250)
}


void MorningAlarm(){         // functions to be called when the first alarm triggers
 
  int whiteLed = 11;          // declare that we have connected the White LEDs to pin 11
 
  for(int fadeValue = 0 ; fadeValue <= 75; fadeValue +=5) {       // sets the value (range from 0 to 255):

  analogWrite(whiteLed, fadeValue);    // start to fade in the LEDs   
     
  delay(1000);                  // wait for 1 second to see the dimming effect
 
   Serial.println("LIGHT ON");       // write on the serial port "LIGHT ON"                       
}
}

void EveningAlarm(){         // functions to be called when the first alarm triggers
 
  int whiteLed = 11;
   
  for(int fadeValue = 75 ; fadeValue >= 0; fadeValue -=5) {
   
  analogWrite(whiteLed, fadeValue);        
       
  delay(1000);
 
  Serial.println("LIGHT OFF");        // the same as above but with fade out     
}
}



void digitalClockDisplay()         
{
  DateTime now = RTC.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    if(now.month() < 10) Serial.print("0");
    Serial.print(now.month(), DEC);
    Serial.print('/');
    if(now.day() < 10) Serial.print("0");
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    if(now.hour() < 10) Serial.print("0");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    if(now.minute() < 10) Serial.print("0");
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    if(now.second() < 10) Serial.print("0");
    Serial.print(now.second(), DEC);
    Serial.println();
    
    delay(5000);
    
}                            // END