Tutorial- Weather Simulation for PWM expansion module

Would you like to help?
Share your walkthrough tutorial with others

Posts: 293
Joined: Tue Oct 25, 2011 7:39 am
PostPosted: Mon Jun 25, 2012 9:32 am
So... you want to try to implement the Weather Simulation. Thanks for trying it and I hope you enjoy it.

To do so... I assume you have Arduino open with the .INO loaded and saved as whatever you want to call it (file name is irrelevant). Let me start by trying to explain what the program does then I am going to simply copy and paste EVERY line of code from the .INO that you will NEED to edit- followed by a line by line explanation of what it is your editing and how to do it. ALL you need to do is change some numbers- thats IT. But first a description so you can see if this what you want to run.

As it exists today, the code runs as a stand alone software for the PWM OR ANALOG dimming expansion module. Although I use PWM, Roberto tells me that there is no difference between them aside from the output signal type so the code will work identically on either. By stand alone I mean that it completely takes over your PMW expansion module- it runs independently of the Main controller- it doesn't even acknowledge the fact that the main controller exists. This will evolve as we work to enable some comm etc but its not working now. It simply runs your lights, thats it- period. Sounds like its not doing much? Read on...

So, what does it do?

1) It uses your latitude and longitude position (or the position you select for you tank) to calculate the daily sunrise and sunset times. It turns on your lights (you can modify this... keep reading) at exactly sunrise, and turns them off at exactly sunset. If you use the latitude and longitude of your house the tank will turn on as the sun first appears on the horizon and turn off as the sun dips below the horizon- every day- all year- EXACTLY. If you live somewhere with 5 hours of light in the winter and 18 hour days in the summer... you might want to use your Longitude coordinates but pick a Latitude closer to the equator so your tank sees a bit more of a normal reef light cycle.

2) Once the lights "turn on" how bright are they... do I have to worry about 14 hour days and bleaching my coral... in short... its your tank so watch things if you don't like it change it! BUT... within reason, day length is not a huge concern because the program models the normal variation of solar intensity using a Cosine function. You need to tell it what the LOWEST PWM output setting is that produces flicker free light for each of your channels- and then what the HIGHEST PWM output setting is for each channel (be careful here... read this part of the code tutorial carefully to set this up correctly). Then, when the sun rises- the lights start at their flicker point and progress to their MAX intensity setting at Mid day (exactly half way between sunrise and sunset). As you transition into the second half of the day the lights go from their MAX setting to their flicker point at sunset and then shut off.... but a lot can happen to the lights while they are on... keep reading.

3) You can modify when any given string of lights will rise and set by inputting a Channel Offset value that will cause them to come on XXXX seconds prior to or after sunrise or sunset. For instance, if you have a few blue only channels you could configure it such that they stay on later than the true sunset time (when the white lights would be off... if you configured it this way). This would achieve a nice night time viewing of fluorescence etc... If your lights are set up with channels across the tank left to right, you can configure it so that the left (or right or whatever) lights come on first and set first while the other side comes on late and sets late ... so the sun rises on one side and sets to the other and channels will come on across the tank. Since light intensity changes during the day... and if you use offsets and have lights on prior to or after sunset... each channel theoretically experiences its own independent day length... and if you simply calculate the mid day point (i.e. half way through total lights on time) for each channel independently you would get odd color blends. For instance, my blue strings run 2 hours (7200 sec) longer than the whites in the evening, thus their midday point is an hour later than the whites. To avoid color blends changing through the day as whites peak, and then blues peak- while the white channels are declining, the program corrects for this and actually splits the day into two parts, morning and afternoon (for EVERY channel independently). Each channel then has an independently calculated "slope" so that EVERY channel regardless of offset values peaks at EXACTLY midday (as defined by 1/2 between rise and set without regard to offsets). In this way, your color should be pretty much constant throughout the day (as good as you can get without setting every channel to the exact same length) but you can use your channels any way you want.

4) It randomly calculates (every day a new value is chosen) if the day will be cloudy, what percentage of the day will be overcast, and the number of clouds that will be generated that day, their start and end times. You can set a parameter that controls the percent chance that any given day will be cloudy. The code I distributed will produce clouds every day (chance=100% but this can be changed), their number, their length and their time of appearance is random. Although you can set the min and max number, since they are randomly timed and the effect is nice... I have left it random. Any given cloudy day will experience between 2-10 clouds. The percentage of the day that is overcast is linked to the number of clouds in a given day- in this way days with low # of clouds do not end up with exceedingly long (if few) clouds. Thus, the length of a given cloud is random and may be as little as a few minutes or as much as perhaps 30 minutes but does not get out of hand. It can even be cloudy "after the sun has set" if you have channels that extend light significantly past the calculated sunset (for instance, my blue channels).

