Hi guys, first time asking a question here, and quite new to coding & Arduino.
I have written a sketch for the "Arduino Sensor Kit". What the code does is reading all sensor values and then based on user input (via button) display either:
The reading from an individual sensor
Readings from all sensors at the same time
Only the sensor reading that triggered an alarm
The alarm function can also be inhibited by the user using the same button.
Now, everything works great when printing on Serial interface, but the moment I want to display any of the above on the OLED 0.96" display, the program either stops or start printing garbage on the serial interface, without displaying anything on the OLED display.
If I remove all the "user interface" and just do a simple display on the OLED, then it works. I have tried many different approaches, but keep running into issues with the OLED.
Thanks for your quick reply.
I am using an Arduino UNO clone.
Displaying on OLED from Setup is working fine. I have also done the (F( suggestion and was able to display some info on the OLED display.
Looks like my issue is indeed memory related. Any suggestions on how to further reduce memory usage?
Chrisbad:
Thanks for your quick reply.
I am using an Arduino UNO clone.
Displaying on OLED from Setup is working fine. I have also done the (F( suggestion and was able to display some info on the OLED display.
Looks like my issue is indeed memory related. Any suggestions on how to further reduce memory usage?
Your posted program (no use of the F macro) when compiled for a UNO here;
Sketch uses 23836 bytes (73%) of program storage space. Maximum is 32256 bytes.
Global variables use 1115 bytes (54%) of dynamic memory, leaving 933 bytes for local variables. Maximum is 2048 bytes.
I know that some Adafruit libraries need a display buffer for those displays. Almost all the display functions operate on the buffer and then you call display.display() to send the bits to the physical OLED.
It may be that when you never called any of those functions that hit the buffer, the optimizer threw it away. Alternatively, it may be that that buffer is created by a malloc call that wouldn't be counted as part of your dynamic memory by the compiler.
Grab a copy of the freemem function if you're curious and see how much RAM you have at the end of setup.
If you've got a graphical display (not solely text), take the XY resolution of your display.
Multiply the two numbers together, and divide the result by 8.
Unless you've got a partial frame buffer (and consequently slower display updates) that number represents how many bytes the library probably reserves for its frame buffer AFTER the sketch has started.