Author Topic: RTC Modul DS3232  (Read 4696 times)

Wolfgang

  • New Member
  • *
  • Posts: 12
    • View Profile
RTC Modul DS3232
« on: April 20, 2014, 03:31:10 AM »
Hi all, hi Gabriel,

after finishing my Test Assembly I figured out , that my RTC Modul DS3232 does not work with the Mega_SunTracking_Heliostat_Program_V098.
This modul is more accurate and should be 100% compatible to the DS1307, but is isn't.
I found a library for the DS3232 and with the included example program it works as expected.
Then I changed the "#include-Statement" to the new library without no luck. After reading the according code I found differences which I am not able to change to get this little beast working with Mega_SunTracking_Heliostat_Program. It would be nice if anybody will have a look at the library written by JChristensen at https://github.com/JChristensen/DS3232RTC or can explain another way to use this modul.

thanks in advance


Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 654
    • View Profile
Re: RTC Modul DS3232
« Reply #1 on: April 22, 2014, 01:48:58 PM »
Hi Wolfgang,

That's weird that the library already in the Sun Tracking Program doesn't work. I use the DS3231 RTC chip without problems, but I guess maybe there is some slight difference with the DS3232 chip?

Anyway, if RTC_Code.h library isn't working, then you should be able to replace it with the one you mentioned. I don't have one to test on, but I'm assuming that you would have to do something like this.

First replace #include "RTC_Code.h" with #include <DS3232RTC.h> like you said.
 
Then find this code near the top of the void loop.
Code: [Select]
  int month, year, day, dayOfWeek;
  float hour, minute, second;
  byte secondRTC, minuteRTC, hourRTC, dayOfWeekRTC, dayOfMonthRTC, monthRTC, yearRTC;
   
  RTC_Code::getDateDs1307(&secondRTC, &minuteRTC, &hourRTC, &dayOfWeekRTC, &dayOfMonthRTC, &monthRTC, &yearRTC);
  if (joystickModeOnOff!=1){
  Serial.println(" ");   
  Serial.print("Time: ");
  RTC_Code::printtime(hourRTC, minuteRTC, secondRTC, monthRTC, dayOfMonthRTC, yearRTC, dayOfWeekRTC);//Displays the RTC time
  delay(500);
  }

 
  //The variables below can be set to accept input from devices other than an RTC.
  dayOfWeek=dayOfWeekRTC;//NOT CURRENTLY USED
  year = yearRTC;//NOT CURRENTLY USED
  month = monthRTC;
  day = dayOfMonthRTC;
  hour = hourRTC;
  minute = minuteRTC;
  second = secondRTC;


And replace it with something like this.


Code: [Select]
  int month, year, day, dayOfWeek;
  float hour, minute, second;
  tmElements_t tm;

  if (joystickModeOnOff!=1){
  Serial.println(" ");   
  Serial.print("Time: ");


    RTC.read(tm);
    Serial.print(tm.Hour, DEC);
    Serial.print(':');
    Serial.print(tm.Minute,DEC);
    Serial.print(':');
    Serial.println(tm.Second,DEC);

  delay(500);
  }

 
  //The variables below can be set to accept input from devices other than an RTC.

  year = tm.Year;//NOT CURRENTLY USED
  month = tm.Month;
  day = tm.Day;
  hour = tm.Hour;
  minute = tm.Minute;
  second = tm.Second;

Like I said, I don't have the chip to test this with, but it should at least get you on the right track.

Good Luck!


Wolfgang

  • New Member
  • *
  • Posts: 12
    • View Profile
Re: RTC Modul DS3232
« Reply #2 on: April 23, 2014, 12:07:50 PM »
Hi Gabriel
thanks for your response and effort.
After fiddling around the hole day, I discover that the chip on my module was DS3231N and not DS3232 as assumed. But I think, that's not the problem. I tried different Librarys without luck. It seems that there is an connectivity problem cause I never could set the time even not with your modified "Set_RTC_time".
You told me, that you use the same chip without problems. I am now interested to know, if my modified SET_RTC_Time is working with your chip. Please  have a look at the attached file.


Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 654
    • View Profile
Re: RTC Modul DS3232
« Reply #3 on: April 24, 2014, 06:17:03 AM »
Hi Wolfgang,
If it really is the same chip, than you really shouldn't need to change the library. Do you have direct links to the RTC and Arduino you bought. I want to check something real quick.

