Help reducing RAM usage

Hello everyone,

I'm having many troubles regarding RAM memory usage and I would like your help to reduce it anyhow in my code to solve my problem.

I'm sending attached the code.

Thank you very much. Best regards,

Argh_V0_07.ino (14.5 KB)

How much SRAM is it using?

I wasn't able to measure it. I tried to use as described here but the code didn't run well: Measuring Memory Usage | Memories of an Arduino | Adafruit Learning System.

Are there any other ways to measure the SRAM used?


When I compile that sketch using 1.5.5 Arduino IDE, it says:

Global variables use 1,217 bytes (59%) of dynamic memory, leaving 831 bytes for local variables. Maximum is 2,048 bytes

I wonder whether you may have a memory corruption problem rather than a lack of RAM. I see the sketch includes some DIY functions that replicate conventional C runtime library string functions, so perhaps there is a bug in one of these.

You are at the mercy of the SD and Ethernet libraries which both need large

Checkout the source of these to see if there comments about reducing the footprint.
There may be other libraries or versions that use a bit less RAM.

Thanks for the replies!

Actually my real problem is that when I load the webpage from the SD card the images usually won't load correctly.

I think that this problem is caused by an excessive RAM usage, because before optimizing the SRAM, the code would not even run. I optimized the SRAM following these tips (Optimizing SRAM | Memories of an Arduino | Adafruit Learning System) and manage to make my code work 90% (the only problem are the images).

I tried also to put the images in Base64 inside the HTML code trying to reduce the RAM usage, but it didn't work either.

It's a very strange problem. Sometimes the images load correctly, then other times they don't.

Sounds like you need a 1284P board, with its 16K of SRAM (twice that of a Mega2560).
I offer them in several form factors, including with an SD card: