BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

BlynkTimer and dynamic memory usage high


#1

BlynkTimer uses up a ton of dynamic memory in the declaration alone. Memory changed from 46% to 62% Take a look.

Commented out and compiled
//BlynkTimer blynkOutputTimer;

Global variables use 1,274 bytes (62%) of dynamic memory, leaving 774 bytes for local variables. Maximum is 2,048 bytes.

Uncommented and compiled
BlynkTimer blynkOutputTimer;

Global variables use 952 bytes (46%) of dynamic memory, leaving 1,096 bytes for local variables. Maximum is 2,048 bytes.

Everything else involved with BlynkTimer is disabled in the code. Just the declaration itself takes up memory space.

Adding a second BlynkTimer took it to max
BlynkTimer blynkOutputTimer;
BlynkTimer trackingIntervalTimer;
Global variables use 1,596 bytes (77%) of dynamic memory, leaving 452 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur.

How can I get BlynkTimer to not use so much dyno memory? I realize that it is based on SimpleTimer. Perhaps Simpletimer is the culprit.

Any ideas to reduce mem?
Thanks
Dean


#2

What are you using? An UNO? … ATTiny85? … an actual dead bug??

I run a large Blynk sketch on an Arduino MEGA with a whopping 256 KB, of which 8 KB is used by the bootloader, and over a dozen running timers…

Sketch uses 47394 bytes (18%) of program storage space. Maximum is 253952 bytes.
Global variables use 3174 bytes (38%) of dynamic memory, leaving 5018 bytes for local variables. Maximum is 8192 bytes.

#3

Hi Gunner, Thanks so much for responding. This is good feedback. I am working with an UNO. In perspective, your dozen timers are not using nearly the dynamic space as mine. My two timer declarations alone go from 952 to 1596 bytes. That’s 644 bytes increase! A dozen would break the bank in my case. But I should be able to use at least 3 or 4 timers. I must be doing something wrong here.


#4

You don’t need to declare a separate instance of Blynk timer for each timer you use, one declaration can support multiple timers; all doing different things and running at different intervals.

I can’t remember exactly how many timers per instance (10 springs to mind, but as I rarely use timers it’s not something I tend to worry about) but I’m sure @Gunner will be able to tell you.

Pete.


#5

Yes, it is a bit limited on memory with only 32 KB :grimacing:

With Blynk Timer, it is 16 timer instances per timer object (up from the 10 of SimpleTimer)

BlynkTimer timer;

timer.setInterval(500L, CNTRDisplay);  // Update Loop counter Widget
timer.setInterval(1000L, timeDisplay);  // Update Time Widget
timer.setInterval(1750L, AnalogSensors);  // Misc analog sensors on CodeShield
timer.setInterval(2040L, whiteLED);  // White LED button monitor on CodeShield
timer.setInterval(4050L, SuperCapVoltage);  // Super Cap charge display
timer.setInterval(30060L, DHTSensor);  // DHT22 sensor
timer.setInterval(30900L, thermTemp);  // Thermistor  on CodeShield
timer.setInterval(60040L, sendUptime);  // Up Time Widget
timer.setInterval(400090L, dateDisplay);  // Update Date Widget
... and so on

#6

This makes total sense. One timer with multiple function callbacks. This is exactly what I need. Thanks!!


#7

better buy a nodemecu with 4M RAM for only 2.50 $, no ?:scream: