Go Down

Topic: What is considered low RAM ? (Read 163 times) previous topic - next topic

arawire

I have written my first Arduino programme and am getting some strange results  The sketch is about 20,000 bytes and when I check the RAM when running it's saying 358 is free.  Is this considered low enough to cause problems.  I know there is 2 k to play with, but I'm using the Adafruit WAVEHC library and the NewPing one.

Thanks in advance.

econjack

You can monitor your RAM usage with the following function:

Code: [Select]


int freeRam () {
 extern int __heap_start, *__brkval;
 int v;
 return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}


Put calls to freeRam() at various points in the program and display the results on the Serial monitor.

arawire

thanks for that.. that is what I am currently doing... I was just wondering what was considered low.  ie my RAM says there is 350 is free and I'm sure my problems are related to low RAM... So would 350f be considered low enough to cause issues.

ChilliTronix

Well, 350 bytes free is greater than 10% so I would have thought that was fine. After all, it is there to be used.

arawire

thanks for that ... so I gather from what you're saying is that below 10% free ie on the Uno 200 is where you may get into a pickle?

wildbill

You don't have to have any free as a margin. You just need to know that at the most costly point in your code that you haven't run the stack into the heap.

econjack

Low Ram is a relative concept. If you're doing recursive factorials, 350 bytes might look like a lot until you change 5! to 10!. If you have a defined task that uses a fixed variable allocations, you might get away with as little as 25 bytes of RAM left. Your design should be able to give you at least an approximate count of the RAM you will need.

ChilliTronix

thanks for that ... so I gather from what you're saying is that below 10% free ie on the Uno 200 is where you may get into a pickle?
No I just picked 10% to show you you have plenty left.

As noted above, you don't need any free RAM. All you have to watch out for is that if you don't have any free you can't use any more. Apart from that everything is good!

Nick Gammon

I have written my first Arduino programme and am getting some strange results 
This is another X-Y problem. You are asking about free RAM, but ...

http://xyproblem.info/

Quote
I have written my first Arduino programme ...
What program? Post your code.

Quote
... and am getting some strange results  ...
What results?

How to use this forum
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

arawire

yes .. thanks, i totally understand .. I just felt a bit guilty about dumping lots of code for someone to look at so I was trying to be more concise.  I'll post it up tomorrow..

BTW.. I removed all the string references and freed up another 150 bytes RAM.. So Thanks

arawire

OK, I'm posting the code here - so any pointers would be great.  It is my first Arduino program so if you could be gentle that would be great and explain any wrong coding as if you were to a child.  Just to summarize, I have one ultrasonic sensor, and Adafruit wave shield that plays speech based on "assumed movement".   I've managed to reduce RAM drastically by using ints, getting rid of strings and switch statements .. problem is now that when I press the button for the calibration routine in the void playUntilBlocked it restarts itself.. I think specifically on the wave.stop.  Comments on the code would be much appreciated (bear in mind it's not finished).  Thanks

... it says the code is too big so I'm attaching it as a text file.

Go Up