5) The Cloud effect is what drives this program... that and storms. A "cloud" is a period of time during which the intensity of all the channels over the tank enters a random walk- and further may be set up such that the lights "chase" each other across the tank. For instance, consider a tank with 4 channels of lights two on the left and two on the right each side has one blue and one white channel. You define a DimOrder array in which you would group the left and right channels independently (details follow with code). Then, as the cloud starts all the channels will dim to 50% of their CURRENT max intensity (this Max intensity of course will changes as the day progresses given the insolation model). Once all the lights have dimmed to 50% (in 20 seconds or so) the random walk starts. The channels you grouped together using 0's in the DimOrder array get their first random walk point and the intensity will go up or down (its random...) from their current 50% set point to whatever the walk value is (+/- 0-20% from current % intensity set point). This occurs over 400 msec as a smooth transition with lights being changed in intensity every 100 msec. Then, a new value is calculated for the walk and the old value is passed to the other side of the tank (with DimOrder values of 1) which begins its intensity change while the new value replaces the prior for the DimOrder array channels with values of 0. So... the tank basically randomly brightens and dims with one side leading by 400 msec the other, its not SUPER obvious that the lights are chasing but I think its sometimes notable and looks very pleasing to the eye. A cloud ends by ramping all channels up to their CURRENT MAX setting over a short period.

5a) As clouds begin they are randomly assigned a potential to form a storm, any given cloud may generate 0, 1, or 2 storms. Any given storm may become severe, although the potential to do so increases if the cloud occurs in the afternoon. The evolution of a cloud to a storm is somewhat complex but it usually takes at least 5-10 minutes of a cloud to actually build up the correct statistics (that are tracked internally) to trigger storm formation (if it is possible for this cloud). Two types of storms are possible, and this will also depend on your tank set up. Basically, you define in the set up which channels are "White" channels... a "storm" sets the white channels to a max intensity of 25% of their current intensity value while the blues ramp from 0-100% (0 is always the flicker point, NO LIGHTS should ever go OFF during a storm). Then a lightning strike sequence is generated when some internally tracked stats accumulate to trigger it. Lightning strike sequences produce 2-11 strikes with random durations between them of up to about 1-2 seconds, each strike is randomly intense (i.e. the intensity output of the channel settings during the strikes), and their durations are modeled based upon the duration of a real strike (although I allow ours to be a bit longer). The random walk during a storm is accelerated, every 300 msec a new value is seeded so the tank lighting moves notably faster during a storm... which is kinda cool

You can configure which channels will be utilized during a lightning strike, I use them ALL to make it intense... but you can pick and choose.

5b) Severe Storms are those storms in which lightning is much more frequent and the "White" channels are turned OFF. Thus, if you set up your WChannel array with any values of 1 (denoting a white channel) these channels will turn off during a storm, the others will ramp and strikes occur. The channels that are used to generate the lightning striked during storms (either type) are specified in your StrikeChannel array (that I briefly alluded to just prior to this). If you only have white channels, you of course would not want to enter a 1 in all positions of the WChannel Array- the tank would go dark during a severe storm but for the lightning strikes. I guess this array is misleadingly labeled... think of the WChannel array as the place to set which channels will go dark to further darken the tank during a severe storm. Of course, if you have independent blue and white channels... Try it will ALL the white channels set to 1 in the array... it looks great.

6) You have the option of configuring MoonPhase lighting for any channel. I just re-wrote this section, its now super easy to configure moon lighting... read on. For reference the code I uploaded uses channel 4 for MoonPhase lighting on my system.
Last edited by rufessor on Mon Jul 16, 2012 7:45 am, edited 2 times in total.

Posts: 293
Joined: Tue Oct 25, 2011 7:39 am
PostPosted: Mon Jun 25, 2012 1:29 pm
So... here are the relevant sections of the code you NEED to edit.

FIRST... near the top of the code there is a grouping of some Global variables the are used to set up your tank. It looks exactly like THIS

