Not enough RAM for Nokia 5110

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
abrahamn
 
Posts: 7
Joined: Thu Apr 04, 2013 9:53 am

Not enough RAM for Nokia 5110

Post by abrahamn »

I am building a datalogger using the Adafruit SD/RTC logger board on an Uno, and I am trying to integrate the Nokia 5110 display.

When I try to use the RTC function, SD capability, and the LCD display all at once I get crazy serial output and haywire program behavior, which I think is from running out of RAM. But if I comment out either the SD or the LCD sections it runs fine. Using a memory usage monitor it looks like the LCD routines use about 700 bytes. Is there a way to run a stripped-down version of the LCD controller? The only thing I want from the LCD is the 5x7 text capability.

Thanks,
Abe

User avatar
abrahamn
 
Posts: 7
Joined: Thu Apr 04, 2013 9:53 am

Re: Not enough RAM for Nokia 5110

Post by abrahamn »

Or to take another approach: if I never use the display and the SD writer at the same time, is there any way to turn each one off when not in use and free up its RAM? There are display.begin() and SD.begin() functions, but is there anything to end them?

--Abe

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Not enough RAM for Nokia 5110

Post by adafruit_support_bill »

It would probably require some library hacking to allow the two libraries to release memory when they were not using it. An easier approach may be to move to a processor with more SRAM. The Leonardo has 2.5K (0.5K more than the Uno). The Mega has 8K which should give you plenty of room.

Have you looked through your code for other memory optimization opportunities? Literal strings in print statements are pretty easy to force into Flash with the "F()" macro.

User avatar
abrahamn
 
Posts: 7
Joined: Thu Apr 04, 2013 9:53 am

Re: Not enough RAM for Nokia 5110

Post by abrahamn »

Thanks for your suggestions. I have very few literals to take advantage of, and I'd like to stick with the Uno for economics (I need to make a bunch of these devices.) So that leaves the Leonardo, and possibility of modifying the libraries, though the library option goes beyond where I feel competent.

Do you have any advice on a starting point or strategy for getting the libraries to release RAM?

Thanks,
Abe

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Not enough RAM for Nokia 5110

Post by adafruit_support_bill »

You might first look at the SD library. I believe it is possible to specify a smaller buffer size for that. If that doesn't buy you enough space, you may need to look into a memory sharing scheme.

In general, dynamic memory allocation in an embedded system is best avoided. It is easy to fragment the heap to the point where large allocations cannot be safely made. This is an extreme case, where the screen buffer is more than 1/3 of available SRAM!

I would find the buffer allocation section of the two libraries and determine how much each one needs. Then I would declare a buffer big enough for the larger of the two at file scope. Then create versions of the "begin()" functions that accept a buffer pointer instead of allocating a new buffer.

Of course then you are responsible for making sure that the two libraries don't step on each other's data.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”