Go Down

Topic: Low on memory any ideas? (Read 3116 times) previous topic - next topic

BassTeQ

Nov 29, 2014, 11:08 pm Last Edit: Nov 29, 2014, 11:10 pm by BassTeQ
Hi all, running a little low on memory on my Uno, looking at the code -> http://codepad.org/XY494JZ8, is there anything that could be changed to help free some up?

The available free memory is output every 6 seconds along with the results of the ping.

Appreciate any assistance, thanks.

KenF

First trick.  Wherever you have print("something in inverted commas")
replace it with print(F("something in inverted commas"));

AWOL

What's the point of StrContains?

What's wrong with strstr_P?

UKHeliBob

It's not much, but do all of these variables need to be ints or could some/all be bytes ?
Code: [Select]
const int FanSwitchPIN = 7;
const int RebootPIN = 8;
const int TempSensorPIN = 0;

int buttonState = 0;
int TempSensor = 0;
int BadPingCnt = 0;
int PCReset = 0;

The pin numbers obviously don't.  Are there any local variables in functions that could be declared as smaller data types ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Riva

Does your linked code work?
Code: [Select]

Serial.println("setup loop");
Ethernet.begin(mac, ip);
server.begin();           // start to listen for clients
Serial.begin(9600);

I did not realize you could start printing to serial before it's initialized?
Don't PM me for help as I will ignore it.

joebert

I'd re-evaluate the use of "printf / sprintf", and whether their convenience is worth allocating 12.5% of my memory to "buffer".
I'm guessing "__FlashStringHelper*" errors are why the F() macro isn't being used inside sprintf lines, which ties up another 55+ bytes for storing the templates for those sprintf calls.



"PingTime" is overflowing, it has room for "Reboot". Maybe you meant to use "buffer" instead?

Code: [Select]
printf(PingTime,"%s", "Rebooting");



It looks like the main issue comes down to output buffering being anticipated, but strayed away from. So that sizable "buffer" variable, combined with smaller redundant variables designed to improve readability, but eventually leading to variable confusion like what happened in "PingTime", ends up eating more memory than is needed.

BassTeQ

Thanks all for the replies, yes the code does work.
I'll try as suggested and reply with the outcome next week.

Much appreciated.

Go Up