Help Servo Motor + RTC DS1307

Hello,

I’m new using arduino… some normal programs works for me. But the RTC is killing me!
Can anyone help?

I got this message when testing a RTC program:

CODE:
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> written by mattt on the Arduino forum and modified by D. Sjunnesson

void setup(){
Serial.begin(9600);
RTC.stop();
RTC.set(DS1307_SEC,1); set the seconds
RTC.set(DS1307_MIN,23); set the minutes
RTC.set(DS1307_HR,12); set the hours
RTC.set(DS1307_DOW,4); set the day of the week
RTC.set(DS1307_DATE,15); set the date
RTC.set(DS1307_MTH,7); set the month
RTC.set(DS1307_YR,10); set the year
RTC.start();
}

void loop(){
Serial.print(RTC.get(DS1307_HR,true)); read the hour and also update all the values by pushing in true
Serial.print(":");
Serial.print(RTC.get(DS1307_MIN,false));read minutes without update (false)
Serial.print(":");
Serial.print(RTC.get(DS1307_SEC,false));read seconds
Serial.print(" “); some space for a more happy life
Serial.print(RTC.get(DS1307_DATE,false));read date
Serial.print(”/");
Serial.print(RTC.get(DS1307_MTH,false));read month
Serial.print("/");
Serial.print(RTC.get(DS1307_YR,false)); //read year
Serial.println();
delay(1000);
}

PROBLEM:

In file included from sketch_may28b.cpp:3:
C:\Program Files\arduino-1.0.1_radiuino-1.3\libraries\DS1307/DS1307.h:47: error: ‘boolean’ has not been declared
C:\Program Files\arduino-1.0.1_radiuino-1.3\libraries\DS1307/DS1307.h:48: error: ‘boolean’ has not been declared
C:\Program Files\arduino-1.0.1_radiuino-1.3\libraries\DS1307/DS1307.h:55: error: ‘byte’ does not name a type
sketch_may28b.cpp: In function ‘void setup()’:
sketch_may28b:7: error: ‘set’ was not declared in this scope
sketch_may28b:7: error: expected ;' before 'the' sketch_may28b:8: error: expected ;’ before ‘the’
sketch_may28b:9: error: expected ;' before 'the' sketch_may28b:10: error: expected ;’ before ‘the’
sketch_may28b:11: error: expected ;' before 'the' sketch_may28b:12: error: expected ;’ before ‘the’
sketch_may28b:13: error: expected ;' before 'the' sketch_may28b.cpp: In function 'void loop()': sketch_may28b:18: error: 'read' was not declared in this scope sketch_may28b:18: error: expected ;’ before ‘the’
sketch_may28b:20: error: expected ;' before 'minutes' sketch_may28b:22: error: expected ;’ before ‘seconds’
sketch_may28b:23: error: ‘some’ was not declared in this scope
sketch_may28b:23: error: expected ;' before 'space' sketch_may28b:24: error: expected ;’ before ‘date’
sketch_may28b:26: error: expected `;’ before 'month

I just want to active the motor each 20 minutes for examples

Looks like the compilation errors originate in the DS1307 library, and subsequently various errors are reported in your sketch because the RTC symbol hasn't been declared. Perhaps the DS1307 library you're using hasn't been updated for Arduino 1.x?

OK, "written by mattt on the Arduino forum and modified by D. Sjunnesson" is not a good way to tell others exactly what code you are using. Post the code here (I know it's not very long). There might be very easy fixes.

Hello,

It is here:
/*
DS1307.h - library for DS1307 rtc
*/

// ensure this library description is only included once
#ifndef DS1307_h
#define DS1307_h

// include types & constants of Wiring core API
#include <WConstants.h>

// include types & constants of Wire ic2 lib
#include <…/Wire/Wire.h>

#define DS1307_SEC 0
#define DS1307_MIN 1
#define DS1307_HR 2
#define DS1307_DOW 3
#define DS1307_DATE 4
#define DS1307_MTH 5
#define DS1307_YR 6

#define DS1307_BASE_YR 2000

#define DS1307_CTRL_ID B1101000 //DS1307

// Define register bit masks
#define DS1307_CLOCKHALT B10000000

#define DS1307_LO_BCD B00001111
#define DS1307_HI_BCD B11110000

#define DS1307_HI_SEC B01110000
#define DS1307_HI_MIN B01110000
#define DS1307_HI_HR B00110000
#define DS1307_LO_DOW B00000111
#define DS1307_HI_DATE B00110000
#define DS1307_HI_MTH B00110000
#define DS1307_HI_YR B11110000

// library interface description
class DS1307
{
// user-accessible “public” interface
public:
DS1307();
void get(int *, boolean);
int get(int, boolean);
void set(int, int);
void start(void);
void stop(void);

// library-accessible “private” interface
private:
byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
void read(void);
void save(void);
};

extern DS1307 RTC;

#endif

RTC.set(DS1307_SEC,1); set the seconds

Set the seconds is NOT a comment. Its rubish code!.

Mark

Replace this #include <WConstants.h> with this #include <Arduino.h> and see if it now compiles in Arduino IDE 1.x

b4f4:
modified by D. Sjunnesson

I think holmes4 is right.

I remember that name. It spells trouble. If you are a newbie, you should be using IDE 1.x and you don’t actually need any library other than Wire.h. If you need to use a library , there are better ones around than the one you’ve got.

Try this

//Arduino 1.0+ Only
//Arduino 1.0+ Only
// pre-set the time in the void then use reset button to set it!

#include <LiquidCrystal.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

LiquidCrystal lcd(8,9,A2,5,6,7);

void setup(){
  Wire.begin();
  Serial.begin(9600);
      lcd.begin(16, 2);
      lcd.clear();
  
  setDateTime(); //MUST CONFIGURE IN FUNCTION
printDate();
Serial.println("loopstart");
}

void loop(){
      lcd.clear();
  printDate();
  
  delay(1000);
}

void setDateTime(){

  byte second =      30; //0-59
  byte minute =      24; //0-59
  byte hour =        0; //0-23
  byte weekDay =     5; //1-7
  byte monthDay =    19; //1-31
  byte month =       4; //1-12
  byte year  =       13; //0-99

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekDay));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero); //start 

  Wire.endTransmission();

}

byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

  //print the date EG   3/1/11 23:59:59
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print("     ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

 
  lcd.print(monthDay);
  lcd.print("/");
  lcd.print(month);
  lcd.print("/");
  lcd.print(year);
  
  lcd.setCursor(0,1);
  lcd.print(hour);
  lcd.print(":");
  lcd.print(minute);
  lcd.print(":");
    if(second <10)
  {
    lcd.print("0");
  }
  lcd.print(second);
}

Thanks!

I'm really newbie. If anyone can help more I will me good. I will test it tomorrow about Mark.

What I want is to active the motor at 12pm and at 8pm using the Real time clock.

About the libraries, which other can I use for the Real Time Clock?

I am using the one on adafruit github. Works for me.

https://github.com/adafruit/RTClib

Liudr

I used your code, but I got this on serial monitor: q"&þÆ!¹ÆÏ@+¼F¡Q3þ?!©æ@û¼Fbæÿâ9ÎãàârÀQ4Q ?ä On each second apear it, so i think is a problem o character?

First of all, it is NOT MY CODE! Then, have you read the code before running it?

Serial.begin(57600);

Your serial port setting in the code should be the same as the setting on the serial monitor window.

Your code suggestion!

I'm newbie. Please, how do i set it?

First start Arduino IDE, then press the serial monitor button. On the bottom right corner of the window, select 38400, if you have not modified the original code. You should see the right text after these steps.

Hii everyone.

I have question, how to open servo increase by day from RTC. for example servo 1 : Day 1 = 1 Open, Day 2 = 2 Open, etc.

i was got the program to count day, now have to try the program open servo by number of days.