Relay schedule in internal memory

Do you have a question on how to do something.
Ask in here.

Posts: 9
Joined: Fri Mar 09, 2018 10:48 pm
PostPosted: Thu Apr 05, 2018 10:34 pm
I have ports 4 and 5 on my relay connected to my skimmer and UV. I want them to run on different schedules and I would like to be able to adjust those schedules without having to reprogram the RA+ each time. I thought I could do this by saving the schedule values in the internal memory. I set them both up with the Time Schedule radio button in the wizard and change the time schedule to what I need (more or less skimmer runs daytime and uv at night). Everything compiles fine and uploads to the RA. However, when I look in the uapp at the memory i only see one set of 4 memory locations for the on/off hour and minute for StdLights. How do I access the memory for the second set of schedule values that I set in the wizard if I want to change them? Thanks.

Posts: 12226
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Fri Apr 06, 2018 3:26 pm
You will have to use custom memory locations.
Roberto.
User avatar
Posts: 2737
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Fri Apr 06, 2018 5:30 pm
couldn't he just use the metal halide locations and that function?

Sent from my XT1585 using Tapatalk

Posts: 12226
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Fri Apr 06, 2018 5:49 pm
I don't think the uapp offer custom memory locations.
He can do that if he uses your Android app.
Roberto.

Posts: 9
Joined: Fri Mar 09, 2018 10:48 pm
PostPosted: Fri Apr 06, 2018 8:12 pm
Yeah sorry, I'm using the android app and I can read/set memory locations from that. Once I knew what to search for from Roberto's post I found some old posts with people trying to do the same thing. I think i can piece it together from that. Will let you know!
User avatar
Posts: 2737
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Sat Apr 07, 2018 7:28 am
careefer wrote:Yeah sorry, I'm using the android app and I can read/set memory locations from that. Once I knew what to search for from Roberto's post I found some old posts with people trying to do the same thing. I think i can piece it together from that. Will let you know!
awesome. give that stuff a try and let us know if you need any further help or "tweaks".

Sent from my XT1585 using Tapatalk

Posts: 9
Joined: Fri Mar 09, 2018 10:48 pm
PostPosted: Sat Apr 07, 2018 11:12 pm
OK, done. Actually fairly simple but thought I would document in detail here for those looking for the same thing later.

1. Create a new CustomMemVars.h file which is included into Globals.h. This contains the memory locations for the on hour and minute and off hour and minute for each relay. I put these starting at 110-113 for Relay 1, 120-123 for Relay
2 and so on. The first few lines look like

Code: Select all
#define PortTimerStart 110
#define Port1TimerOnHour   PortTimerStart
#define Port1TimerOnMin   PortTimerStart+1
#define Port1TimerOffHour   PortTimerStart+2
#define Port1TimerOffMin   PortTimerStart+3
#define Port2TimerOnHour   PortTimerStart+10
#define Port2TimerOnMin   PortTimerStart+11
#define Port2TimerOffHour   PortTimerStart+12


create new functions within InternalEEprom.cpp that read and write to each of these memory locations. Here are a couple of examples. Just pass the relay id for reads and the relay id and a value for writes. For the other memory locations the other functions add 1, 2 and 3 to the calculated memory position respectively.

Code: Select all
uint8_t InternalEEPROMClass::PortTimerOnHour_read(const uint8_t relayid)
{
    return read((PortTimerStart+(10*(relayid-1))));
}
void InternalEEPROMClass::PortTimerOnHour_write(const uint8_t relayid, const uint8_t value)
{
    write(PortTimerStart+(10*(relayid-1)), value);
}


3. Protoype the above funcitons in InternalEEPROM.h

4. Edit InitialInternalMemory.ino which is in the examples to set the values you would like. This step is optional since you can use the android app after the fact to edit the values directly. but e.g.

