So I have a aquarium(oh yes another one), and I'm using an Arduino Mega to turn on the lights and other functions however this software just does the lights as the program is halting and is no longer responding as expected.

What I want the code to do and what works at least for a 24 hours period turn the lights on and off based off the sun positions IE sunrise twilight, sunrise, sunset and sunset twilight. I did this with suncalc() and is my code. The other thing it does is Ramp UP/Down based on a curve, this part was not programmed by myself I asked a friend that has programming experience for help. I tied a potentiometer to the ramp up/down to control intensity. You can fry corals by turning the LEDS on full blast!

What happens If I turn the arduino on in the morning it runs fine though out the day turns on ramps up ramps down all turns off. All Good. However over night things go downhill. Suncalc() runs but at some point in time after that the ramp up/down crashes it turns on one maybe two channels and that all she wrote. Adjusting the pot does nothing only thing that works is hitting reset which is hard to get to or unplugging the arduino and pluggging it back in. For the moment to solve this issue I have the arduino on an Aquarium timer that turns it on and off at night.

Am I asking too much of the mega or do I need to try and clean this up?

You will need to isolate whether the problem has to do with your clock or with some other aspect. To do that I would follow two strategies.

I would make a simplified version of your clock code that just blinks an led every 10 minutes (or some such) and leave it run for a couple of days just to ensure the clock can run past 24 hrs.

Separately I would make a slightly different version of your entire project arranged so that it runs through a full 24 hr cycle in (say) 10 minutes. This will show if non-timer problems are causing the crash and because it is running quickly you can add Serial.print statements to monitor values on your PC.

...R

Two or three hours spent thinking and reading documentation solves most programming problems.

on the 1st one as this is all connected now, would it be too complicated to have it still turn the lights on/off no ramp nothing fancy just on at a time off at a time, and increment a number on the LCD? Problem I'm having right now is my old lights are bad and I until I get some Coral recovery using the arduino to just blink an LED isn't an option atm when it is I can do that for sure!!

Can total ever be zero? I'm not sure what the arduino does on a divide by zero condition, but you might want to test for it.

Other than that, it's time to pepper your sketch with serial print. Since you're resetting nightly, do you have another arduino with the ability to write to an SD card - might make it easier to gather and save telemetry.

Perhaps you could write a small program on your Laptop (using Python or Ruby, for example) that collects the Serial.print messages and saves them to a text file along with Laptop generated time-stamps. If you can leave the laptop running for a day or two you may get some useful data that would be too tedious to collect manually.

You could then search through the text file with a text editor to find the interesting bits.

Perhaps you could write a small program on your Laptop (using Python or Ruby, for example) that collects the Serial.print messages and saves them to a text file along with Laptop generated time-stamps. If you can leave the laptop running for a day or two you may get some useful data that would be too tedious to collect manually.

You could then search through the text file with a text editor to find the interesting bits.

...R

I'm afraid this is beyond my abilities, I wouldn't even know where to begin on that

However I will do some googling it seems there is already an article on it so I'll see what I can come up with

while True:if(ser.isClosed()):breaktry:# This tries to open an existing file but creates a new file if necessary.logfile = open("c:\log.txt", "a")try:str = ser.readline()logfile.write(localtime)logfile.write(str)finally:logfile.close()except IOError:pass

localtime = time.asctime( time.localtime(time.time()) )inside the loop before "str = ser.readline()" so that it updates the time before it writes to the file

You might also want to consider whether you need to write the time to the file every time or just once every 15 or 30 minutes. But that's a little more complex.

I don't know enough about Python to know if your code will write the time on one line and the Arduino output on another line. It would be better if both were on the same line separated by a comma as that would make it easy to read the Logfile into a spreadsheet as a CSV file. I hope some other Forum reader can help on this point as I don't want to suggest changes that might break things.

I just ran a speed test and it failed as soon as the lights started to come on. so now at least I have a starting point!

Had to change the python code a bit, this reads it but its very messy.

Update so watching the speed test and something interesting happened, It didn't crash but it sure bogged way down. I went from a minute being 1 second to 24 seconds. This all happened when I hit the ramp up/down code. it would appear I may want to simplify that code.