Help with RTC DS3234, Newbie

Hi, I recently discovered arduinos and decided I wanted to learn more about them. I have no previous experience in coding or computers so its been quite a challenge. My first project is an automatic dog feeder. I would like to have a dc motor activated for x amount of time twice a day. I have sparkfun red board and an RTC ds3234. I downloaded the example sketch from sparkfun weblsite:

#include <SPI.h>
const int  cs=8; //chip select 

void setup() {
  Serial.begin(9600);
  RTC_init();
  //day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59)
  SetTimeDate(11,12,13,14,15,16); 
}

void loop() {
  Serial.println(ReadTimeDate());
  delay(1000);
}
//=====================================
int RTC_init(){ 
	  pinMode(cs,OUTPUT); // chip select
	  // start the SPI library:
	  SPI.begin();
	  SPI.setBitOrder(MSBFIRST); 
	  SPI.setDataMode(SPI_MODE1); // both mode 1 & 3 should work 
	  //set control register 
	  digitalWrite(cs, LOW);  
	  SPI.transfer(0x8E);
	  SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled
	  digitalWrite(cs, HIGH);
	  delay(10);
}
//=====================================
int SetTimeDate(int d, int mo, int y, int h, int mi, int s){ 
	int TimeDate [7]={s,mi,h,0,d,mo,y};
	for(int i=0; i<=6;i++){
		if(i==3)
			i++;
		int b= TimeDate[i]/10;
		int a= TimeDate[i]-b*10;
		if(i==2){
			if (b==2)
				b=B00000010;
			else if (b==1)
				b=B00000001;
		}	
		TimeDate[i]= a+(b<<4);
		  
		digitalWrite(cs, LOW);
		SPI.transfer(i+0x80); 
		SPI.transfer(TimeDate[i]);        
		digitalWrite(cs, HIGH);
  }
}
//=====================================
String ReadTimeDate(){
	String temp;
	int TimeDate [7]; //second,minute,hour,null,day,month,year		
	for(int i=0; i<=6;i++){
		if(i==3)
			i++;
		digitalWrite(cs, LOW);
		SPI.transfer(i+0x00); 
		unsigned int n = SPI.transfer(0x00);        
		digitalWrite(cs, HIGH);
		int a=n & B00001111;    
		if(i==2){	
			int b=(n & B00110000)>>4; //24 hour mode
			if(b==B00000010)
				b=20;        
			else if(b==B00000001)
				b=10;
			TimeDate[i]=a+b;
		}
		else if(i==4){
			int b=(n & B00110000)>>4;
			TimeDate[i]=a+b*10;
		}
		else if(i==5){
			int b=(n & B00010000)>>4;
			TimeDate[i]=a+b*10;
		}
		else if(i==6){
			int b=(n & B11110000)>>4;
			TimeDate[i]=a+b*10;
		}
		else{	
			int b=(n & B01110000)>>4;
			TimeDate[i]=a+b*10;	
			}
	}
	temp.concat(TimeDate[4]);
	temp.concat("/") ;
	temp.concat(TimeDate[5]);
	temp.concat("/") ;
	temp.concat(TimeDate[6]);
	temp.concat("     ") ;
	temp.concat(TimeDate[2]);
	temp.concat(":") ;
	temp.concat(TimeDate[1]);
	temp.concat(":") ;
	temp.concat(TimeDate[0]);
  return(temp);
}

and was planning on adapting it to suite my needs with an if() statment. Initially I was able to get it to keep time and activate the motor but it wouldn’t shut off. Now I can’t even get the original sparkfun code to work. It just reads 0’s for the time and date. I would post my adaptation of the code but i became frustrated and deleted it. I’ve tried downloading some alarm examples such as:

#include <Time.h>

#include <TimeAlarms.h>



void setup()

{

  Serial.begin(9600);

  SetTimeDate(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011

  // create the alarms 

  Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day

  Alarm.alarmRepeat(17,45,0,EveningAlarm);  // 5:45pm every day 

  Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm);  // 8:30:30 every Saturday 



 

  Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds    

  Alarm.timerOnce(10, OnceOnly);             // called once after 10 seconds 

}



void  loop(){  

  digitalClockDisplay();

  Alarm.delay(1000); // wait one second between clock display

}



// functions to be called when an alarm triggers:

void MorningAlarm(){

  Serial.println("Alarm: - turn lights off");    

}



void EveningAlarm(){

  Serial.println("Alarm: - turn lights on");           

}



void WeeklyAlarm(){

  Serial.println("Alarm: - its Monday Morning");      

}



void ExplicitAlarm(){

  Serial.println("Alarm: - this triggers only at the given date and time");       

}



void Repeats(){

  Serial.println("15 second timer");         

}



void OnceOnly(){

  Serial.println("This timer only triggers once");  

}



void digitalClockDisplay()

{

  // digital clock display of the time

  Serial.print(hour());

  printDigits(minute());

  printDigits(second());

  Serial.println(); 

}



void printDigits(int digits)

{

  Serial.print(":");

  if(digits < 10)

    Serial.print('0');

  Serial.print(digits);

}

but i keep getting errors like " ‘SetTimeDate’ was not declared in this scope." If anyone could offer some advice I would greatly appreciate it.

Your first code has a function called SetTimeDate(). Your second code does not. Yet, both call it.

but i keep getting errors like " ‘SetTimeDate’ was not declared in this scope." If anyone could offer some advice I would greatly appreciate it.

Do you have both the Time and TimeAlarms libraries installed in your user libraries? The error you got is what you see if the library is not installed.

Edit: As Paul S has stated, SetTimeDate() is not a valid function in the Time library.

The Time library is designed to sync with an I2C RTC like the ds1307, and will not get the time from an SPI RTC like the ds3234 as it is written.

Instead of baseing your work off of the SparkFun code, my recommendation would be to use a ds3234 library like GitHub - rodan/ds3234: arduino library for DS3234 RTC
or http://playground.arduino.cc/Main/DS3234SoftwareLibrary

Get comfortable with reading the RTC, and then write your own alarm code to turn the feeder on and off.

I do have both Time and TimeAlarms installed. I'll take a look at the ones you recommended, Thanks for the suggestion. Hopefully it will save me some frustration.