Go Down

Topic: Strugling with RTC (Read 971 times) previous topic - next topic

PlayStationFarm

I'm trying to build a controller for an automatic chicken coop door.  The door and the mechanics are no problem at all but I have no electronics nor programing experience.  As a result I have been stubbing my toe on setting up my RTC to work with the UNO R3 I have.  The pic below shows my set-up with the Arduino UNO on the bottom, the Arduino motor controller shield on top, and the Adafruit RTC plugged into the motor controller.  The black plastic box is an old Pelican box I had in my junk pile and works great to keep the electronics clean in a dusty chicken coop.

Using the instructions at the Adafruit learning site I have installed (I guess) the RTClib library and compiled/loaded the "TEST" sketch into my UNO.  The compiling and loading seemed to work OK but when I go to serial monitor I get a blank screen.

Since I get a blank screen I do not know if the sketch is loaded properly.  Since I get a blank screen I do not know if the clock time is set properly.  Can someone talk me through some troubleshooting steps?  Thanks.


lost_and_confused

Hi Playstationfarm.

(Been where you are.  Don't fret too much.)

Couple of things though:
The sketch would be handy to look at.

Zip it up and post it as an attachment.

Good luck.

snugRugBug

Hi, I'm not the biggest expert, but here is something to start with:
Have you tested your Uno with any other code? Could be that the hardware isn't working right. Try loading this sketch first:
Code: [Select]

void setup()
{
Serial.begin( 9600 ); // Opens the serial line @ 9600 baud
delay( 10 );
Serial.println( "Hello, world" ); // prints out on the Serial monitor
}

void loop()
{
}


This should print "Hello World" on your serial monitor.

If this works, there is something weird about the RTC code you are trying to run. You should upload it, so we can take a look.
If the Hello World thing doesn't work, there is probably a big hardware problem.

This is just a starting point. Tell us what you find.

PlayStationFarm

#3
Mar 29, 2013, 12:16 am Last Edit: Mar 29, 2013, 12:18 am by PlayStationFarm Reason: 1
Sorry.  I should have put this in my first post.  It's the RTC test sketch provided by Adafruit on their website.

I have gone through many of the learning lessons from various places on the internet and I also have had good success with printing to screen with a couple of the lessons.  Also, I have written a sketch that runs my coop door open and closed just great.  I encountered lots of trouble trying to program lengthy pause times.  So I decided that an RTC was needed to overcome millis() limitations.

Here is the RTC test sketch provided by Adafruit . . .

Code: [Select]
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
   Serial.begin(57600);
   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(__DATE__, __TIME__));
 }

}

void loop () {
   DateTime now = RTC.now();

   Serial.print(now.year(), DEC);
   Serial.print('/');
   Serial.print(now.month(), DEC);
   Serial.print('/');
   Serial.print(now.day(), DEC);
   Serial.print(' ');
   Serial.print(now.hour(), DEC);
   Serial.print(':');
   Serial.print(now.minute(), DEC);
   Serial.print(':');
   Serial.print(now.second(), DEC);
   Serial.println();

   Serial.print(" since 1970 = ");
   Serial.print(now.unixtime());
   Serial.print("s = ");
   Serial.print(now.unixtime() / 86400L);
   Serial.println("d");

   // calculate a date which is 7 days and 30 seconds into the future
   DateTime future (now.unixtime() + 7 * 86400L + 30);

   Serial.print(" now + 7d + 30s: ");
   Serial.print(future.year(), DEC);
   Serial.print('/');
   Serial.print(future.month(), DEC);
   Serial.print('/');
   Serial.print(future.day(), DEC);
   Serial.print(' ');
   Serial.print(future.hour(), DEC);
   Serial.print(':');
   Serial.print(future.minute(), DEC);
   Serial.print(':');
   Serial.print(future.second(), DEC);
   Serial.println();

   Serial.println();
   delay(3000);
}


I may be having trouble with my addition of the RTClib library.  I remember reading somewhere in the gazillion pages of my studies that the Arduino IDE will automatically color the #include commands when the correct files are located in the library directory.  My IDE colors those commands blue and I'm pretty sure that's not good.  I did have some difficulty getting those RTClib.cpp and RTClib.h files in the library.  I might have something wrong there.  But when I compiled that sketch no error messages were given.  Hmmmmm.

Here is the sketch that I have tried to use with the lengthy pause intervals between run times for my door motor.  I have tested this same sketch with much shorter timing settings and it works very good.

Code: [Select]
// Drive motor CW 34 seconds, pause 16 hours, run motor CCW 34 seconds, pause 8 hours, repeat.  L.C. H. 2/24/2013

// Motor A definitions
int DIR_A = 12;
int SPEED_A = 3;
int BREAK_A = 9;

// Motor B definitions
int DIR_B = 13;
int SPEED_B = 11;
int BREAK_B = 8;

void setup()
{
 pinMode(SPEED_A, OUTPUT);
 pinMode(DIR_A, OUTPUT);
 pinMode(BREAK_A, OUTPUT);

 // release break
 digitalWrite(BREAK_A, LOW);
}

void loop()
{
 // run motor backward full speed.  (Max is 250)
 digitalWrite(DIR_A, HIGH);
 analogWrite(SPEED_A, 250);

 // run motor for 34 seconds to open
 delay(34000);

// stop motor
 analogWrite(SPEED_A, 0);

 // pause door open 16 hours (minus runtime)
 delay(57566000);

// run motor forward full speed.  (Max is 250)
 digitalWrite(DIR_A, LOW);
 analogWrite(SPEED_A, 250);

 // run motor for 34 seconds to close
 delay(34000);

 // stop motor
 analogWrite(SPEED_A, 0);

 // pause door closed 8 hour (minus runtime)
 delay(10000);
 
}


PlayStationFarm


Go Up