Dstroy's NEW grow journal

ANC

Well-Known Member
Never worry too much about getting everything perfect. Worry about not doing.You are just laying the groundwork for growing even better weed down the line.
 

dstroy

Well-Known Member
I've had some time to work on the code for the garden. I'm self-taught, and wrote all of this on my own after quite a bit of research.

Now I can easily change the on/off time for the lights, and how long they are on for.

Default is 12/12 for flowering and 18/6 for vegging.

It works by setting up the on/off times in the Switches() function.

The light timer function is much easier to read and understand now I think.

Feel free to cut/paste and repurpose for your own use.

It's very stable, and has run for longer than 60 days (I've got a run time counter that keeps track of how long it's been since it was last reset), and memory usage when compiled is claimed to be 953 bytes (11% of the mega's 8k).

That said, if you have questions I will answer them to the best of my knowledge.
 

Attachments

dstroy

Well-Known Member
12/21/17

Day 53 of flowering for the BB

aero res
pH 5.8
ppm 810
temp 68f

flower tent has been kept from 39-43%RH, veg tent from 45-55%RH. temps are about 68 in the tent at night, unless the dehumidifier is running (outside the tents) then it's 72f. lights on temps are 75-77f
 

Attachments

SSGrower

Well-Known Member
I just changed my program a little.

Now it turns on the vacuum pump to recover any nutrient solution right after the spray nozzles turn on.

The pump is on for 30 seconds, and the vacuum chamber opens for 30 seconds, this happens every 180 seconds.

No more water on my roots, not even a little bit.
I have not yet seen how you accomplish your automation, in full, I see the microprocessor and relays but am curios what you mean when you say you changed the program? Are you writ g control code or do youmean you just changed a few input parameters. Is it an off the shelf unit? Arduino? RasPi?
 

dstroy

Well-Known Member
I have not yet seen how you accomplish your automation, in full, I see the microprocessor and relays but am curios what you mean when you say you changed the program? Are you writ g control code or do youmean you just changed a few input parameters. Is it an off the shelf unit? Arduino? RasPi?
It's ran by an arduino mega 2560.

I wrote the code, and put it in the zip file that I attached a few posts ago. Feel free to poke around in it to see what it looks like, took me a while to get everything working the way I wanted it to.

I'm not sure what you mean by how I accomplish my automation though. What did you want to know?
 

SSGrower

Well-Known Member
It's ran by an arduino mega 2560.

I wrote the code, and put it in the zip file that I attached a few posts ago. Feel free to poke around in it to see what it looks like, took me a while to get everything working the way I wanted it to.

I'm not sure what you mean by how I accomplish my automation though. What did you want to know?
That is basically what I meant, I'm happy to look at your code and would ask you to look at mine? I can pm you or post here your choice.

Many questions about how to program and interface with sensors still, and I'm using an uno r3 to control things.
 

dstroy

Well-Known Member
That is basically what I meant, I'm happy to look at your code and would ask you to look at mine? I can pm you or post here your choice.

Many questions about how to program and interface with sensors still, and I'm using an uno r3 to control things.
You can post it here, that's ok with me. Plus it might help others in the future.

Just put it in a zip file and attach it to your reply.
 

SSGrower

Well-Known Member
You can post it here, that's ok with me. Plus it might help others in the future.

Just put it in a zip file and attach it to your reply.
you are doing a lot of type of things like pulling real-time status information of devices that I am looking to add more of.

You seem to handle the passing of a day (time 23:59 to time 0:00) much the way I originally envisioned but could not figure out how to make the code work when the user wanted to run lights on at night (i.e. on at 4pm off at 10am) so I went a different route..

My most current code (rev5load4) has a lot of things commented out because I believe I have an issue with the power supply on the r3 not being sufficient to power my 8 channel relay when more than 6 relays are called to be on.

I don't want to start a growing debate but I am currently experimenting with a 20 hour day and the code I use for that is Rev5shortenday.

I particularly find the control logic for your HPA system confusing and intriguing because that technique is completely foreign to me but one of the main objectives that I have with the code I am writing is to make it easy for the end user to customize to their needs.
 

Attachments

Last edited:

dstroy

Well-Known Member
you are doing a lot of type of things like pulling real-time status information of devices that I am looking to add more of.

You seem to handle the passing of a day (time 23:59 to time 0:00) much the way I originally envisioned but could not figure out how to make the code work when the user wanted to run lights on at night (i.e. on at 4pm off at 10am) so I went a different route..

