Dynamically check RAM usage while running ?

I have a fairly mature sketch for an Arduino with
(1) DS1307 RTC
(2) SSD1306 OLED
(3) Dallas temperaure sensor.

When I load it into a UNO R3. The sketch compiles but the code locks up mid stream . If I strip code until it comples to
< 22,200 bytes program space
< 840 bytes dynamic memory
I can run 1 & 2 together, or 2 & 3, but not all three at once.

The sketch has run on a MEGA no problem. So I'm pretty sure I have a memory overflow problem due to UNO R3 limitations.

I'm looking for tools/clues to help diagnose what is happening in RAM. From my dim dark Arduino memory I vaguely recall there is a way to measure & report (or log at least) dynamic memory usage while a sketch is running. e.g. heap, stack size?

Any suggestions appreciated.
TIA

I have not used it myself yet, but maybe worth a try.

A MEGA 2560.
Likely the OLED library & fonts are using more memory than the 328;has

This article has code for a function that will fix you up:

HTH

a7

1 Like

If it is 128x64, that consumes half the Uno's memory, dynamically (which does not show up in the compile/link report).

Use the SSD1306 text only library to eliminate that issue.

1 Like

indeed it is, so I'll try that text-only lib, thank you.

Good doc thank you. freeram() should do it ! :slight_smile:

Off topic: I notice it doesn't cover the Renesas R4 WifI, R4 Minima. I hope there is a similar ref for them somewhere (not just the datasheets!)

With the exception of the EEPROM examples, I guess.

I got the text-only OLED library working nicely on a UNO R3 but so far not on R4 Minima. Do you know if this lib is incompatible with Renesas boards?

What goes wrong? The text-only library docs have this disclaimer:

SSD1306Ascii runs on Arduino AVR boards, Arduino Due and many other Arduino style boards that have the SPI or Wire library.

Just tested an SSD1306 with I2C interface on an UNO R4 WiFi using the SSD1306Ascii library, seems to work ok with the example program HelloWorldWire.

I have 3 sketches that work fine on UNO R3 not on R4 ( both WiFi & Minima)

  1. RTC master uses DS1307RTC library
  2. OTEXT_master uses SSD1306Ascii
  3. TinyRTC combines 1 + 2 into a visible clock

For all these the RTC reports nothing and the OLED stays blank on R4

So I reverted to the really basic ReadTest provided with DS1307RTC library and it also cannot communicate to R4, telling me to check the circuit.
(In all tests I'm swapping in same RTC/OLED hardware & wiring)

It seems both SSD1306Ascii and DS1307RTC libs don't support I2C properly on (my) R4's ???

I haven't tried this yet ... but I will, tomorrow :slightly_smiling_face:

Just occurred to me: could be the R4's simply use a different I2C_ADDRESS .... ?

Think I may have found the problem. The DS1307RTC library calls Wire.begin() in the constructor, commenting this out in the library and calling Wire.begin() at the start of setup() appears to work.

I'm not having any problem with a simple test of SSD1306Ascii using hardware I2C.

Made some progress:
weirdly it seems SSD1306AsciiWire.h doesn't call Wire.begin() so I added

#ifdef ARDUINO_ARCH_RENESAS
Wire.begin();
#endif

and my OTXT_Master now works on R3 (using avri2c lite version) and both R4's

Similar story with my RTC_master.

I haven't got my TinyRTC combination for RTC + OLED working yet, but it can't be far away.

Thanks for the hints @david_2018

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.