Another Arduino LED light schedule sketch - Page 3
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


Reply
 
Thread Tools Display Modes
Old 11-18-2013, 02:49 AM   #31
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Thanks Benjaf!

I was able to code this quite quickly with your help. EEPROM and all.

I am now able to set the Maximum lighting value from the TFT screen, and I won't lose settings if I lose power, or reset the board.

Now...on to being able to set/alter the start time from the screen.
AquaPorn is offline   Reply With Quote
Sponsored Links
Advertisement
 
Old 11-21-2013, 02:32 AM   #32
Christophe
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2013
Location: Albuquerque
Posts: 47
Default

Cool project!

I've done my own Arduino controller specifically for a Current-USA Satellite LED+. It is IR remote controlled, and has separate channels for low-intensity RGBs and a single-channel for higher-intensity white LEDs. It has a bunch of other presets that I am not all that interested in, but the controllability is nice. Hacking the IR protocol was easy, a few other people have detailed it in another thread here in this forum. The Arduino (I used an Uno R3) uses a single PWM channel to drive an IR LED, which could be used to control multiple lights with the same program.

I use an RTC to feed a decimal hour time value to sine functions that control light intensity for each channel. The functions are parametrized such that they are 0 at the specified power-on and power-off times. The amplitude given to the functions determines how fast they ramp, and for how long they plateau at the highest value. Split photoperiods can be done also.

If you're interested in trying to adapt it, I can put up the code, let me know!
Attached Thumbnails
Click image for larger version

Name:	SplitPhotoPeriod.jpg
Views:	19
Size:	50.3 KB
ID:	237577  

Christophe is offline   Reply With Quote
Old 11-22-2013, 09:38 AM   #33
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 104
Default

Looks like an interesting solution!
By now I am really just fiddling with the serial communication between Arduino and Python client, the light scheduling is loosely based on my previous version of this sketch. It takes a while to get anywhere since I am learning Python in the process, but that was sort of the point.
The main issue is a lack of time to spend on the project!
__________________
benjaf is online now   Reply With Quote
Old 11-22-2013, 01:48 PM   #34
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Hi Benjaf...I'm here to bother you again.

I am now trying to incorporate being able to set a start time from the GUI.



How I am trying to code it is similar to how you showed me to add a variable to the intensity.

For every channel I have called it out like this:

sunMatrix[0][0][Sunset_Hr] = RiseHour;
sunMatrix[0][0][Sunset_Min] = RiseMin;
sunMatrix[0][1][Sunrise_Hr] = RiseHour;
sunMatrix[0][1][Sunrise_Min] = RiseMin;
sunMatrix[0][1][Sunset_Hr] = RiseHour;
sunMatrix[0][1][Sunset_Min] = RiseMin;
sunMatrix[0][2][Sunrise_Hr] = RiseHour;
sunMatrix[0][2][Sunrise_Min] = RiseMin;

