CONTROLLINO-PLC / CONTROLLINO_Library

151 stars 55 forks source link

Unclear if RTC alarm functionality is in 3.07 or not #52

Closed greenveg closed 6 months ago

greenveg commented 2 years ago

Both this example and the instructions here tells me that there is RTC alarm functionality implemented.

I have the latest version, 3.0.7 installed in PlatformIO / vsCode and it just gives me a standard _'ControllinoClearAlarm' was not declared in this scope when I try to compile code with Controllino_ClearAlarm() or Controllino_SetAlarm(int, int).

Downloaded the 3.0.7 source and had a look, no alarms found there either.

Am I blind/stupid or is it simply something for 3.0.8?

Thanks!

CONTROLLINO-Support commented 2 years ago

Hi greenveg!

You are right. The Alarm stuff is not in the 3.0.7. Try to manually replace the Controllino.h and Controllino.cpp files by the lates ones from the github.

And we will release the 3.0.8 in the meantime ...

Best regards, Lukas

greenveg commented 2 years ago

I pasted the slightly simplified versions of your functions (SetAlarm() and ClearAlarm()) at the bottom of my code instead, PlatformIO is such a hassle when you want to edit your library files...

Set alarm works well and as expected. Checked multiple times. ClearAlarm doesn't seem to work.

In setup I have: pinMode(CONTROLLINO_RTC_INTERRUPT, INPUT_PULLUP);

and I have this at the top of my (non-blocking) loop:

  if(digitalRead(CONTROLLINO_RTC_INTERRUPT) == LOW){
    Serial.println("Alarm triggered! Resetting...");
    _ClearAlarm();
  }

Problem: Interrupt pin keep being low, so I keep getting the "Alarm triggered! Resetting..." in my serial console.

This is my slightly simplified version of your functions (removed flag for if RTC is properly initialized):

void _SetAlarm(unsigned char aHour, unsigned char aMinute) {

    unsigned char TimeDate [2]={aMinute, aHour}; //we use a zero in the middle of the array as thats how the data are stored inside the the chip
    unsigned char i,a,b,temp;//Help variable i is used to control for cycle and a,b are used to prepare time data for the RTC chip.
    unsigned char SPISetting; // variable to hold SPI setting

        //Store SPI setting
        SPISetting = SPCR;
        // start the SPI library:
        SPI.begin();
        SPI.setBitOrder(MSBFIRST);
        SPI.setDataMode(SPI_MODE0);

        for(i = 0; i < 2;i++)
        {

            if (i == 0)    //minutes
            {
                b = TimeDate[i]/40; //get the 40s
                b = b<<6;
                a = TimeDate[i]%40; // get the rest
                temp = a/20; //get the 20s
                temp = temp<<5;
                b = b+temp;
                a = a%20; // get the rest
                temp = a/10; //get the 10s
                temp = temp<<4;
                b = b+temp;
                a = a%10; // get the rest
            }

            if (i == 1)    //hours
            {
                b = TimeDate[i]/10; //get the 10s
                b = b<<4;
                a = TimeDate[i]%10; // get the rest

            }
                TimeDate[i]= a + b;   
                Controllino_SetRTCSS(HIGH);
                SPI.transfer(i + 0x19); //0x19 is starting address for write 
                SPI.transfer(TimeDate[i]);
                Controllino_SetRTCSS(LOW);
            }
        Controllino_SetRTCSS(HIGH);
        SPI.transfer(0x11); //0x11 is starting address for control2 write 
        SPI.transfer(B00010010); // enable alarms
        Controllino_SetRTCSS(LOW);
        //Return the SPI settings to previous state
        SPCR = SPISetting;

}

void _ClearAlarm() {
    unsigned char SPISetting; // variable to hold SPI setting

        //Store SPI setting
        SPISetting = SPCR;
        // start the SPI library:
        SPI.begin();
        SPI.setBitOrder(MSBFIRST);
        SPI.setDataMode(SPI_MODE0);
        Controllino_SetRTCSS(HIGH);
        SPI.transfer(0x11); //0x11 is address for control2 write 
        SPI.transfer(B11110101); // clear alarms
        Controllino_SetRTCSS(LOW);
        //Return the SPI settings to previous state
        SPCR = SPISetting;
}
greenveg commented 2 years ago

Another note: In your RTC example you have a slight error on row 76 I think:

if (digitalRead(CONTROLLINO_RTC_INTERRUPT) = 1)

Pretty sure it should be == 0 since you also have it on a pullup in the same example: pinMode(CONTROLLINO_RTC_INTERRUPT, INPUT_PULLUP);

CONTROLLINO-Support commented 2 years ago

Thanks a lot! The Alarm stuff is not a code from the CONTROLLINO team and it was commited by an external contributor. It seems that it has to be bugfixed before we can release it in 3.0.8.

greenveg commented 2 years ago

Alarm and timer functionality would be super helpful!

Ping @Columbo818, looks like it's you who perhaps know why ClearAlarm() is not working?

Columbo818 commented 2 years ago

Good catch @greenveg - I'm at work at the moment but will sort a bug fix once I'm home and can test.

@CONTROLLINO-Support I implemented this because you hadnt. I was hoping you'd take my code and move forwards with it, but from what I can see you've just left it as-is, and havent released any updates since.

Your software is lacking core features and demos, and your definition of "open source" seems to be "contact us and we'll decide if you're worthy" - Its very disappointing, and is why I dont use a Controllino anymore.

greenveg commented 2 years ago

Bump @Columbo818 🙂

I tried having a look at what datasheet for the RTC module says about setting and clearing alarms to see if I could sort it out but these waters are too deep for me I'm afraid 😅

Mr-Bart-Simpson commented 1 year ago

As the discussion here goes a bit into bugfixing the alarm funcs in the lib, I'd like to add another comment here.

First of all, I have to mention, that I'm not a experienced C/C++ developer (my background is more on C#...) and therefore, this may or may not be a real issue!

When directly including the source into my project (using PlatformIO in Visual Studio Code), I get a warning on the Controllino_SetAlarm() func.

char Controllino_SetAlarm(unsigned char *aHour, unsigned char *aMinute) {   
    unsigned char TimeDate [2]={aMinute,aHour};
...

The warning states, that the assignment of the TimeDate array is a problem, because a value of type "unsigned char *" cannot be used to initialize an entity of type "unsigned char"

greenveg commented 1 year ago

Bump! Is this fixed yet? Any timeline for a 3.0.8 release? I'm debating if I should buy more Controllinos or try one of your competitors (mostly for fun, I've used Controllinos since 2017 and still love them)

CONTROLLINO-Support commented 1 year ago

I am sorry for the delayed 3.0.8 Release. We were doing some personal changes here. It should be done in the next two weeks.

Columbo818 commented 1 year ago

@greenveg https://github.com/CONTROLLINO-PLC/CONTROLLINO_Library/pull/59

pmmarquez commented 8 months ago

Is #59 fixing the issue @greenveg and @CONTROLLINO-Support ? if so we include #59 on the next release