Arduino Micro Freezing When Running Code

Hey guys,

I'm pretty new to the forum and Arduino and I've been pulling my hair out over this problem.
I am writing code that is interfacing with a text-to-speech module and also a gps module. I am creating a device that reads the gps data then lets the client know where he is based on an array of way points I have constructed. But recently, my program has started to act funny. Sometimes when I upload the program it locks up the Micro completely and uploading a new program is difficult. Sometimes only part of the program works and then as soon as it reaches some point (at random) it will stop working.

My first thought after doing some reading was that I was using too much SRAM with my array of strings that are the waypoints. But then I went back and commented out most of my strings in the array and I still had the same problem. So I decided to learn how to put that array of strings into the Flash memory and still the problem continues. The code was working the way I needed it to until I added the final waypoint phrases the client wanted.

I also tried using an Arduino Uno to see if maybe I just had a bad controller but I got the same results. The code is difficult to test without an Emic2 or VenusGPS and I have two versions of it. One that uses PROGMEM and the other that is just regular with most of the strings in my array commented out.

I have the newest Arduino IDE installed and it says that use less than 800 bytes of the SRAM on both versions for my globals so there should be enough to run the program. I'm hoping someone has run into a problem like this and can help me out.

One last thing I've noticed that is odd to me is that I have a my text-to-speech module let the user know when the power is on when everything is first turned on. I have a flag variable that is global so that once that is ran one time it sets the flag so that that block of code can't be run again. But I find that it will repeat that phrase over and over again. When I go to print out the value of the flag, it somehow gets changed from a 1 (meaning it already ran and let the user know it has power) back to a 0 (its starting value).

The first version (Master_3_25_15) uses just an array of strings, the second version (Master_4_14_15) uses PROGMEM and I should add that it did work properly once. But upon resetting to see if I could get a repeated working result has not worked since.

Thanks

Master_3_25_15.ino (18.8 KB)

Master_4_14_15.ino (20.4 KB)

Aside from pissing away resources on the String class, your GetGPSData() function is fundamentally flawed. Most of the time, the function will reach the end, without encountering a return statement. There is no telling what will be popped off the stack, since you put nothing on the stack.

      if (satNumber >= 11);

That semicolon is almost assuredly wrong.

GetField() has some serious issues, too. It assumes that there are 80 characters in the sentence array, regardless of how may are actually there. It writes stuff into other arrays with no concern as to whether there is room, or not.

Thank you for the quick reply.

I never noticed the semicolon on the satNumber check, thank you for pointing that out. I have fixed the function GetGPSData so that it will always return something and then changed the CompareGPSLookup to handle that new return. With these fixes, my program still seems to freeze once it tries to print out a successful latitude and longitude. The only reason I set GetField() to 80 characters is because that is the maximum amount of characters I should be reading at one time from my GPS module.

Thanks again for the help

The only reason I set GetField() to 80 characters is because that is the maximum amount of characters I should be reading at one time from my GPS module.

It's character data. If the data is properly NULL terminated, strlen() will tell you how much data the array actually contains, so you don't walk past the data that is valid for the current sentence.

I still think you need to stop using Strings. Even with all that data in EEPROM, is suspect that you are running out of SRAM or you are fragmenting it to the point where there isn't enough contiguous memory.

Use statically sized arrays of characters, instead.

When I first thought that the memory was the problem, I would commet out some of my added waypoints (new strings) and it would work. But now I have most of them commented out and it still freezes once it gets its data.

I will definitely try to change them to a char array

Thanks again for the reply

Flipskater321123:
When I first thought that the memory was the problem, I would commet out some of my added waypoints (new strings) and it would work. But now I have most of them commented out and it still freezes once it gets its data.

I will definitely try to change them to a char array

Thanks again for the reply

Hi, I'm an arduino newbie and I'd be interested if you managed to solve your problem and if it was caused by you running out of memory?

It occurs to me that you use alot of repeated phrase segments, such as "You are on the " and "South side of " etc. that perhaps you could store once then access with pointers, constructing phrases that way?

I would bet that after 5 years, they found a solution. Try sending them a PM, they probably won't be around to read this. They might be surprised to be getting such late advice, though...