And then in the matrix array I am trying something like this:

},{
{0, 0, (RiseHour), (RiseMin+2), 0},
{(RiseHour), (RiseMin+10), (RiseHour+12), (RiseMin+7), RBlue_max}, ////RBlue_Ch1
{(RiseHour+12), (RiseMin+12), 24, 0, 0}
},{
{0, 0, (RiseHour), (RiseMin+8), 0},
{(RiseHour), (RiseMin+14), (RiseHour+12), (RiseMin+2), Blue_max}, ////Blue_Ch1
{(RiseHour+12), (RiseMin+8), 24, 0, 0}

To avoid timing conflicts between Hours and to make sure minutes do not increase above 59.

I am unsure if the Update function is able to pick up which period the schedule is in, or if I can't use the math like I am?

I am hoping you have a suggestion for me.

Thanks!!
Steve

Last edited by AquaPorn; 11-22-2013 at 02:03 PM.. Reason: Added photo
AquaPorn is offline   Reply With Quote
Old 11-22-2013, 05:55 PM   #35
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

I am 80% sure I can't do the math within the matrix. I have changed the variable naming to:

sunMatrix[CHANNELS][0][Sunset_Hr] = RiseHour;
sunMatrix[CHANNELS][0][Sunset_Min] = RiseMin;
sunMatrix[CHANNELS][1][Sunrise_Hr] = RiseHour;
sunMatrix[CHANNELS][1][Sunrise_Min] = RiseMin;
sunMatrix[CHANNELS][1][Sunset_Hr] = RiseHour;
sunMatrix[CHANNELS][1][Sunset_Min] = RiseMin;
sunMatrix[CHANNELS][2][Sunrise_Hr] = RiseHour;
sunMatrix[CHANNELS][2][Sunrise_Min] = RiseMin;

And I am getting the Blue's....whether they ramp up/down I am unsure. But, I am guessing the white's are not coming on because I have them starting 2 hours after the blues which I designated RiseHour+2 in the matrix.

Getting closer though...
AquaPorn is offline   Reply With Quote
Old 11-22-2013, 06:03 PM   #36
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 104
Default

Actually, to do this you will have to make a few changes.
First of all, you will have to move the initialization of the matrix into a function so you can call it as many times as you want. If you do that, then you can keep it like you described above:

int lightMatrix[CHANNELS][MAXPERIODS][5];

void UpdateMatrix() {
lightMatrix = {
{0, 0, (RiseHour), (RiseMin+2), 0},
{(RiseHour), (RiseMin+10), (RiseHour+12), (RiseMin+7), RBlue_max}, ////RBlue_Ch1
{(RiseHour+12), (RiseMin+12), 24, 0, 0}
},{
...
}

Keep in mind that you have to have the definition outside the function like above!

Any time one of the variables are changed, you reinitialize the entire matrix in the easiest possible way:

UpdateMatrix();

This makes sure everything is always updated, and you have to do as little work as possible!
Hope this helps, always happy to help
__________________
benjaf is online now   Reply With Quote
Old 11-23-2013, 03:08 AM   #37
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Thanks for the help!!

I am having an issue though. It's probably due to my lack of experience. A year ago I didn't even know what Arduino was, and never had any experience writing code until 10 months ago.
So, I don't understand the compilation error I am receiving. What it means that is. My lack of vocabulary with all of this.

I made the adjustments you recommended, but it won't compile. It is giving me an error on this line

lightMatrix={

"expected primary expression before {"

I'm unsure what this means...I kind of hunt and peck a few things, but no success.
AquaPorn is offline   Reply With Quote
Old 11-23-2013, 07:35 AM   #38
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 104
Default

Without having seen your code, my guess would be that you have an unfinished line above the line reporting the error. That is the case in the majority of odd errors!
__________________
benjaf is online now   Reply With Quote
Old 11-23-2013, 02:25 PM   #39
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

I'm checking that out.

Something odd happening. I woke up in the middle of the night and all the blue LEDs were on?
This morning I turned on the LEDs to find all channels on??
Lol!

Maybe Sunday I'll have time to actually sit and sift through all the code.
At least I know something is happening. Lol!
AquaPorn is offline   Reply With Quote
Old 11-24-2013, 02:47 PM   #40
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Hi Benjaf,

I've been wrestling around with code, and I don't think I am any closer.

I posted the code on the Arduuino forum seeking help, and those guys are so f'n cryptic with their direction. The best I got was that "you can't initialize an array in that way"
"Your Declaration is correct, but your initialization is not".

Why can't they just show me??
AquaPorn is offline   Reply With Quote
Old 11-24-2013, 03:36 PM   #41
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 104
Default

Well they are like that sometimes, a lot of the more active people there assume you have quite a bit of experience in both electronics and programming.
Declaration: the 'creation' of the array ( int lightMatrix[x][x][x]; )
Initialization: creating the contents of the array ( lightMatrix = {{x},{x}}; )

But anyway, I have made a very basic sketch to show you how I meant it:
http://codebender.cc/sketch:23963
The variable names etc. are not accurate, but the idea stands.
And it works - just not in the Arduino IDE (programming environment). Arduino has quite at few quirks like that, and I keep forgetting them. I usually use Codebender because it is more 'friendly'!
__________________
benjaf is online now   Reply With Quote
Old 11-24-2013, 06:01 PM   #42
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 104
Default

If you want to make it 'Arduino IDE Compatible' you will have to replace the contents of the UpdateMatrix() function with one of these for each channel:

// Channel 1:
sunMatrix[0][0][Sunrise_Hr] = 0;
sunMatrix[0][0][Sunrise_Min] = 0;
sunMatrix[0][0][Sunset_Hr] = RiseHour;
sunMatrix[0][0][Sunset_Min] = RiseMin + 2;
sunMatrix[0][0][INTENSITY] = 0;
sunMatrix[0][1][Sunrise_Hr] = RiseHour;
sunMatrix[0][1][Sunrise_Min] = RiseMin + 10;
sunMatrix[0][1][Sunset_Hr] = RiseHour + 12;
sunMatrix[0][1][Sunset_Min] = RiseMin + 7;
sunMatrix[0][1][INTENSITY] = RBlue_max;
sunMatrix[0][2][Sunrise_Hr] = RiseHour + 12;
sunMatrix[0][2][Sunrise_Min] = RiseMin + 12;
sunMatrix[0][2][Sunset_Hr] = 24;
sunMatrix[0][2][Sunset_Min] = 0;
sunMatrix[0][2][INTENSITY] = 0;

It is a somewhat more tedious process!
__________________

Last edited by benjaf; 11-24-2013 at 06:28 PM.. Reason: Typo
benjaf is online now   Reply With Quote
Old 11-24-2013, 07:05 PM   #43
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Awesome! Awesome! Awesome!

Thank you so much for taking the time!!

One of the comments from the Arduino forum (I was trying not to bother you too much) stated I couldn't shortcut it the way I was trying to do, and I would have to initialize all the elements of the array.

But, I still had hope....

It is a tedious process, but I'm too far in to turn back now.

Thank you so much. You have full credit in my code, and shout outs on my You Tube channel and Build thread.
AquaPorn is offline   Reply With Quote
Old 11-24-2013, 07:18 PM   #44
benjaf
Algae Grower
 
benjaf's Avatar
 
PTrader: (0/0%)
Join Date: Mar 2012
Location: Denmark
Posts: 104
Default

You're welcome
While the original suggestion might be a 'shortcut', that is how it would normally be done. Why the standard Arduino compiler does not allow it is beyond me, the resulting code is a mess!
But hey, whatever works
__________________
benjaf is online now   Reply With Quote
Old 12-01-2013, 03:24 PM   #45
AquaPorn
Algae Grower
 
PTrader: (0/0%)
Join Date: May 2013
Location: Chicago Suburb
Posts: 26
Default

Thanks again Benjaf!
Got it completely integrated with my UI. Thanks for taking the time to help me out.

https://www.youtube.com/watch?v=0Ldx0fuJl8s

Last edited by AquaPorn; 12-01-2013 at 03:46 PM.. Reason: URL correction
AquaPorn is offline   Reply With Quote
Reply

Tags
arduino, diy, led

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not 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

Forum Jump


All times are GMT. The time now is 04:59 AM.


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