My egg incubator gets stuck on the screen for turning eggs for X amount of seconds.
It actually ends up saying " urning egg's for 45 seconds" and doesn't leave that screen. Any idea why?
code is to long to post here so it is attatched
EGG_INCUBATOR_By_SLIMFARMER.ino (24.4 KB)
Did this suddenly happen after you changed something in the program?
Paul
Paul_KD7HB:
Did this suddenly happen after you changed something in the program?
Paul
No this is the first time testing the program.
Anita_Bath:
No this is the first time testing the program.
Guess it's not your program.
Did you copy it correctly? Did the author have the same or similar problem?
Paul
You have a couple of errors causing the problem.
The problem with the text on the display is a bit obscure for someone new, when you position the cursor to (6,2), then print out motorspinduration and the text following it, you have too many spaces after "seconds" so the text is wrapping to the next line. Because of the way the LCD display chip works, the lines on a 4x20 LCD display wrap line0 > line 2 > line1 > line3, so the end of line 2 is wrapping to line 1 and overwriting the first letter of "Turning". You really don't need any spaces at the end of the text, lcd.clear() clears the entire display, so you are just overwriting blank spaces with blank spaces.
while (((millis() - rotationtime) > durationB4spin) && (rotate == 0))
{
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" Turning EGG'S for ");
lcd.setCursor(6, 2);
lcd.print(motorspinduration);
lcd.print(" seconds ");
digitalWrite(motorpin, LOW);
delay(durationONspin);
digitalWrite(motorpin, HIGH);
rotate = 1;
}
The other problem is with the length of the delay. Try printing out the value of durationONspin to the serial monitor and you will see why the code appears to freeze.
david_2018:
You have a couple of errors causing the problem.
The problem with the text on the display is a bit obscure for someone new, when you position the cursor to (6,2), then print out motorspinduration and the text following it, you have too many spaces after "seconds" so the text is wrapping to the next line. Because of the way the LCD display chip works, the lines on a 4x20 LCD display wrap line0 > line 2 > line1 > line3, so the end of line 2 is wrapping to line 1 and overwriting the first letter of "Turning". You really don't need any spaces at the end of the text, lcd.clear() clears the entire display, so you are just overwriting blank spaces with blank spaces.
while (((millis() - rotationtime) > durationB4spin) && (rotate == 0))
{
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" Turning EGG'S for ");
lcd.setCursor(6, 2);
lcd.print(motorspinduration);
lcd.print(" seconds ");
digitalWrite(motorpin, LOW);
delay(durationONspin);
digitalWrite(motorpin, HIGH);
rotate = 1;
}
The other problem is with the length of the delay. Try printing out the value of durationONspin to the serial monitor and you will see why the code appears to freeze.
I found this code for the most part in a youtube video, but I had to type it all out which helped me learn a fair bit. I ended up changing some parts and adding some features when the door is opened. I had no idea about the black spaces on the lcd print so that's good to know thanks. I should have that fixed now.
However when I print the spinONduration to the serial monitor all i get is
4294949760
4294949⸮
If i print out motorspinduration I get this.
⸮⸮C⸮⸮C⸮⸮C⸮⸮C⸮⸮C⸮48
48C⸮⸮C⸮⸮C⸮⸮
⸮⸮⸮
⸮⸮⸮⸮⸮C⸮⸮C⸮48C⸮⸮C⸮⸮C⸮48C⸮⸮C⸮48
So as for the issue of it freezing i'm still lost haha. The spin count down on the main menu is getting frozen now too.... hummm
Not sure why you are getting all the odd characters in the serial monitor, the value of spinONduration is 4294949760 and motorspinduration is 48. Are you trying to convert the numbers to text before sending to the serial monitor?
Your problem is the value of spinONduration. You are calculating the value in setup(), which should produce a value of 48000. The equation is correct, but you have declared motorspinduration as int, a 16-bit signed integer, which can only have a value from -32768 to +32767. The result of the multiplication is too large for an int, and ends up as a negative number. Then you are storing the result in durationONspin, declared as an unsigned long, which is not capable of storing negative numbers, so you end up with an extremely large positive number.
durationONspin = motorspinduration * 1000; //seconds to Ms