Go Down

Topic: String() and other library stack problems. How to identify which library ? (Read 346 times) previous topic - next topic

LeeMcK

I need a way to identify what String() function or what piece of library code is messing up my development projects.

I am using Arduino 1.0.5 on Ubuntu Linux.

I am whipping along doing a couple of data logger projects. For each project, I add one new function at a time.

I get to the point where I have several include files like this:

Code: [Select]

#include <Wire.h>
#include <RTClib.h>                      // Real time clock
#include <Adafruit_Sensor.h>    // Barometer
#include <Adafruit_BMP085_U.h>   // Barometer
#include <SPI.h>                // SD card
#include <SD.h>                 // SD card
// Libraries from LCD example
//#include <OneWire.h>
//#include <LiquidCrystal.h>
/*


I am repeatedly running into problems where  Serial.println(), appending  "\n" to Strings, using long() type cast, declaring pinMode(pin9, OUTPUT), and invoking lcd() statements are either returning  blank data or breaking SD.open().

So the question is: how do I trace the program execution, or how do I reorder the #include statements, or how do I put padding or a marker or harmless instructions on the stack so I can identify which library or which included class function or which code is failing to clean up the stack?

I request no comments from PaulS. Your comments are demoralizing, so do not offer your comments. Thanks.

The Arduino is a great community, fun platform and Open Source. Thanks again.


AWOL

You're probably running out of RAM, but without seeing your code, it's hard to tell.

Quote
I need a way to identify what String() function or what piece of library code is messing up my development projects.

It is quite possible that the first part of sentence contains a hint about what may be wrong with your code.

Quote
So the question is: how do I trace the program execution,

It is quite possible you can only make things worse.
Are you making full use of program memory for constants?
What about the F() macro for prints?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

LeeMcK

The sketch I am developing is a data logger that reads barometeric pressure.
The Arduino is a Uno, and stacked on the Uno is the Adafruit logger plus real time clock.
The gadget is running now, logging barometeric pressure.
When compiled, the program reports:

Memory used 24976 bytes
Out of             32256 bytes, max. Leaving 7280 bytes free.

The compiler message doesn't seem to say I am running out of memory.
What is your comment, is 7280 bytes not enough?

Trying to learn more about the memory used, I switched on compile messages in the Arduino preferences.
The compile and upload messages tell a lot. I removed some unused variables and cleared away some compiler warnings.

So I pause here and ask you a question,  can you show me a code example of printing out the address of a string variable? is there any way I can
create a couple of pointers that will tell me the exact memory address
of some of my data values? Are there any system memory variables that I can read? Can you show me any way to read the memory value when a function() has run and show me the instruction pointer or memory address right before the return; statement?

It looks like the avr-gcc library has a library and a function call, but I'd need a tutorial example to learn how to use it.

What I am trying to add is an LCD display. So far the display works  and I have a pinout.

So for simplification, I leave the LCD disconnected and I uncomment the LCD library code one line at a time .
The software problem that gets me is the command that opens the SD card for writing always fails
when I uncomment the LCD library initialization instruction like this:

Code: [Select]
LiquidCrystal lcd(2,3,6,7,8,9);  // lcd(RS,EN,D4,D5,D6,D7)

Thanks for the memory out comment. If I am out of memory well how do I print out the memory addresses of the last data items?

AWOL

Quote
The compiler message doesn't seem to say I am running out of memory.

All the compiler message says is that you're not running short of program memory.
It says nothing about RAM.


Quote
can you show me a code example of printing out the address of a string variable?

Code: [Select]
char string [20];
...
...
...
Serial.println ((unsigned int)string, HEX);
// OR
Serial.println ((unsigned int)&string[0], HEX);


Quote
is there any way I can create a couple of pointers that will tell me the exact memory address
of some of my data values?
Yes, see the use of the "&" operator above.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Quote
If I am out of memory well how do I print out the memory addresses of the last data items?

First, you have to know which are the last data items. This means that you need a memory map, and you have to know where the stack and the heap are.

The biggest problem with memory usage on the Arduino is that the static memory stuff occupies one end of the memory. The heap is next to that, and grows and shrinks as dynamic memory allocation occurs. The stack starts at the other end, and grows and shrinks as functions are called and returns happen. As long as the heap and the stack never meet, no problem. Once they do, all bets are off.

There are ways of determining how far the edge of the heap and the top of the stack are from each other. But, the values changes as you try to measure them.

Look at:
http://playground.arduino.cc/Code/AvailableMemory

LeeMcK

Thanks for the code example for displaying the address of a data value.

I bought a Arduino Due with 16x more memory than the Arduino Uno and tried my program with so called "library stack problems" on the DUE.

The effort introduced a lot more uncertainties but the bottom line is the SD.open() function call consistently works when running a demo program and consistently fails when running with a several libraries.

Lack of program memory is not the single problem causing my application failure.

Here is the attack I am going to try:

I am going to isolate the SD library activity, the RTC (real time clock) activity, and the String() activity each into a separate function().
For the resulting function() calls, I am going to put "address of..." telltale number data at the top and the bottom of each function().
Then I have separated the function() s so they do not fight and I can see of one of them is failing to return with the stack in good order.

Go Up