Find the programming mistake and win a voltmeter and a book!

At http://www.oppedahl.com/arduino/ you can see a writeup of my project to measure the day's high and low outdoor temperatures. This project works (you can see the functioning web page at http://wx1.oppedahl.com:81/), but to get it to work I had to comment out lots of features that I wish I could have included. The code that I wrote (which is my first real coding since the days of FORTRAN and BASIC) is "brittle". If I add a few seemingly harmless "print" statements, the code gets flaky when I run it.

I assume that I made one of those errors that newbies make, like referencing a place in an array that is beyond the boundaries of the array, the kind of thing that C compilers don't catch.

Anyway, there is a reward for the first person who finds my "array pointer out of range" problem, or whatever my stupid mistake was.

Thanks for listening.

If I add a few seemingly harmless "print" statements, the code gets flaky when I run it.

Without looking at the code that sounds like you are running out of memory. Have you tried moving literal strings into program memory?

Without looking at the code that sounds like you are running out of memory. Have you tried moving literal strings into program memory?

Wow, this shows how new I am to embedded systems like this. I compile the code, and it is a "mere" 16K and the Uno has 32K. But of course that is the EEPROM, right? I guess the memory that you wonder if I am running out of is SRAM of which the Uno has only 2K.

I've read large portions of the Arduino.cc web site, and I've read three Arduino books. I don't recall ever seeing a place that discusses "moving literal strings into program memory". I guess this is a compiler thing that I don't understand. I assumed that all of my literal strings were stored in program memory and nowhere else, except maybe little snippets that might be in RAM very briefly while the print function accomplishes printing.

So I'll bite. Is there somewhere on the Arduino.cc web site where it discusses how to "move literal strings into program memory"? Thanks.

Oh and since we are on the topic. Is there some sort of Arduino emulator that can take as input a sketch and produce as output an estimate of the amount of RAM that is likely to be consumed?

Did you read about progmem?

I compile the code, and it is a "mere" 16K and the Uno has 32K. But of course that is the EEPROM, right?

Actually no.

The AVR 328p chip used on the arduino Uno board has three types of memories.

Flash (alis program memory) 32k bytes (minus 256 of bootloader space) SRAM 2K bytes used to store variables, constants, arrays, stack space, etc. EEPROM 1K bytes user read/write memory avalible for storing user written information that is non-volatable

Grumpy_Mike:

If I add a few seemingly harmless "print" statements, the code gets flaky when I run it.

Without looking at the code that sounds like you are running out of memory. Have you tried moving literal strings into program memory?

I think you nailed it. A quick check of the code shows huge amounts of literal strings everywhere.

Is there some sort of Arduino emulator that can take as input a sketch and produce as output an estimate of the amount of RAM that is likely to be consumed?

Have you seen this: http://www.arduino.cc/playground/Code/AvailableMemory? I often put calls to freememory() at the end of setup and at various parts of the main loop. May not be perfect, but gives you an idea of how you are doing.

Brad.

I don't recall ever seeing a place that discusses "moving literal strings into program memory".

First off look here:- http://www.arduino.cc/en/Reference/PROGMEM

Next look at:- http://arduino.cc/pipermail/developers_arduino.cc/2011-March/004738.html

Then search google for threads on this forum involving this topic, this was my top hit:- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1295141054

I assumed that all of my literal strings were stored in program memory and nowhere else, except maybe little snippets that might be in RAM very briefly while the print function accomplishes printing.

That ARE held in program memory (where else could they be held?) but they are copied in their entirety into RAM before "main()" is executed.