-
-
Notifications
You must be signed in to change notification settings - Fork 34
Home
One of the most frequently asked questions is - "Why isn't there a true print function included in the library?" Many display libraries include a print/printf/println function to mimic the features of the Arduino Serial library. The reason I didn't include it in ss_oled is because it goes against one of the goals of the library - small size. By adding a formatted print function, it would necessarily add a dependency on printf() or I would need to write similar code. If you need to print formatted output of numbers, strings, etc, you can do it like this:
char szTemp[32];
sprintf(szTemp, "My value = %d", myValue);
oledWriteString(0,0,0, szTemp, FONT_NORMAL, 0 1);
The printf() functions in the C runtime library are pretty large and I didn't want them to be a forced dependency within ss_oled.
Microcontrollers often have meager resources available (RAM/ROM) and one of the goals of ss_oled is to minimize the size of the code, font data and RAM usage. The majority of OLED displays are write-only; this means that we can't read back the data after it's written. For some operations (e.g. drawing lines) the new pixels need to be combined with the existing pixels on the display. If we're unable to read the display memory, how can we combine new and old pixels? The answer is to create a "back buffer" which has a copy of the display memory in our local memory. A 128x64 1 bit per pixel display needs (128x64)/8 = 1024 bytes. On the simplest of MCUs (ATtiny series), they usually have less than that amount of RAM. This means that we can't keep a copy of the display in memory and are limited to write-only operations such as drawing text which overwrites the background pixels. On 'larger' MCUs like the ARM Cortex-M, ESP32 and newer AVRs, there is enough RAM to keep a copy of the back buffer. This brings us back to the render flag. On systems which support a back buffer, it can be a speed advantage to prepare your drawing in memory, then write it to the display at a later time. The ss_oled functions support this option through the render flag. Setting the render flag to true tells the library to transmit the data immediately to the display (and keep a copy in memory if there is a back buffer). If you do operations with the render flag set to false, they'll only occur on the back buffer and when you're ready to display it, call the oledDumpBuffer() function.