The Planted Tank Forum - Reply to Topic
Planted Tank Forums
Your Tanks Image Hosting *Tank Tracker * Plant Profiles Fish Profiles Planted Tank Guide Photo Gallery Articles

Go Back   The Planted Tank Forum > Specific Aspects of a Planted Tank > DIY > Another Arduino LED light schedule sketch

Thread: Another Arduino LED light schedule sketch Reply to Thread
Title:
  
Message:
Post Icons
You may choose an icon for your message from the following list:
 

Register Now

In order to be able to post messages on the The Planted Tank Forum forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in

Human Verification

In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.



Additional Options
Miscellaneous Options

Topic Review (Newest First)
02-03-2014 06:16 PM
AquaPorn I'll let you know what I find.

I'm at the Arduino forum as I don't know wether to increase or decrease the frequency of the pins.
Changing is pretty straight forward.

Truthfully, I've had nothing but issues ever since I changed out the Sainsmart clone for an actual Arduino.

Who would have thought?
02-03-2014 06:08 PM
benjaf
Quote:
Originally Posted by AquaPorn View Post
Hi Benjaf,

Ok, so I'm seriously confused now. I've been fiddling around, and I just can't get it to stop the jerky step up.
I don't understand why it's fine once, and then reverts back to stepping?
I've tried several different things: only using two channel, and I even went back to the old original sketch that I knew worked...I have video to prove it.
Nothing.

Now I'm down to blaming hardware as it is the only thing different since originally starting.
I went from a Sainsmart Mega to an actual Arduino Mega, and from LEDsee drivers to Meanwell LDDs.

I'm starting to question the PWM frequency of the Arduino board.
Do you think adjusting these would help?
At this point I think it is likely that your hardware may be playing you. My experience in the hardware field is somewhat limited so unfortunately I don't think I am the best person to help you here..
02-03-2014 04:58 PM
AquaPorn Hi Benjaf,

Ok, so I'm seriously confused now. I've been fiddling around, and I just can't get it to stop the jerky step up.
I don't understand why it's fine once, and then reverts back to stepping?
I've tried several different things: only using two channel, and I even went back to the old original sketch that I knew worked...I have video to prove it.
Nothing.

Now I'm down to blaming hardware as it is the only thing different since originally starting.
I went from a Sainsmart Mega to an actual Arduino Mega, and from LEDsee drivers to Meanwell LDDs.

I'm starting to question the PWM frequency of the Arduino board.
Do you think adjusting these would help?
02-02-2014 02:34 AM
sketch804 Gonna follow this one!
01-29-2014 05:50 PM
benjaf
Quote:
Originally Posted by AquaPorn View Post
I must be doing something wrong? It won't initialize with .SetPoint().

Using the example sketch I added 8 channels each channel has 4 periods.
It works fine with AddPoint().

I changed all periods to .SetPoint(), indexed each period 0 to 4, and then added variables risehour, risemin, color_max. With the exception of the first and last period where the intensity equals 0.
I then declared each variable with a value.

int RBlue_max =255
int rise hour = 8
ect....

And it failed to initialize. I then changed all the set points back to whole numbers to test, and it again failed to initialize using .SetPoint()

I'm missing something?? Any suggestions?
It may very well be my code that doesn't actually support this.. It was not really something I had thought of originally.

Oh well, new plan:
You initialize it just like the example with AddPoint() and set some generic times and intensities, let's call it InitializeLights(). The actual values don't matter, they will be overwritten anyway.
You then make a second function to set the actual values using SetPoint(), let's call it UpdateLights(). Since the channels are already set up elsewhere you only have to set the points this time, the channel creation with pins and such is not necessary. Example:
Code:
int channelNo = 0;
Channels[channelNo].SetPoint(0, 8, 0, 0);
Channels[channelNo].SetPoint(1, 8, 30, 255);
Channels[channelNo].SetPoint(2, 20, 0, 255);
Channels[channelNo].SetPoint(3, 20, 30, 0);

channelNo = 1;
// ... etc ...
During setup you then first call InitializeLights() to set up the basic structure and then UpdateLights() to set up the actual light values.Any time you need to rewrite the values you just call UpdateLights() again.
01-29-2014 05:02 PM
AquaPorn I must be doing something wrong? It won't initialize with .SetPoint().

Using the example sketch I added 8 channels each channel has 4 periods.
It works fine with AddPoint().

I changed all periods to .SetPoint(), indexed each period 0 to 4, and then added variables risehour, risemin, color_max. With the exception of the first and last period where the intensity equals 0.
I then declared each variable with a value.

int RBlue_max =255
int rise hour = 8
ect....

And it failed to initialize. I then changed all the set points back to whole numbers to test, and it again failed to initialize using .SetPoint()

I'm missing something?? Any suggestions?
01-28-2014 06:30 PM
benjaf
Quote:
Originally Posted by AquaPorn View Post
So, something like this

