Okay so I added a turner motor feature to the previously mentioned sketch I found online. It now turns the eggs every 5 hours for 1 minute. During lockdown (last 3 days of the hatch) I can toggle the int TurnerONOFF = 1; to a 0 and keep the turner from turner. I would have to reprogram the arduino to make this happen but thats the easiest way to do it right now.
Down the road I would want to add menu features for the turner and have it countdown to when the next turn is on the screen along with saying its now turning when it is.
It seems stable compared to the last sketches I have played with. It has been up and running all day so far. Going to put in some eggs and see how this goes.
set someInterval to a value and msecLst to msec. some action could be a function pointer to various things or simply invoke a state machine with a timer-stimulus
static unsigned long msecLst = 0;
unsigned long msec = millis ();
if (msecLst && msec - msecLst > someInterval) {
msecLst = msec;
// some action
}
}
I originally tested it with 10000 ms on 10000 ms off and it worked fine cycling at that. so I then upped it to 5 hours (18000000) and 1 min (60000) on but it doesn't seem to cycle then. Is that number to big for it to handle?
Also after a while my lcd screen goes all gibberish but the program I think still keeps running. What would cause this? Do I need capacitors in the power supply?
Those numbers would work if your time variables are unsigned long. That they don't makes me wonder if you're using ints or they are being interpreted that way. Check your variable types and put a UL suffix on both constants.
I didn't post this yesterday because you said it was working with 5 hours and I assumed you had already fixed it:
/home/test/Downloads/egg_incubator_vs_4/egg_incubator_vs_4.ino:54:28: warning: overflow in implicit constant conversion [-Woverflow]
const int turnerInterval = 18000000; // 5 hours in ms
^~~~~~~~
The next line should also be unsigned, unsigned int will work as long as the number is <= 65535, otherwise use unsigned long.
const int turnerDuration = 60000; // one minute in ms
Anita_Bath:
Also after a while my lcd screen goes all gibberish but the program I think still keeps running. What would cause this? Do I need capacitors in the power supply?
Can you post a schematic show how you have everything wired? That sounds like power supply problems, since the code is switching a heater ON/OFF that is likely to be causing voltage spikes on the AC supply, but could also be from relays.
Also after a while my lcd screen goes all gibberish but the program I think still keeps running. What would cause this? Do I need capacitors in the power supply?
A large capacitor connected across the Vcc/GND of the display could help.
Corruption of the lcd displays with relay and motor noise is a common problem, and they can be difficult to solve.
Anita_Bath:
Also after a while my lcd screen goes all gibberish but the program I think still keeps running. What would cause this? Do I need capacitors in the power supply?
It sounds like you are getting noise on the i2c lines that is messing with your communication with the lcd. Are the wires from the arduino to the LCD very long? Or is it a shield plugged into the board? The most likely cause is the motor turning on/off. Does it have any type of noise filtering on it? Flyback diode?
I put a .1 and a .01 uF capacitor on the power and ground wires going to the LCD and that seems to stop the gibberish from happening after a few hours. However now the arduino is locking up after a while and I have no idea why.
The motor is controlled through an 8 channel relay board.
I will try to draw up a wiring diagram.
I have attached the latest sketch of what I am using. I made it so I can enter hours and seconds as they should be vs milliseconds. keeps it easier and as a smaller number
You have far too much code in there for something that doesn't work. </broken record>
I'd add some messages using Serial so you can gather clues about what it was doing when (or indeed if) the system crashed. Use the F macro for your text strings to save space in RAM.
wildbill:
You have far too much code in there for something that doesn't work. </broken record>
I'd add some messages using Serial so you can gather clues about what it was doing when (or indeed if) the system crashed. Use the F macro for your text strings to save space in RAM.
Feel free to show what I should have...
The code is proven code and I added the turner feature.
As it stands now with the turner feature after I compile I get this.
Sketch uses 11408 bytes (37%) of program storage space. Maximum is 30720 bytes.
Global variables use 513 bytes (25%) of dynamic memory, leaving 1535 bytes for local variables. Maximum is 2048 bytes.
If I take out the turner feature I get this.
Sketch uses 11280 bytes (36%) of program storage space. Maximum is 30720 bytes.
Global variables use 505 bytes (24%) of dynamic memory, leaving 1543 bytes for local variables. Maximum is 2048 bytes.
I could however go through and add the F macro fix to the screen printing that is going on for the temp and humidity and fan control and see how much that changes it.
Another thing I got thinking about is I had a RTC module hooked up to pin 4 and 5 along with the LCD because in previous codes it used an RTC. I wondered if it was interfering so I unhooked it. Going to wait and see if that changes anything.
Looks like you have plenty of memory. I'm more interested in whether dropping the turning makes it work again. I'm wondering if there are spikes from the motor turning on and off that are giving the Arduino a headache.
wildbill:
Looks like you have plenty of memory. I'm more interested in whether dropping the turning makes it work again. I'm wondering if there are spikes from the motor turning on and off that are giving the Arduino a headache.
Could be a code issue instead of course.
I made a clean version with out the turner feature and added the F macro to all the lcd print lines it would let me. Some would make errors or not compile for an arduino nano... When compiled I now get.
Sketch uses 11360 bytes (36%) of program storage space. Maximum is 30720 bytes.
Global variables use 329 bytes (16%) of dynamic memory, leaving 1719 bytes for local variables. Maximum is 2048 bytes.
Anita_Bath:
I made a clean version with out the turner feature and added the F macro to all the lcd print lines it would let me. Some would make errors or not compile for an arduino nano... When compiled I now get.
Sketch uses 11360 bytes (36%) of program storage space. Maximum is 30720 bytes.
Global variables use 329 bytes (16%) of dynamic memory, leaving 1719 bytes for local variables. Maximum is 2048 bytes.
I would say the f macro helps haha
That's nice ...but what was the answer to the question in reply #33 ????
I am currently letting it run with the RTC unplugged and the turner set to turn every 20 min for 5 seconds to see if that makes a difference.
I wondered if 5 hours is to long for the memory? I dunno
It is turning every 20 min whereas at 4 or 5 hours it never moved. so we shall see.
If it fails I will upload a clean version with no turner and see if it locks up then. I only want to change one or two things at a time to make sure I know what the real issue is in the end of all this lol.
what kind of board are you using?
Standard-Arduino or someting different?
If you have one IO-pin free you could add a simple LED with current-limiting resistor to this IO-Pin
and add some commands that make the LED blink once per second (using blink without delay).
Or if you have at least two characters free on your LCD
adding some code that changes one character between "A" and "Z" to indicate board is executing loop()
what kind of board are you using?
Standard-Arduino or someting different?
If you have one IO-pin free you could add a simple LED with current-limiting resistor to this IO-Pin
and add some commands that make the LED blink once per second (using blink without delay).
Or if you have at least two characters free on your LCD
adding some code that changes one character between "A" and "Z" to indicate board is executing loop()
best regards
Stefan
I appreciate the idea. However on my lcd the temp is shown to the second decimal and it jitters all around when its working. When froze up it stays locked at a temp. For example 37.22 celsius for instance. I have been using that jittering around to know if its truly working or not.
I have looked inside your code adding serial output can help to narrow down the problem.
in your setup-function
void setup(void)
{
// Start up the temperature sensor library.
sensor.begin();
you would insert
void setup(void)
{
Serial.begin(115200);
Serial.Println(); // print a "newline to make sure serial output begins in collum one
// Start up the temperature sensor library.
sensor.begin();
and inside
your function void loop(void)
and/or inside the other functions
inserting commands that do the serial output