Heliostat: Integrating RTC DS3231 and SunPosition Library

Hi Everyone,

So I am creating a heliostat am doing it by integrating 2 50cm long linear actuators which I will use to move the mirror instead of stepper motors as I already have them at home. I have thought of using Inertial Measurement Units(IMU) to give me the data of the Altitude and Azimuth of the mirror along with the location of the heliostat but am not sure if they are the right sensors to use.

I am using the library SunPosition.h library by Ken Wilmot to get teh azimuth and altitude of the sun and DS3231 Lib by Rinky Dinky electronics for my RTC clock

I want to know the altitude and the azimuth of the Sun at real time and that is why I am trying to integrate a RTC with the SunPosition Library code. I'm a beginner coder so am struggling to write the code.

How do I ge the Sun Position using the RTC (DS3231). any help will be greatly appreciated

#include <DS3231.h>
#include <SolarPosition.h>

DS3231 rtc(SDA,SCL);
// number of decimal digits to print
const uint8_t digits = 3;
Time t;
// some test positions:
SolarPosition Toronto(43.653109, -79.386304);  // Toronto, Canada


// program begins

void setup()
{
  Serial.begin(9600);
  Serial.println(F("\tSolar Position Demo"));
t = rtc.getTime();
  // set the Time service as the time provider
  SolarPosition::setTimeProvider(rtc.getTime());      //I AM CONTINUOUSLY GETTING A ERROR HERE
}

void loop()
{
  // now test the real time methods:
  //
  printTime(RTC.get());

  Serial.print(F("Toronto:\t"));
  printSolarPosition(Toronto.getSolarPosition(), digits);
  Serial.println();

  delay(15000);
}

// Print a solar position to serial
//
void printSolarPosition(SolarPosition_t pos, int numDigits)
{
  Serial.print(F("el: "));
  Serial.print(pos.elevation, numDigits);
  Serial.print(F(" deg\t"));

  Serial.print(F("az: "));
  Serial.print(pos.azimuth, numDigits);
  Serial.println(F(" deg"));
}

// Print a time to serial
//
void printTime(time_t t)
{
  tmElements_t someTime;
  breakTime(t, someTime);

  Serial.print(someTime.Hour);
  Serial.print(F(":"));
  Serial.print(someTime.Minute);
  Serial.print(F(":"));
  Serial.print(someTime.Second);
  Serial.print(F(" UTC on "));
  Serial.print(dayStr(someTime.Wday));
  Serial.print(F(", "));
  Serial.print(monthStr(someTime.Month));
  Serial.print(F(" "));
  Serial.print(someTime.Day);
  Serial.print(F(", "));
  Serial.println(tmYearToCalendar(someTime.Year));
}

What error there? Is it failing to compile or doing something wrong when executed?

At a glance you appear to be using the solar position stuff as in the examples. If your sketch is working, post the results.

a7

Please do not cross post.

Hi,

So I'm trying to integrate a RTC (DS3231) clock to give me the real time of a place and feed that data into a sun position calculator (SunPosition lib by Ken Willmott) to give me the location of the sun in real time.

I'm very new to coding in Arduino and am struggling to write the code. Could you please help me

Have you looked at the examples with the library ?
There is even one called solarTimeRTC which sounds promising ?

That is a rather complex project for a beginner.

We strongly recommend to start with the simple examples that come with the Arduino IDE, to learn the special features of Arduino, and to work your way up.

@sroy10

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

Thank you.

You need to change ‘#include <arduino.h>’ to ‘#include <Arduino.h>’ in SolarPosition.h in /libraries/SolarPosition-master/.

Also your clock has to be in UTC.

Hi,

The sketch isn't working and the error message I am getting is this

image

Please copy the full error message using the "Copy error message" button in the IDE and post it here in code tags

Hi,

I am not a complete beginner to Arduino but I am not the best programmer. This is project I am doing for university so there is no returning back from here. Any help from you would be really appreciated

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
solarTimeRTC.ino: In function 'void setup()':

solarTimeRTC:22:45: error: invalid use of void expression

SolarPosition::setTimeProvider(rtc.begin());

                                         ^

solarTimeRTC.ino: In function 'void loop()':

solarTimeRTC:30:29: error: too many arguments to function 'void printTime()'

printTime(rtc.getTimeStr());

                         ^

solarTimeRTC.ino:55:6: note: declared here

void printTime()

  ^~~~~~~~~

solarTimeRTC:34:22: error: 'Toronto' was not declared in this scope

printSolarPosition(Toronto.getSolarPosition(), digits);

                  ^~~~~~~

exit status 1

invalid use of void expression

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Take a look at the examples that come with the library. They'll show you how to use setTimeProvider.

As it happens, I was just in the process of posting a complete, fully functional heliostat project. If you use this for your university project, of course you will give due credit to all the contributors and code sources.

1 Like

Thank you, I had a look at your work and its fantastic. However, I'll be using linear actuators and an IMU for my project.

You mention that for long time tracking I want to add an RTC. So that is where I am stuck at. Could you assist me as to how to use the DS3231 library to and the azimuth and altitude of the Sun using the SunPosition lib

Yes I am working on how to make the solarTimeRTC working. This post is about that example

It would have been helpful to know that from the start

Hi Everyone,

I've fixed the issue. Turns out I was using the wrong DS3231 library from the start. So you need to use the library that is in te original solarTimeRTC code to make it work!

that looks very professional, and awesome.

Perhaps. But the library doesn't lock you in to a particular RTC library. It only requires that you include some RTC library and set that libraries 'now()' method as the time sync provider. It does however, depend on the DateTime library for that kind of usage.

So it should be very easy to modify solarTimeRTC to work with any RTC library, including the Rinky Dink Electronics one. You just need to use the correct functions that belong to that library. You are using functions that belong to a different library, that is the source of your errors.