Code:
Channels[channelNo].SetPoint(1, 8, 0, 0);
Channels[channelNo].SetPoint(2, 8, 30, 255);
Channels[channelNo].SetPoint(3, 20, 0, 255);
Channels[channelNo].SetPoint(4, 20, 30, 0);
And can I use the same set points for each channel? Or, do they have to be unique?
Yes pretty much, except you start with 0 in stead of 1. The numbers are actually just the index in the Point array contained by each channel.

Quote:
Originally Posted by AquaPorn View Post
EDIT:
Ok. I see where it is initialized in setup().
I think I can just call that at my enter buttons on the LCD as well, so it is only called when a change is made?
Exactly. You use this just like the old one. Use your variables to set the correct times for each point and call it again whenever one of them changes.

And another thing. The example uses the same fade mode as the old one, where PWM is increased in a linear fashion (fademode_linear). But due to the way we perceive light this does not look linear at all. The alternative mode (fademode_exponential) attempts to compensate for this. The fademode is chosen for each channel during initialization.
01-28-2014 05:07 PM
AquaPorn Thanks Benjaf!

Ok. I had no issues getting the new sketch up and running as written with 7 channels on 4 periods(points).
No Steps!!! Just even smooth linear increasing!

Now the tricky part...the integration.

Just a couple of questions just to be clear.

SetPoint()?
So, something like this

Code:
Channels[channelNo].SetPoint(1, 8, 0, 0);
Channels[channelNo].SetPoint(2, 8, 30, 255);
Channels[channelNo].SetPoint(3, 20, 0, 255);
Channels[channelNo].SetPoint(4, 20, 30, 0);
And can I use the same set points for each channel? Or, do they have to be unique?

" Since you will be calling InitializeChannels several times"
Anything I need to change to call this function?

EDIT:
Ok. I see where it is initialized in setup().
I think I can just call that at my enter buttons on the LCD as well, so it is only called when a change is made?

Thanks!
01-28-2014 08:06 AM
benjaf I committed a small fix, you could not add points with their float intensity (0-1) as everything was treated like an int (0-255).
01-28-2014 05:39 AM
benjaf Well the good thing is you don't really need to bother with most of the stuff in the .h and .cpp files. I think the most significant change is that you have to think of the light intensity as a chart with lines connecting a bunch of points.
Regarding the whole variable thing. Since you will be calling InitializeChannels several times you need to use SetPoint() rather than AddPoint(). The only real difference is that you need to include the point number:
Code:
Channels[channelNo].SetPoint(#, 8, 0, 0);
Where # is the point number starting from 0.
01-27-2014 10:40 PM
AquaPorn Lol!! Hi buddy.

Ok. So, I'm looking over the new sketch. I'm sure I will get used to it, but it is still kind of greek to me.

Before I start trying to integrate this new sketch, and since you already know what I'm trying to accomplish, do you foresee any issues I may have?

Like using variables instead of whole numbers...stuff like that.
01-23-2014 12:45 AM
AquaPorn Thanks Ben,

I think you might be right about the code...actually I have no doubt you wouldn't steer me wrong.

Comfort...is pretty much the reason I haven't looked into changing to your new code.
I never had an issue with your original code. I understand it well, and then I put in all that effort to integrate the touch screen. I'm stubborn and was going to make work come hell or high water!

Honestly, I haven't even seen the new version with he exception of the snippets that have been posted.

I'll check it out...so be prepared!

Thanks for all the help mate!
01-22-2014 06:00 PM
benjaf
Quote:
Originally Posted by AquaPorn View Post
I changed it back to the old calculation. The new calculation with "progress" would start the lighting, but would not fade at the scheduled time.
I guess that is what I get for suggesting untested code! Oh well.. As long as the old version works for you!
Quote:
Originally Posted by AquaPorn View Post
My new thought is perhaps the "float" math...it may be taking longer to calculate due to breaking it out of the array???
I highly doubt it. Float calculations really aren't THAT expensive, but that should be fairly easy to spot if you start debugging to find out where the processing time is spent.
I am slightly concerned that the whole schedule reading is simply too wasteful when you have that many channels. The new version should be somewhat better, but I certainly understand that you don't really want to replace it
01-22-2014 05:05 PM
AquaPorn Alas Benjaf...you were right.

I'm going to have to hook it up to the serial port and try to trouble shoot it.

I changed it back to the old calculation. The new calculation with "progress" would start the lighting, but would not fade at the scheduled time.

I also found it steps on the fade as well. It just isn't as noticeable because it does fade smoothly to a point, but once it reaches that point it steps 3 or 4 times down to zero.
I can only assume this is what's happening on the ramping. It probably steps 4 times to a certain value, and then smoothed out the rest of the way.

My new thought is perhaps the "float" math...it may be taking longer to calculate due to breaking it out of the array???

Still not sure. Bottom line the code is not happy....

The search continues. I will let you know if I discover the issue.
01-20-2014 03:23 PM
Rvacinek This is a seriously great thread to read through. keep the information flowing.
This thread has more than 15 replies. Click here to review the whole thread.

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright Planted Tank LLC 2012