My most current code (rev5load4) has a lot of things commented out because I believe I have an issue with the power supply on the r3 not being sufficient to power my 8 channel relay when more than 6 relays are called to be on.

I don't want to start a growing debate but I am currently experimenting with a 20 hour day and the code I use for that is Rev5shortenday.

I particularly find the control logic for your HPA system confusing and intriguing because that technique is completely foreign to me but one of the main objectives that I have with the code I am writing is to make it easy for the end user to customize to their needs.
Figuring out how to make a light timer that doesn't break when the day rolls over to 0 was very counter-intuitive for me as well, but I'm happy to report that both of those work equally as well.

You should power your relay board with a separate power supply, the output pins for the uno are only supposed to do like 20mA per pin normally (40mA max I think)

Yeah, can't really do without an RTC they're really handy. I use real time extensively, the system time is synchronized with the RTC every so often because if not the system time is subject to drifting several seconds per day depending on temperature.

So, if your program is long and you are running a bunch of different functions it is a good idea to snapshot the time at the beginning or near the beginning of your loop(), you do that by putting the time into one variable that all the different functions you call use, because different functions use different amounts of clock cycles and things can get screwy if you don't do this.

I'm a novice, and don't know what reducing the day to 20 hours does but if it works for you then great. I don't grow stellar shit yet bro, still learning.

I'll explain how the HPA functions work, this is a state machine, it "remembers" its' last position and only calls digitalwrite() if it needs to because calling digitalwrite is easier than manipulating pins directly but it uses a lot of clock cycles so it's better if we don't call it every time we go through the function.

void hpasolenoid1() //function call
{
if ((t - HPA1timer) > sprayinterval) //if the current time "t" minus the last time that the sprayers were on is greater than the time that is supposed to pass before they spray THEN
{
HPA1spray = true; //set the spray flag to true (this ultimately is what turns on/off the solenoids)
HPA1timer = t; //set the function timer (HPA1timer) to the current time (t)
}
if (((t - HPA1timer) >= sprayduration) && HPA1spray == true) //if the current time minus the function timer (HPA1timer) is greater than OR equal to the amount of time to spray AND they are flagged to be spraying
{
HPA1spray = false; //turn the sprayers off
HPA1timer = t; //reset the function timer
}
if (HPA1SprayState != HPA1spray) //if the current state does not equal the remembered state (this is what turns the sprayers on or off) if it is the same then it skips this and continues the program
{
if (HPA1spray == true) //if the spray flag is true
{
digitalWrite(FETone, HIGH); //turn the sprayers on
}
if (HPA1spray == false) //if the spray flag is false
{
digitalWrite(FETone, LOW); // turn the sprayers off
}
}
HPA1SprayState = HPA1spray; //sets the state
}
 

dstroy

Well-Known Member
you are doing a lot of type of things like pulling real-time status information of devices that I am looking to add more of.

You seem to handle the passing of a day (time 23:59 to time 0:00) much the way I originally envisioned but could not figure out how to make the code work when the user wanted to run lights on at night (i.e. on at 4pm off at 10am) so I went a different route..

My most current code (rev5load4) has a lot of things commented out because I believe I have an issue with the power supply on the r3 not being sufficient to power my 8 channel relay when more than 6 relays are called to be on.

I don't want to start a growing debate but I am currently experimenting with a 20 hour day and the code I use for that is Rev5shortenday.

I particularly find the control logic for your HPA system confusing and intriguing because that technique is completely foreign to me but one of the main objectives that I have with the code I am writing is to make it easy for the end user to customize to their needs.
There are a couple things that I would change immediately, the first is that you do not need to constantly try and set your time every run through loop(), you can put that inside of a timer and have it run every minute at the max because what we are doing is not super critical of the exact time but we DO want to be synchronized with the time, so use system time instead which is set when you read the RTC time into system time. This will make your loop run much faster which is the end goal (fast and stable).

The second thing that you should do is to get rid of all the serial strings you have in mem and put them in progmem instead, you do that like this:

Serial.print(F("insert message here, this comes from progmem and doesn't use any ram")); this will save you a TON of memory

The last thing that I would do is to remove all of your calls to delay() because delay is a blocking call which means that NOTHING can happen while it is executing unless you have an interrupt attached to a pin and you don't.

I like the veg/flower transition idea, that's cool.
 

SSGrower

