Well, I’ve had an interesting time analyzing my program bit by bit or should that be byte by byte!
I have declared a total of 58 global variables, most of then unsigned int’s and I really cannot reduce the count without compromising what I want to achieve. But correct me if I’m wrong, 58 int’s only take up 116 bytes!
So I decided to analyze the program and find out just where all my dynamic memory was going. I started with a blank Blynk sketch for the Arduino Mega + ESP8266 shield, compiled it and noted the memory usage. Then one by one I added the various sections, compiled it and noted the memory usage.
Basic Blynk sketch dynamic memory usage 33%
Pre-setup dynamic memory usage 41%
Setup dynamic memory usage 68%
Main program dynamic memory usage 81% (main program has 8 void routines + loop)
So apart from the main program the biggest memory hungry animal is the setup, so I looked into what I had in there, interesting…
I’m using 6 Blynk timers, the dataSave timer is commented out because I’ve taken out the SD card save routine.
timer.setInterval(500L, airData); //Run airData every 0.5 seconds
timer.setInterval(45000L, battery); //Update battery voltage every 45 seconds
timer.setInterval(1000L, time_clk); //Check time clock every 1 second
timer.setInterval(30000L, clk); //Update clock every 30 seconds
timer.setInterval(5000L, airData_print); //Update screen every 5 seconds
timer.setInterval(60000L, sendData); //Send data to Blynk every 60 seconds
//timer.setInterval(900000L, dataSave); //Save data to SD card every 900 seconds (15 minutes).
These 6 timers take up 826 bytes or 10.1% of dynamic memory and there doesn’t seem to be any correlation between time and bytes i.e.the 60000L takes up 330 bytes and the 45000L only 14 bytes.
Are my findings correct and is there any way to reduce this memory usage?