OPEnSLab-OSU / Loom

Arduino library for Internet of Things Rapid Prototyping in environmental sensing
GNU General Public License v3.0
26 stars 3 forks source link

[Loom 3] Adalogger Featherwing RTC (PCF8523) does not remember initialization #188

Closed kurtjd closed 2 years ago

kurtjd commented 2 years ago

Describe the bug When the RTC is first used after reset (such as by removing the coin-cell battery and putting it back in), the expected behavior of the RTC module is to either initialize the RTC with compile time or prompt the user for a custom time depending on the parameters set in the config.h file when a sketch using the RTC is uploaded and ran. On subsequent runs of the sketch, the RTC should remember it was previously initialized assuming the battery has not been removed and not re-prompt the user for a custom time/be reset at compile time.

The PCF8523 RTC module handles the first part just fine, but it does not remember that the RTC was initialized between sketch runs. This is contrary to the behavior of the DS3231 RTC module which does remember if the RTC has been initialized. After a bit of digging into library code, it appears a certain value needs to be written into a certain register of the RTC in order for it to know it has been already initialized. Looking at the current code for Loom's PCF8523 module, it does not seem like we are doing that.

After adding the code to write the specific value into the specific register, progress was made in that the RTC was able to remember that it was initialized, however it believes its time is invalid for some reason. Will have to look into this further.

Hardware in Use This was tested with a Feather M0 Basic and two different Adalogger Featherwings (in order to rule out possible hardware issue). The issue happened with both Adaloggers, so it is likely a software issue.

To Reproduce Steps to reproduce the behavior:

  1. Remove the coin-cell battery from the Adalogger then put it back in to reset the RTC
  2. Attach a Feather M0
  3. Open/create a Loom sketch that uses the PCF8523 module
  4. In the config.h section for the PCF8523 component, set the third parameter to true (for use custom time)
  5. Upload the sketch and then open the serial monitor (where you will be prompted to enter a custom time)
  6. Normally at this point the RTC is initialized and you will not be prompted again when the Feather M0 is reset
  7. However, close the serial monitor and press the reset button on the Feather M0
  8. Reopen the serial monitor and notice you will receive a message that the RTC has not been initialized and it will prompt you again
  9. Despite the RTC not losing any power (the Feather didn't even lose power) it is not remembering that it was initialized

Expected behavior See step 6 above for expected behavior.

Code This is the basic PCF8523_Custom_Time example:

#include <Loom.h>

// Include configuration
const char* json_config =
#include "config.h"
;

// In Tools menu, set:
// Internet  > Disabled
// Sensors   > Enabled
// Radios    > Disabled
// Actuators > Disabled
// Max       > Disabled

using namespace Loom;

Loom::Manager Feather{};

void setup()
{
  Feather.begin_serial(true);
  Feather.parse_config(json_config);
  Feather.print_config();

  LPrintln("\n ** Setup Complete ** ");
}

void loop()
{
  Feather.measure();
  Feather.package();
  Feather.display_data();
  Feather.pause();
}

Config

"{\
    'general':\
    {\
        'name':'Device',\
        'instance':1,\
        'interval':10000\
    },\
    'components':[\
        {\
            'name':'PCF8523',\
            'params':[11, true, true]\
        }\
    ]\
}"

Additional context This issue arises when using the current Loom 3 codebase. Unknown if this issue exists in the Loom 2 codebase as well.

kurtjd commented 2 years ago

Closed due to PCF8523 not being fully supported by Loom.