Number crunching too much load for Arduino to power LCD?

I am building a Thermostat with some fancy features. I built up the menu system code separate from the temperature measuring, storing, and averaging code. I am trying to merge them now. Each works great by itself. When I try to merge them the display is all garbled. I noted out the main loop and ran just the set up and display works fine. Made it do a few things no problem. So I started slowly adding in the rest of the code. Buttons caused no problems. Adding in the variables cause no problems. Adding in the constraints and maps caused no problems. When I started adding in the lines of code that do the calculations (It’s a 400 index array that gets averaged in Real Time) things start to get flaky on the display. The more calcs I add the more it gags until it just won’t display at all. Eventually it starts doing what seems to be a random reboot of the LCD. I suspected the calculations were taking up too power and dropping my voltage. I checked it but it is stable at about 4.97 I believe. However, I believe it is regulated and maybe it’s just drawing too much current and the regulator on board cannot power it by itself. I tried powering off a 9v and the USB at the same time but no change. I don’t have enough hands or any gator clips to try to measure the current while powered up so I cannot tell if the regulator is just struggling. I also don’t have the proper sized capacitor to try to filter any ripple out but It’s DC so there should not be any? I plan to try to get the parts in the AM to put the LCD on a separate regulator. Am I on the right track here? Or is it something else. All the lines of code work as intended by themselves but as I add them in the display just gets worse and worse.

Thank You

UPDATE: I have slowed the main loop down to 1000 milies (AKA 1 second). Everything seems to work right when I do this. Must be a power consumption issue then?

Not power.

You are probably getting a stack overflow. Your Arduino bombs out because you use up all the memory and the stack overflows into something used for something else.

Try making your analog arrays smallers.

Was the first thing I tried. Shrank the 400 slot array down to 10 slots. Same problem :frowning:

The regulator/power us not the problem. That i can assure you. You will run out of space on memory and stack long before you draw to much power of the regulator.

Did you try fitting some 4.7uf caps and nanof caps around your 5volt and input lines?

I used to get garbage on 2 conditions. Stack overflow and noise. Smaller code and caps solved both. And i run some serious calcs on battery analysers.

I did find a bug in my code a few hours ago which got rid of the scrambling characters. The problem now is just that as I increases the frequency of my loop the characters in the bottom row and eventually in the top row start getting dimmer and dimmer. If I turn on the serial bus for debugging purposes I start getting the random reboot of the LCD but if I turn off the LCD in the code the Serial print works fine.

I have been reading up on a cap size to put across the bus to try to stabilize it. I didn't have a 1uF. Going hunting for some in 1 hour. Biggest I have is 560pF ceramic and only a 680uF electrolitic and smallest I have is 1pF ceramic. Will any of those work?

Thank You.

Thats quite an interesting "fault". And one I have never experienced.

To be brutal about it. You cant go wrong with too many caps on the dc lines. No matter there size. So place then across, even 2 or 3 in a row and see if it goes better. Even accross the LCD pin 1 and 2 and 15 and 16.

Unfortunately i am not sure how to help further than that.

Is all grounding done properly everywhere?

Everything has a common ground.

I added a 680uF and a few tiny pF caps across the power bus. It is making a HUGE Difference. I got my delay from 1 second down to 50 mS and could only see a tiny dimming of the bottom row of text. at 100 mS it is undetectable. That will do. Now to start pulling out different sized caps until I figure out which ones are having the best effect :slight_smile:

Thank You.

Presuming this is a text display, 16 by 2 or similar, I do hope you are not attempting to update the display any more often than five times per second, and not updating it at all unless the display information actually changes.

If you frequently use the clear function and then write data, you most certainly will see the text appear to dim out. You should only clear the display immediately before you write all your new data, not clear it, perform a calculation and then write the data.

You should only clear the display immediately before you write all your new data, not clear it, perform a calculation and then write the data.

Why? Does it have something to do with the library?

If one is writing their own code without using a prepackaged library then doing the opposite makes more sense. You can clear the display, use the time that it takes to perform the operation in lieu of all or part of the required (relatively lengthy) delay time and then write the data.

Don

I don’t like to clear my character LCDs at all, unless I’m displaying a something totally different (for example, menu vs. status). Just print right over the top of your old info, with an appropriate number of spaces padded on to the end to account for different length strings (a space-pad function works a treat). Then it doesn’t matter how often you update.