Well-Known Member
Figuring out how to make a light timer that doesn't break when the day rolls over to 0 was very counter-intuitive for me as well, but I'm happy to report that both of those work equally as well.

You should power your relay board with a separate power supply, the output pins for the uno are only supposed to do like 20mA per pin normally (40mA max I think)

Yeah, can't really do without an RTC they're really handy. I use real time extensively, the system time is synchronized with the RTC every so often because if not the system time is subject to drifting several seconds per day depending on temperature.

So, if your program is long and you are running a bunch of different functions it is a good idea to snapshot the time at the beginning or near the beginning of your loop(), you do that by putting the time into one variable that all the different functions you call use, because different functions use different amounts of clock cycles and things can get screwy if you don't do this.

I'm a novice, and don't know what reducing the day to 20 hours does but if it works for you then great. I don't grow stellar shit yet bro, still learning.

I'll explain how the HPA functions work, this is a state machine, it "remembers" its' last position and only calls digitalwrite() if it needs to because calling digitalwrite is easier than manipulating pins directly but it uses a lot of clock cycles so it's better if we don't call it every time we go through the function.

void hpasolenoid1() //function call
{
if ((t - HPA1timer) > sprayinterval) //if the current time "t" minus the last time that the sprayers were on is greater than the time that is supposed to pass before they spray THEN
{
HPA1spray = true; //set the spray flag to true (this ultimately is what turns on/off the solenoids)
HPA1timer = t; //set the function timer (HPA1timer) to the current time (t)
}
if (((t - HPA1timer) >= sprayduration) && HPA1spray == true) //if the current time minus the function timer (HPA1timer) is greater than OR equal to the amount of time to spray AND they are flagged to be spraying
{
HPA1spray = false; //turn the sprayers off
HPA1timer = t; //reset the function timer
}
if (HPA1SprayState != HPA1spray) //if the current state does not equal the remembered state (this is what turns the sprayers on or off) if it is the same then it skips this and continues the program
{
if (HPA1spray == true) //if the spray flag is true
{
digitalWrite(FETone, HIGH); //turn the sprayers on
}
if (HPA1spray == false) //if the spray flag is false
{
digitalWrite(FETone, LOW); // turn the sprayers off
}
}
HPA1SprayState = HPA1spray; //sets the state
}
I just fixed the relay just as you describe, probably as you were typing it, had to test with whacked out temp and humidity parameters but it worked, I have a 3a 5v and took off from a bus.

I do take a snapshot of time, was wondering why you used millis function when you had and RTC but makes sense the way you explain it
 

Attachments

SSGrower

Well-Known Member
The delay after flipping the man lights on is a safety, should only go through that when switching that relay from off to on. I get a lot of power fluctuanions and outages so being able to recover from one safely was critical, if I were using hps MH or other lamp I'd suggest a few minutes worth of delay before kicking back on. I will double check for unnecessary delays though and get the serial statement sorted as you suggest. I use an app called arduinodroid on an old phone but just as a monitor for those serial print statements.

CRS (cant remember shit)
do you have a battery backup?
 

dstroy

Well-Known Member
I just fixed the relay just as you describe, probably as you were typing it, had to test with whacked out temp and humidity parameters but it worked, I have a 3a 5v and took off from a bus.

I do take a snapshot of time, was wondering why you used millis function when you had and RTC but makes sense the way you explain it
Nice! Now things should be more stable for you and you should be able to manipulate all the relays no problem.

You snapshot the time, but you read from the RTC while doing it (reading from the RTC is slower than we want so we shouldn't do it every time).

DateTime now = rtc.now();

Instead of that, you would make another time element variable and put the system time into it.

t = now(); like that, which is fast.

and only read the RTC time into the system time (DateTime now = rtc.now();) every so often
 

dstroy

Well-Known Member
The delay after flipping the man lights on is a safety, should only go through that when switching that relay from off to on. I get a lot of power fluctuanions and outages so being able to recover from one safely was critical, if I were using hps MH or other lamp I'd suggest a few minutes worth of delay before kicking back on. I will double check for unnecessary delays though and get the serial statement sorted as you suggest. I use an app called arduinodroid on an old phone but just as a monitor for those serial print statements.

CRS (cant remember shit)
do you have a battery backup?
are you worried about your program freezing from a brownout? If so you should enable the watchdog timer, included in the AVR lib.

I do have a battery backup, all it powers is the arduino and essential functions (timekeeping, and spraying)
 
Top