Code: Select all
//***********************************ARRAYS YOU MUST MODIFY TO MAKE YOUR TANK SET UP WORK*****************************
byte flicker[]={31,30,31,30,28,0,0,0};//need to input actual values here for flicker point on all channels in PWM expansion box
byte ChMax[]={200,220,200,220,225,0,0,0};//Incremental value (Max-flicker) above flicker you want as max intensity (!!!!!!! Light Set Point is ChMax PLUS Flicker !!!!!!)
boolean Wchannel[]={1,0,1,0,0,0,0,0}; //use 1 to designate white channel (i.e. off during storm and used for lightning).  Array corresponds to PWM channel 0-5 in order
//Array to give direction to dimming.  e.g. DimOrder[]={0,0,1,1,0,0} (cloud chase effects, just group channels you want to dim together during a cloud or storm
//as either a 0 or a 1, i.e. all left side channels are 0 all right are 1 or all front are 0 all back are 1 or whatever
//(which is zero or 1 will change who dims first).  set them all to 0 if your tank has no left/right or front/back lights.
byte DimOrder[]={0,0,1,1,1,0,0,0};
//set all channel positions that you would like to use for the lightning strike effect to 1 (0-5 are PWM channels 6,7 are Main PWM outs)- and channels with a 0 are not used in strike
byte StrikeChannel[]={1,1,1,1,0,0,0,0};
byte MoonCh[]={0,0,0,0,1,0,0,0,};//Designate channels for moon phase lighting after sunset
//**********************************DONE CHANGING THINGS HERE BUT YOU MUST CHANGE ChOffset array and Latitude, Longitude IN CalcSUN function******

Line by line summary:
byte flicker[]={31,30,31,30,28,0,0,0};
This array is sized to hold 8 channels of information-
---we are working on enabling control over the PWM channels on your controller its not in yet but the array is 8 in ---anticipation of this being implemented... so if you have these channels you can fill the array but they WILL NOT ---work as of yet.