Code: Select all
  // set initial values for relay on off schedule as needed
    // Port 4 is the skimmer
    InternalMemory.PortTimerOnHour_write(4, 7);
    InternalMemory.PortTimerOnMin_write(4, 0);
    InternalMemory.PortTimerOffHour_write(4, 19);
    InternalMemory.PortTimerOffMin_write(4, 0);


5. Edit your sketch to use the StandardLights function to pull the time values in like:
Code: Select all
    ////// Place your custom code below here
    ReefAngel.StandardLights( Port4, InternalMemory.PortTimerOnHour_read(Port4), InternalMemory.PortTimerOnMin_read(Port4), InternalMemory.PortTimerOffHour_read(Port4), InternalMemory.PortTimerOffMin_read(Port4));
    ReefAngel.StandardLights( Port5, InternalMemory.PortTimerOnHour_read(Port5), InternalMemory.PortTimerOnMin_read(Port5), InternalMemory.PortTimerOffHour_read(Port5), InternalMemory.PortTimerOffMin_read(Port5));
    ReefAngel.StandardLights( Port7, InternalMemory.PortTimerOnHour_read(Port7), InternalMemory.PortTimerOnMin_read(Port7), InternalMemory.PortTimerOffHour_read(Port7), InternalMemory.PortTimerOffMin_read(Port7));
    ////// Place your custom code above here


6. Either:
Compile and upload the InitialInstallMemory.ino sketch to setup internal memory then compile and upload the actual sketch
OR
I found it easier to run the wizard and just leave the ports off that i wanted to have use the new timers. That way I got a sketch file that was almost what I needed. I then did the first wizard upload which sets the internal memory values (for everything but your new locations) but rather than doing the second upload of the actual compiled sketch from the wizard I compiled a new sketch with the the lines from step 5 swapped in and uploaded that. If you do it this way your internal memory should get set up with all the values you want for most of the parameters and you will just need to go in and manually write the values for your new timer memory locations via the android app.

This is probably not the most robust or elegant way to do this and some or all of these changes may disappear with library updates. What can I say, old scientific computing habits of just doing whatever gets the job done are hard to break! On the other hand its not that many lines of code to copy and paste back into the needed files.
User avatar
Posts: 2737
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Mon Apr 09, 2018 6:13 am
Nice. However, like you stated, your changes will be lost with any library upgrade. I would suggest you doing what I have done and place your changes inside your code file (so it's all in one place and easy to locate/update/etc).

I'm attaching my INO file for you to read through and look at.

I defined my custom memory locations towards the top of the file, created the function prototypes towards the top and then created the functions at the bottom of the file. I created my own function to read the memory locations (it's simply just a copied function from the libraries).
Here's the memory reading function:
Code: Select all
uint8_t CustomRead(int address)
{
#if not defined __SAM3X8E__
    return eeprom_read_byte((unsigned char *) address);
#else
    return SPIEEPROM.Read(address);
#endif
}

void CustomWrite(int address, const uint8_t value)
{
    if (CustomRead(address) != value )
    {
#if not defined __SAM3X8E__
        eeprom_write_byte((unsigned char *) address, value);
#else
        SPIEEPROM.Write(address, value);
#endif
    }
}


In addition to these change, I created a memory function that validates the values stored in the custom memory locations and if they are outside of it, it simply updates them with some sensible defaults (you could easily do that for yours). The function is called checkCustomMemoryValues().

All the changes you made will work and can easily be consolidated into your INO file.
You don't have to do these things. Just thought I'd share more info with you.

Good job! :D

Posts: 9
Joined: Fri Mar 09, 2018 10:48 pm
PostPosted: Mon Apr 09, 2018 5:28 pm
Very cool. I didn't realize you could do all that stuff within the ino file as well. I am familiar with cpp stuff, but the arduino side is new to me. Thanks for the follow up!
User avatar
Posts: 2737
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Mon Apr 09, 2018 6:00 pm
Forgot to attache my file.
Attachments
_75G_Tank.ino
(12.46 KiB) Downloaded 36 times

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 3 guests

cron