[SOLVED] Sanguino won't run if too many Serial.print statements

I’m a total newbie to the Arduino/Sanguino microcontrollers. I apologize for the long-winded post but I want to make sure I explain my issue as thoroughly as possible.

I’ve been playing with a Sanguino for the last couple of weeks and I’m working on a project to rotate a ham radio antenna, a rotator controller. You enter the compass heading where you want the antenna to point and it turns the antenna to that heading. I have much of the guts of the sketch working fine. This part works fine so far. Now, I want to add a real-time clock which, hardware-wise, is no big deal. What I want the user to be able to do is manually set the clock time. So, using the keypad library I’m slowly figuring out how to do this but in troubleshooting I used a lot of Serial.print commands throughout the keypadEvent code to verify where the program is processing and print various status messages with array and variable values and the like. This is mostly to help me understand how the routine works. I’m not a C programmer so this is all new to me so I’m learning as I go. I have some experience with PHP which has very similar programming instructions. I’m sure my code is very inefficient but at this point all I want to do is get it working.

Where I’m running into problems is I found that there can be too many Serial.print statements which causes the chip to not run, continually reset or just lock up and never run. I found if my sketch is 15265 bytes or higher the sketch the chip just continuously resets. If the byte size is around 15275 the sketch doesn’t even run. It uploads fine as far as I can tell based on the debug LED. If I remove some of the Serial.print statements the sketch will run. After I removed some of the Serial.print statements and added some if statements and other commands when I verify and compile the program the byte count doesn’t seem to increase. But, as soon as I add some Serial.print statements the byte size increases. This doesn’t make sense to me but that’s what I’m seeing in the IDE. When I verify the sketch this is what I see: Binary sketch size: 15265 bytes (of a 63488 byte maximum).

I searched to forums but I didn’t find anything related to this. Am I running into some internal limitation of the 644P chip? I don’t know where to look for a resolution. For now, I just commented out as many Serial.print statements as I could so I could continue development.

I also checked the preferences.txt file to see if there is something in there that might mention this limitation but there’s nothing obvious.

I’m using Arduino version 0022, Windows XP SP2. I haven’t tried any earlier Arduino versions. Just for grins I tried another Sanguino chip I got from a different source so I suspect it’s not the chip as far as a problem with the original chip.

I’m as a loss as how to proceed. When I’m finished with development I’ll remove all Serial.print statements.

Any guidance would be appreciated.

I can post all the different .PDE files if needed; I have each function in a separate tab to keep things more tidy.

Your most likely running out of SRAM memory. The program size is held in flash memory and that is what the compiler reports for the size of your sketch. I think your chip has 64k of flash size, but 4k of sram space. SRAM is used to hold all your variables, arrays and constants and the stack. So all your added Serial.print("tons of messages") added lots of sram usage to hold those messages. There is a way to store strings into flash using a library that can move the string messages to flash memory instead of sram, you will have to search or wait for someone else that has actually used those commands to tell you how.

Good luck;

Lefty (WA6TKD)

Lefty, thanks for the quick reply. That makes sense now. I wasn't aware of that library so I'll poke around for it.

73 and thanks, Bill N6EF

SanguinoGuy916: Lefty, thanks for the quick reply. That makes sense now. I wasn't aware of that library so I'll poke around for it.

73 and thanks, Bill N6EF

Here it is I think: http://arduiniana.org/libraries/flash/

That's exactly what I need. I'll try it. Thanks.

Bill

Problem solved. I ended using the <avr/pgmspace.h> library and PROGMEM. This seems to have solved my problem for time being. Lefty hit it right on, it looks like I filled up my SRAM. Using the PROGMEM I moved my fixed string arrays to program memory instead of SRAM. I adapted a function I found in a post by etracer to print my newly-moved strings to the LCD. So far, so good.

That's great. Any chance after you get it all debugged and cleaned up of posting it here? Never know when I might want to get back into ham radio someday. ;)