You need to fill this array with the PWM intensity setting as a byte value from 0-255. The value should be the LOWEST setting that produces stable light (i.e. no flicker) for each channel your currently using. The ARRAY MUST HAVE 8 values. If you only have 2 channels fill those in and ZERO fill the rest of the array as I have done (I use channels 0-4 but don't have lights for 5-7 (its zero based numbering in arrays... so 1-8 channels =0-7 positions)

byte ChMax[]={200,220,200,220,225,0,0,0};
This array holds 8 values

FIll this array with the MAX values ABOVE flicker point you want your lights to achieve at "noon".
This means that the ACTUAL set point for all your channels throughout the day is this
So... if as in the example, my 0 channel has a flicker point of 31 and a ChMax value of 200 it will reach 231 as its MAX output and never go below 31 unless its set to turn off in a storm or something like that.
If you have a pair of flicker and ChMax values that add to MORE than 255 your lights will actually be set to a very very very low number.... basically they would be off.
To reiterate.
THE MAX LIGHT SET POINT IS ChMax+flicker (at paired positions, i.e. flicker position 0 + ChMax position 0)
This value CANNOT EXCEED 255. If its set to 256 I believe the result would be that your lights would go to 255 near noon and then exactly at noon would actually go to 0 or possibly 1 (which would be OFF or flickering)

boolean Wchannel[]={1,0,1,0,0,0,0,0};
This array tells the program which channels you want to designate as "white" channels. During a severe storm these channels will be turned OFF. During a regular storm these channels will be constrained to between their flicker point and flicker + 25% of ChMax... You do NOT have to have a white only channel to use this array. Just pick the channel you want to dim or turn off during a storm. But remember, its going to be set to ZERO during a severe storm...

Think about it like this.. if you have a tank with only 2 channels one on the left side and another on the right... you need to fill the whole array with 0 or part of the tank will go dark during a severe storm. On the other hand, lets say you have three.... a left a right and a whole tank... maybe you could set the whole tank channel to a 1 and the others to a 0... then they tank would loose the channel spanning the whole tank during severe storm but use the left and the right to ramp lights up and down.. it would effectively darken the tank and look more "Severe" than a standard storm. If you do have channels that work out to mostly whites, and mostly blues start by setting all the Mostly white colors to 1 and the mostly blues to 0... this will yield the effect I was trying to achieve. Remember to think of color balance. If you have channels with a lot of reds or only reds I would set them to 1 so they go off during a severe storm. Its up to you, play and see what works.
Unfortunately I do not currently have a way to make it be a storm for testing purposes so you will just have to observe one and then if you don't like it... change something and try again.

byte DimOrder[]={0,0,1,1,1,0,0,0};
This is the order that the light channels receive their dimming information during the random walk. Any channel with a 0 will dim first, then 400 msec later the channels with 1 will receive the "old" dim value and go to that while the channels with a 0 will receive new information and go to that. To best achieve this effect you probably need to have channels that are differentiated left to right across a tank, group all LEFT side channels regardless of color as either 0 or 1 and group all right side as the other. Same goes for front to back- pick front to be 0 and back to be 1 or whatever... but if you have both front and back as well as left right channels I would recommend that ALL left (regardless of front to back) be set to 0 or 1 and the rights the other. You can play here but the effect is subtle and was designed for tanks with left right discrimination of lighting channels.

byte StrikeChannel[]={1,1,1,1,0,0,0,0};
This sets up the channels that will be utilized to produce the LIGHTNING strikes. Basically, I use all channels but for my true violets. Your going for a pure WHITE blazing strike. So... if you have a bunch of reds on a channel maybe set that to 0. Anything with a 1 is used to produce the lightning strike.

byte MoonCh[]={0,0,0,0,1,0,0,0};
Pretty simple... any channel you want to use for moonlighting... enter a 1.. else it must be an 8 position array with zeros. If you simply have 8 zeros there will be NO moon lighting on over the tank. This uses the MoonPhase calculation in the ReefAngel library.

One additional thing you may need to change here... and this gets a little deeper into the code...

Search for this line exactly... it occurs twice a few lines apart in the code...

Code: Select all
byte MoonToday=MoonPhase()*0.5;//SCALE FACTOR to DIM moon setting for use with HIGH power LED as moon light

If your using a high power LED such as a true violet for moon lighting, you will want to keep that 0.5 scale factor (or maybe even make the number a little bigger like 0.6 or something) this attenuates the max PWM channel intensity to 255*0.5=127.5 (in actuality its a byte value so it would be 128). If your using purpose built moon lights that are not going to over light the tank you can remove the *0.5 part and the moon light will go from 0-255 with the moon.

Then... in the CalSun function we find this
Code: Select all
 //*********************YOU NEED TO CHANGE THESE VALUES Read instructions in their ENTIRETY and CAREFULLY change to values for your tank and geographical region***************************
        //channels 0-5 are PWM expansion board lights 6,7 are ReefAngel Controller PWM outputs
        //offsets for rise/set all values in seconds offset from calculated rise or set value (-) am offset=longer day****** (-)pm offset=shorter day)
        //array order is ch0 am offset, pm offset, ch1 am offset, pm offset etc..
        //THESE values are the number of seconds that a particular channel will be offset from the rise/set time, i.e. negative to rise earlier/set earlier
       int Choffset[]={
        // NOW SET YOUR LATIDTUDE AND LONGITUDE COORDINATES as Degrees, Minutes, Seconds of Lat and Lon
        //If Your NORTH of the equator your LONGITUDE must START with a NEGATIVE number (the rest are positive) e.g. All of North America, Europe, Russia etc are negative
        //If Your EAST of the Prime Meridian your LATITUDE must START with a NEGATIVE number (the rest are positive), e.g. Most of Europe, All of China, India, Austraila, Russia etc are negative
        latitude=dmsToSeconds(40,44,00);//United States of America- Salt Lake City, local time is -7 hours GMT
        //**********************ok now were done changing things IF YOU CHANGED the Top part of the GLOBAL variable decleration AND this... your FULLY configured and ready to load********************************************

This is VERY important-

int Choffset[]={

There are 16 positions, because were eventually going to have the ability to control 8 channels of light. Each day is broke into two parts, morning and afternoon (prior to and after exactly half way between the calculated rise and set times for your latitude and longitude.

The values are in the number of SECONDS you would like each individual channel to rise or set as compared to the actual true sunrise and sunset time for the day. The array is arranged in PAIRS of values for each lighting channel.

I.E. {0am,0pm,1am,1pm,2am,2pm etc.... 7am,7pm} using zero based numbering
SO... if I start the array with
I have told the program that I want Channel 0 of the PWM expansion box to be set to rise as
rise+(-600) or 600 seconds PRIOR to the actual sunrise time. This is the white channel on the RIGHT side of my tank, so it starts ramping up in intensity 10 minutes before "sunrise".

Here is my tank-
Ch0=right side white
Ch1=right side blue
Ch2=left side white
ch3=left side blue
ch4=Whole Tank True Violet

So- to make something rise LATER than the true value you would use a positive value. The math is the SAME for sunset... but remember that if you ADD a negative to sunset your going to get that channel to set PRIOR to the calculated sunset time... so the meaning of the +/- changes depending on if your in the am or pm designated position in the array.

So my tank does this...
lets say rise is 6 am and set is 6 pm for example.
Ch0 comes on at 5:50 am and off at 6pm (this is white and rises first on the left side of my tank)
Ch1 comes on at 5:30 am (blues first) and goes off at 7:40 pm (or so) this is the left side blue
Ch2 comes on at 6 am and off at 6:10 pm (white channel that sets last on the right side of my tank)
ch3 comes on at 5:40 am and goes off at 7:50 pm (or so) this is the right side blue
ch4 comes on at 5:24 am and goes off at 7:50 pm (or so) this is whole tank violets

I don't use 5-7 and they are all zeros in my array. THE ARRAY MUST BE ZERO FILLED TO CONTAIN 16 values.

latitude=dmsToSeconds(40,44,00);//United States of America- Salt Lake City

IMPORTANT... this is the Degrees, Minutes, Seconds of Latitude and Longitude for your location.
BECAUSE THERE ARE ONLY 180 degrees (the globe is divided between East and West and North and South) and we DO NOT have the E/W designations you MUST INDICATE THE SIGN OF YOUR LATITUDE AND LONGITUDE.

LOOK This up if you do not understand. But basically- WEST longitudes are assigned NEGATIVE values BUT ONLY ON THE FIRST DIGIT. DO NOT DO THIS (-111,-47,-00) that will FUBAR the function. ONLY indicate sign on the first digit!!!! And then South latitudes are given negative values (same rule, ONLY indicate sign on the first position).

The calculation of day length and sunrise and sunset for the latitude and longitude positions your specify has unknown behavior if you choose a region of the globe that lacks a given rise and set for the day, i.e. if its winter at the north pole the sun does not rise, or alternatively summer at the north pole yields no sunset. Its not that the calculation cannot figure that out... it does... its just that I did not bother to code in the required accuracy to get this to work since no one is going to want either situation (no lights or no dark) on a reef tank... it *may* work or it may not. The issue comes in calculating elapsed times for the rise and set... if they never happen its not going to work right. I personally would not go here... its not really designed to work for us.

MOST IMPORTANT NOTE (even more than the last one)
The calculation for sunrise and sunset (day length) is accomplished in a slightly different way than might be initially appreciated. I CONVERT all rise and set times to your local time. What I mean to say is this- if you for instance live in New York City in the U.S.A. and you input the latitude and longitude for a nice reef off the coast of south america. And if we assume that the sun rises over that bit of paradise at 7 am and sets at 7:30 pm today, what will happen to your tank is the sun will rise at 7 am LOCAL time and set at 7:30 pm LOCAL time. All the conversions are built in. This is GREAT for using any given location on the planet, you get rise and set times for that location but converted to YOUR LOCAL TIME. This SUCKS... if you wanted to choose somewhere close to you (relatively) but such that your lights would rise a few hours late and set a few hours late so that your light cycle was *shifted* from your normal day so that, for instance, you could see the tank at night.

However- if you want to shift the light cycle all you need to do is change your ChOffset array to be filled with a bunch of numbers, say you wanted to have everything happen 3 hours LATE. Just fill up ChOffset with 9800 as the base line and then put in the offsets I went through (to get left to rise first etc) on TOP of that, or alternatively subtracted from that. I would recommend that your FIRST set up your ChOffset array (which you all ready did... correct? using 0 as the base line. THEN, simply add the number of hours (of course as seconds) you want to shift the tank to EVERY number in the array, if they were negative you would subtract them from 9800 etc etc... then your light shifts 3 hours from the rise and set local time conversion for anywhere on the planet.

CAUTION HERE- The program runs on a 24 hour day (there is no alternative). SO... if you put in big positive (or negative for that matter) offsets that would push one of your channels into setting past MIDNIGHT as the number of seconds elapsed since midnight of the start of the day... it will not really work... the lights will just all turn off at midnight... they will not keep track of how much longer into the new day they should be running. EVERY DAY AT MIDNIGHT a new rise and set are calculated as elapsed seconds since midnight. If your offsets push the elapsed seconds past 84600 (a new day) the lights will just shut off and wait for sunrise of the new day and start over.
MUCH WORSE.. would be to use a large NEGATIVE offset that would push the rise time to the PRIOR day... i.e. if we did something weird, like pick a place where the sunrise was 5 am and inserted -6 hour offsets... well... sunrise would be -3600 hours from midnight. I am *NOT SURE* what will happen... it may be that at midnight you lights would just simply turn on as if they were 1 hour into the day... it may be that the negative in that variable would kill it and your lights simply would NEVER EVER COME ON PERIOD.

So...... I am ASSUMING your running a coral reef and you need 8-16 hours of daylight, and that daylight should occur AFTER midnight of the new day and END prior to midnight of the same day... just so you know. If your using this for plants or something else just pay attention. You need to perhaps figure out what the longest day length is for your given lat lon and when the latest set and earliest rise is and then make sure you offsets don't push things outside of that 84600 second window that is a 24 hour day. For 99-100% of us using this, it would NEVER happen. But- you have been warned.

Finally, the last place your *may* want to edit...
Code: Select all
//***************** to CHANGE THE chance of Clouds actually occuring on a given day************************
        byte CloudChance=100;//% Chance of a Cloud every day
        //****************************now were done- did you use a value from 0-100 without a decimal?****************

Pretty simple... I have it set to have clouds every day... it looks nice and its not hurting anything so I don't intend on changing this... but if you really want to have days without clouds... change the value to a lower number.. it should be pretty accurately the percent chance on any given day... if you use 50 about 1/2 of your days will be cloudy... Valid range =0-100

REMEMBER... if your having trouble getting this to work. PLEASE DO NOT POST HERE ASKING FOR HELP.... GO HERE viewtopic.php?f=11&t=1450 and ask your questions. I will NOT Be monitoring this tutorial.

If you have something to add to further clarify what I have stated, or have experience you want to share with set up configurations etc... please share here with your tips... but don't post code issues here. I will not be looking here for that and you will NOT get help.

Posts: 1
Joined: Wed Jul 11, 2012 9:36 am
PostPosted: Wed Jul 11, 2012 9:41 am
Thanks for this very informative tutorial on weather simulation

Posts: 293
Joined: Tue Oct 25, 2011 7:39 am
PostPosted: Thu Jul 12, 2012 12:53 pm
Your welcome-

Let me and everyone else know if your running it by posting a quick message on the .INO forum thread for this program. I think it will help others to do this knowing that its working on more than just a few systems.

Posts: 14
Joined: Wed Jul 04, 2012 7:03 pm
PostPosted: Fri Jul 13, 2012 6:54 am
This sounds AWESOME!!!! I can't wait to get it set up!
User avatar
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL
PostPosted: Fri Jul 13, 2012 10:04 am
Thanks for all the hard work! :) I have to get the LEDs and drivers first, but once I do I'll do the expansion and go to town with this!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative

Posts: 6
Joined: Thu May 24, 2012 10:25 am
Location: Nocera Inferiore
PostPosted: Tue Jul 31, 2012 8:48 am
Hello I would like to have your help for the setup program.
I understood very little. I built an LED lamp white and royal-blue. There are 8 blocks of LEDs.
Only one block is composed of white LEDs (W) and blue (B) distributed in this way [3W-2B-2B-3W-3W].
The white LEDs are operated by drivers 8
The blue LEDs are operated by 4 drivers.
I do not have any expansion pwm, but check the lamp with the two channels of PWM reefangel. So I can say that I have two channels?
If so how and what should I set in the file. Ino

Posts: 293
Joined: Tue Oct 25, 2011 7:39 am
PostPosted: Tue Aug 28, 2012 12:01 pm
Ok... sorry for the long delay, I had mentioned that I don't check this forum... so lets move this conversation to the PDE/INO discussion for this program...

But. I will clarify this point here as it is relevant to the tutorial. I thought I had mentioned this but instead of re-reading and finding this I will reiterate how this works.

This program, as it currently stands is designed to work on the dimming modules. The issue is that the weather simulation is too much code to cram into the main and leave much room for anything else. So, you cannot use this code to run lights on the Main 2 dimming channels.

However, it is relatively simple to implement comm between these modules enabling the dimming module to control the 2 dimming channels on the main, and then gain weather function from the Main outputs but I have not done that coding. I keep thinking I will work on it, but have a few other non-reef projects that are sucking 100% of my free time currently- that combined with the fact that I am not using any of the main dimming channels has kinda inhibited my working on this much.

I also am hesitant to spend any time on this as I am entirely unsure if anyone is actually using this- so working on it is not a high priority. I can send you some code that was provided to me by Roberto that can be used as a starting point in running this, but its a moot point as it requires the dimming module.

Just an FYI... there is an effort to move at least the lat/lon calculation of sunrise and sunset times from my code (which amounts mostly to code from Michael Rice) over to the main, but no weather features are included. That port is ongoing with trouble shooting but is under the how do I code section.

So to summarize, without a dimming module there is little that can be of use to you here :( Sorry!

Posts: 293
Joined: Tue Oct 25, 2011 7:39 am
PostPosted: Wed Dec 12, 2012 10:59 am
I added some mods to the code to account for those of us that use lat and lon coordinates that yield substantial yearly varaition to the light cycle. I noted that during the peak summer hours some of my corals were fading in color (bleaching) and that as I hit the middle of winter (in terms of the sun) I got better color back on some and a few were looking a little bit light starved (browning a tiny bit or reaching for the light) so I implemented a new bit of code that sets the minimum day light period to 12.5 hours and if a day has less than that amount of daylight, its adjusted to be 12.5 hours long. I add the extra time to the day assymetrically since I like to see the tank when I am home and the sunset is early (5 pm) I took 75% of the extra time and added it to the sunset time where as the remaining 25% of the required extension goes to setting the rise time earlier.

This should fix the winter light issues.

To address the summer bleaching, I simply took any day length beyond 12.5 hours and calculated the % extension of the day. E.G. if the day was supposed to be 10% longer than 12.5 hours I wrote in a routine that corrects the PWM output setting by reducing it by 10% throughout the day. If you using PWM dimming this makes sense, as the light cycle should simply provide 10% less intensity but the day will be 10% longer so overall it should be equal if you were to solve this equation (PAR/hr)*(hr/day) the number should be the same all year... which is what we need.

The code for this is running on my system now, I will not know if the summer correction to reduce PWM intensity by % day length extension is working until late july when I can see if the tank is loosing color or looking good or going darker or whatever.. but for now, the winter day length extension is working well.

Code is on the code page for this program

IF YOUR USING D TYPE dimming, you need to think about the relationship between current and output intensity. By lumens, its roughly linear over most of the dimming range for CREE LED so my code will probably work. But you might at least consider how that differs from PWM dimming if your worried. I know Lumens are not a measure of PAR... but if CREE says one XPG outputs XX lumens... and we know that the lumen output is mostly linear with drive current... proportionally reducing drive current aught to at least approximate a proportional decrease in PAR output so my guess is that as a round assumption, it should work perfectly well. Its not like its going to cause disaster, if you see the tank starting to need more light (it will be very gradual) its a simple matter of adjusting the math. I can help if the code is not clear.

Posts: 329
Joined: Fri May 17, 2013 1:35 pm
PostPosted: Sun Jun 02, 2013 6:47 am
Line by line summary:
byte flicker[]={31,30,31,30,28,0,0,0};
This array is sized to hold 8 channels of information-
---we are working on enabling control over the PWM channels on your controller its not in yet but the array is 8 in ---anticipation of this being implemented... so if you have these channels you can fill the array but they WILL NOT ---work as of yet.

You need to fill this array with the PWM intensity setting as a byte value from 0-255. The value should be the LOWEST setting that produces stable light (i.e. no flicker) for each channel your currently using. The ARRAY MUST HAVE 8 values. If you only have 2 channels fill those in and ZERO fill the rest of the array as I have done (I use channels 0-4 but don't have lights for 5-7 (its zero based numbering in arrays... so 1-8 channels =0-7 positions)

byte ChMax[]={200,220,200,220,225,0,0,0};
This array holds 8 values

im not sure what these numbers mean...i have my lights ramping and they turn on when they hit 10 and whites peak at 35 blues at 40....how does that convert to the numbers your listing i.e. 200's?

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest