user48730: I'm using ESP8266 and 4 dot Matrix Tiles, to display clock ( updates using NTP and WiFi ).
Everything is working well, but only when I'm constructing text using a const char* type.
But, since I wish to construct text as sprintf(temp, "12:00"); or char temp[20]="12:00\n; creates gibberish text.
MD_Parola dotMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void updateTime()
{
  char clk[10];
  char dat[10];
  char temp[10];
  sprintf(temp, "12:00"); // <---- this ways failes
  const char *t = "12:00"; // <---- this way succeeds
  dotMatrix.displayText(t, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}

link to library
Appreciate explanation how to construct text not as const char*

user42015: The library documentation states:

The library does not allocate any memory for the text message

That suggests, that the buffer has to be valid beyond the execution of the displayText() function. But as you declare it inside of your updateTime() function, it the buffer gets out of scope, when exiting that function. The memory space can then be reused by the rest of the program. At that point the library will still have the pointer to the old location, though that pointer can now be considered invalid. Thus you are just reading, what the compiler decided to place in that memory location.
To solve that, you need to keep the buffer variable in scope. You can do this by moving the declaration to the global scope.

48730: <p>I'm using ESP8266 and 4 dot Matrix Tiles, to display clock ( updates using NTP and WiFi ).
Everything is working well, but only when I'm constructing text using a <code>const char*</code> type.</p>
<p>But, since I wish to construct text as <code>sprintf(temp, &quot;12:00&quot;);</code> or <code>char temp[20]=&quot;12:00\n;</code> creates gibberish text.</p>
<pre><code>MD_Parola dotMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void updateTime()
{
  char clk[10];
  char dat[10];
  char temp[10];
  sprintf(temp, &quot;12:00&quot;); // &lt;---- this ways failes
  const char *t = &quot;12:00&quot;; // &lt;---- this way succeeds
  dotMatrix.displayText(t, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
</code></pre>
<p><a href="https://majicdesigns.github.io/MD_Parola/class_m_d___parola.html" rel="nofollow noreferrer">link to library</a></p>
<p>Appreciate explanation how to construct text not as <code>const char*</code></p>
 42015: <p>The library documentation states:</p>
<blockquote>
<p>The library does not allocate any memory for the text message</p>
</blockquote>
<p>That suggests, that the buffer has to be valid beyond the execution of the <code>displayText()</code> function. But as you declare it inside of your <code>updateTime()</code> function, it the buffer gets out of scope, when exiting that function. The memory space can then be reused by the rest of the program. At that point the library will still have the pointer to the old location, though that pointer can now be considered invalid. Thus you are just reading, what the compiler decided to place in that memory location.</p>
<p>To solve that, you need to keep the buffer variable in scope. You can do this by moving the declaration to the global scope.</p>
