Need help saving Global variables that use 2135 bytes (104%) of dynamic memory

Hi Guys,
First post on the forum.
I am trying to putting together a rfid reader, buzzer, oled display and connecting it thru mysensors.
I am creating a homemade alarm system and this will be the controlpanel.
For the project i am using a arduino nano.

Everything worked great until i added the mysensors part and i got the error message:

Global variables use 2135 bytes (104%) of dynamic memory

I googled a lot and tried a lot of solutions like:
Moving data to the ram with the F command in strings.
Switching ints to bytes.
removing all debug options

i am not expert programmer and hoped someone who is can help me.
My programming skils are mostly copy / paste of known working codes and analyzing them and modifying them until they do what i want with a lot of trial and error :wink:
So my appologies in advance that it is quite messy.
Hopefully someone can help me.

Thanks in advance for your comments.

Please see my code in the next reply as the message taking more then 9000 characters.

{taps fingers impatiently}

Jep sorry can't get over the 9.000 max characters rule.
My sketch is about 23.000 characters.
I will find a forum with Les rules.

Thanks in advance for your help.

Moderators please remove this thread.

If it is too big, just attach the code.

TolpuddleSartre:
If it is too big, just attach the code.

Didnt know that i could do that :sleeping: :-X ::slight_smile: .
My appoligies.
Please find the code attached.

RIFD_OLED_PIEP_GRT.ino (22.3 KB)

I'd get rid of the Strings.

sjap84:
Didnt know that i could do that

There's this amazing thread called "How to use this forum - please read" at the top of every board. Reading instructions is crucial if you want to make it in the programming world.

So the problem started when you included this MySensors.h header file right? Maybe we should look in there? Can you post that as well?

TolpuddleSartre:
I'd get rid of the Strings.

Although I totally agree, I suspect that that will only make it worse; I think that the IDE does not count the size of the internal c-string of the String when it calculates memory usage.

Can't look at the code now as I'm using a cell phone. Maybe use of F macro?

sterretje:
Maybe use of F macro?

Already used, though obviously not for the Strings

TolpuddleSartre:
I'd get rid of the Strings.

Thanks for your reply I would if I knew how.
In my case I use strings to show specific messages on the oled screen.

Delta_G:
There's this amazing thread called "How to use this forum - please read" at the top of every board. Reading instructions is crucial if you want to make it in the programming world.

So the problem started when you included this MySensors.h header file right? Maybe we should look in there? Can you post that as well?

Thanks for your reply also,
I am ashamed I didn't read the getting started.
The mysensor.h is the default my sensors setup as used on https://www.mysensors.org
Didn't modify it and is being used on all my mysensors project without a issue.
I do expect that this last peace of code did put to much data in the memory.
Unfortunately I need it to communicate with the mysensors gateway.

As mentioned I did quite some googling and tried most of the solutions mentioned.
F command, changed int to byte etc.
But none of these things changed the 104 procent.

A alternative was mentioned to get a mega as this has more memory but I would use that as a last resort.
Thanks in advance to you all for your help.

n my case I use strings to show specific messages on the oled screen.

No, you use Strings.

TolpuddleSartre:
No, you use Strings.

I hope you mean I spelled it wrong or is there really a difference in programming?

An instance of the String class uses six bytes of RAM, whether or not the String contains any data.
Eliminating Strings is not going to fix your problem, but it may go a way to get to your goal.

If I'm honest, I think you need another, bigger processor, or you need to rewrite some of the libraries.

But don't use Strings.

TolpuddleSartre:
An instance of the String class uses six bytes of RAM, whether or not the String contains any data.
Eliminating Strings is not going to fix your problem, but it may go a way to get to your goal.

If I'm honest, I think you need another, bigger processor, or you need to rewrite some of the libraries.

But don't use Strings.

What could you use to save small pieces of text except for strings?

sjap84:
What could you use to save small pieces of text except for strings?

You could use strings rather than Strings
Specifically, you could use constant strings, held in flash memory.

TolpuddleSartre:
You could use strings rather than Strings
Specifically, you could use constant strings, held in flash memory.

Ok I would try that out see if it will make any difference.
Thanks

sjap84:
The mysensor.h is the default my sensors setup as used on https://www.mysensors.org

I went to that page but I didn't see that header file. If you'll post it or at least a link directly to it (a clickable link this time please) then I'll look. I'm not going to go hunt all over hell's half acre for your header file. But the fact that the memory usage jumped when you started including that is a HUGE clue that you should be paying attention to more than a bunch of guys who can't see the problem jumping on the first suspect they all look for.

Delta_G:
I went to that page but I didn't see that header file. If you'll post it or at least a link directly to it (a clickable link this time please) then I'll look. I'm not going to go hunt all over hell's half acre for your header file. But the fact that the memory usage jumped when you started including that is a HUGE clue that you should be paying attention to more than a bunch of guys who can't see the problem jumping on the first suspect they all look for.

Please find the file here:
mysensors.h

Link no good. Why don't you just post it or attach it before I get too old to help.

Delta_G:
Link no good. Why don’t you just post it or attach it before I get too old to help.

Damn… here you go my apologies.

MySensors.h (12.2 KB)