Wolfgang

  • New Member
  • *
  • Posts: 12
    • View Profile
Re: RTC Modul DS3232
« Reply #4 on: April 24, 2014, 09:24:09 AM »
Hi Gabriel

RTC bought at 12/02/13 at ebay
http://www.ebay.de/itm/DS3231-AT24C32-IIC-Real-Time-Clock-Memory-Modul-RTC-Arduino-AVR-UNO-ARM-PIC-/300938684376?pt=Bauteile&hash=item461157e7d8

Arduino bought  12/06/13 
It seems that the dealer did not sell anymore Arduino stuff.
But here is the link to the ebay-shop

http://stores.ebay.de/LinkDelight-Photography-DE-Shop/Store-Home.html








Wolfgang

  • New Member
  • *
  • Posts: 12
    • View Profile
Re: RTC Modul DS3232
« Reply #5 on: April 25, 2014, 09:32:06 AM »
Hi Gabriel
after receiving a new DS1307 modul which also does't  work I could solve the problem with changing
SDA & SCL Pins from Analog5/6 Pins to Communication PINs 20/21 of my Mega 2560 R3 which has a different Pin - layout for the TWI communication.
Even though RTC was working correct now , long & Lat & timezone have there right values it seems that the
Heliostat Program miscalculate the suns position.

>Datum: 25.4.2014
Latitude: 15.57 Longitude: 57.02 Zeitzone: 1.00
Sun's Alt: -47.138
Sun's Az: -74.951
Number of Machines 1
Machine Number 0
Resetting
Zeit: 18:23:47
<
I'm sure you can solve this problem!

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 654
    • View Profile
Re: RTC Modul DS3232
« Reply #6 on: April 25, 2014, 07:47:24 PM »
Oh, the SDA and SCL pins were my first guess, but I thought I read that it was working with the other library which would mean that it was wired correctly? Oh well, at least it's working now.

If the calculated values aren't correct, then your input is probably wrong somewhere.
Unless you live in the middle of the Arabian sea, then it looks like your latitude and longitude values are mixed up. :)

If that's not it, let me know approximately where you live, and I'll check some things.

Wolfgang

  • New Member
  • *
  • Posts: 12
    • View Profile
Re: RTC Modul DS3232
« Reply #7 on: April 26, 2014, 02:26:48 AM »
Gabriel, thanks for your patience,
as you told me, if the chip I use is the same as yours, I should have nothing to change within the codes.
So I use now exact the files which are located in Mega_SunTracking_Heliostat_Program_V098.zip

and that's what I get:
 
Time: 11:0:9  4/26/14  Day_of_week:6
Time: 11:0:10  4/26/14  Day_of_week:6
Sun's Alt: -47.138
Sun's Az: -74.951
Number of Machines 1
Machine Number 0

I live at Position north
 latitude = 15.57;
 longitude = 57.02;
 timezone = +1;


btw:     Navigation with joystick is OK and it seems, that in manual mode everything work as expected. :)
           if I switch back to automatic mode , nothing happend :'(

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 654
    • View Profile
Re: RTC Modul DS3232
« Reply #8 on: April 26, 2014, 04:31:59 AM »
North of what though? Europe? If yes, then your coordinates should be
 latitude = 57.02;
 longitude = 15.57;

instead of

 latitude = 15.57;
 longitude = 57.02;

I think nothing is happening when you switch back to automatic mode because the sun's altitude is a negative value, which would mean that it is nighttime. I wouldn't expect anything to happen when you switch back. At least not until morning.

Wolfgang

  • New Member
  • *
  • Posts: 12
    • View Profile
Re: RTC Modul DS3232
« Reply #9 on: April 26, 2014, 07:59:24 AM »
Oh yeah - what a stupid mistake - excuse-moi!
After everything is working now,  I'll watch the function for a longer period and I hope that I never had to bother you again.  ;D

thanks for your help.

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 654
    • View Profile
Re: RTC Modul DS3232
« Reply #10 on: April 26, 2014, 06:21:30 PM »
Awesome! Glad it's working. You can totally bug me again if you want. :) You should at least share a picture or something of your machine when it is finished. :)