Pages: [1]   Go Down
Author Topic: Incompatibility with SD.h and other libraries  (Read 1165 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to use the TinyGPS.h, Wire.h, SoftwareSerial.h and SD.h libraries in a common sketch.  My hardware includes the WiFi Shield, LS20031 GPS receiver, the ADXL335 accelerometer and the Sparkfun barometer and everything runs fine UNTIL I load the SD.h library.  Simply loading it (not using the card) renders the sketch inoperable (nothing comes back on the Serial).  I've finally managed through some iterations to get the GPS and barometer to work some times but still with a ton of jumbled text.   smiley-eek

Are there incompatibility issues with the SD.h library?

I know my SD slot and card are good as I can get them to work by themselves. 

I can post my entire sketch if need be.
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1663
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Arduino are you using? You may be running out of sram.

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the Arduino Uno.

Shouldn't it alert me if I used too mush space?  The sketch loads without issue, it just does not do anything after loading.  That or the text is garbled (if I change a few things around).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On a side note - I've noticed if I do not include TinyGPS I can get this to work, but then I'm at a loss as to how to read from the GPS receiver.  I am running a continual loop and need stats from teh GPS but cannot leave the Serial open as in all the examples I have seen thus far...
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1663
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Shouldn't it alert me if I used too mush space?
I think it should, but it doesn't.
Quote
The sketch loads without issue, it just does not do anything after loading.  That or the text is garbled
Both are common symptoms of running out of sram. There are many threads in the Programming Questions forum (where this thread should be) about how to reduce your use of sram. The easiest to start with is to reduce the number and length of string constants. By default they are stored in sram. So a statement like this:
Code:
  Serial.print("Hello there");
stores the string in sram. You can easily move it, and all similar print strings, to flash by doing this:
Code:
  Serial.print(F("Hello there"));
There are various other techniques as well but it is possible that with so many libraries there's no way to reduce the sram use to the point that the code will run reliably. I had that happen in a project of mine and the only solution was to use two CPUs (Nanos) talking to each other.

Pete
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1663
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just FYI I did a few quick tests to find out the size of those libraries.
If you have just this do-nothing code:
Code:
void setup(void){}
void loop(void){}
It uses 466 bytes of program space and 9 bytes of sram.
Adding the SD.h library increases this to 5646 bytes of program space and 798 bytes of sram. Adding wire.h and SoftwareSerial.h increases it to 7320 program space and 1073 bytes of sram. So, without adding any code at all, you will have used up a bit more than half the available sram, most of it used by the SD library which needs that space for buffers.
Also note that without doing anything at all other than add libraries, this uses nearly a quarter of the available program space.

One of the arts of programming minicomputers back in the day was how to cram as much functionality as possible into the available ram. The other art was knowing when you're beaten.

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am definitely not running out of RAM.  I isolated this incompatibility down to the use of the SoftSerial object.  If you use TinyGPS you typically (looking at the example that comes with the library) create an instance of SoftSerial through the creation of an nss.  See this page for an example:  http://arduiniana.org/libraries/tinygps/

If I load all libraries but simply don't use SoftSerial (effectively rendering the TinyGPS library useless) everything runs; I'm just not running any functions that leverage off of the TinyGPS  library.
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1663
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I isolated this incompatibility
They are usually only incompatible if they try to use the same pin for different purposes. You say that everything works without softserial which means that the others aren't interfering with each other. Since you have to tell SoftSerial which pins to use, the incompatibility, if there is one, would be your fault.

Quote
If I load all libraries but simply don't use SoftSerial (effectively rendering the TinyGPS library useless) everything runs
And when you use SoftSerial it tries to allocate some ram for whatever it needs (buffers etc.) and that takes you over the limit.
There are several threads in the forum which describe how to find out how much sram your code is using dynamically. You could use that code to print out how much sram you're using before you start Softserial and then try printing it again after you start SoftSerial.

Pete
Logged

Pages: [1]   Go Up
Jump to: