esp32 + md_parola + ds1820 = large headache

Hey guys, I bought yesterday esp32 and after few hours of playing I decided to try little more difficult porting from arduino to esp32.

What is the problem? When I try

float tempC = round(sensors.getTempC(deviceAddress)*10)/10.0;
  if (oldTemp != tempC) {
    Serial.print("Temp C: ");
    Serial.println(tempC);
    char result[4]; 
    dtostrf(tempC, 3, 1, result); 
    P.setFont(M[0].pFont);
    P.displayText(result, PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
    //P.displayText("TEST", PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_SCROLL_LEFT, PA_NO_EFFECT); 
  }

On arduino work great. On esp32 I get only first number. When I try something like commented line (with "TEST") display work like it shold do. I even tried: char result[5]="TEST"; only got T on display.

Is it problem with md_parola library or the problem is in me? Thank you in advance.

    char result[4];
    dtostrf(tempC, 3, 1, result);

Unless you are dealing with single digit temperatures, your array is too small. 17.4 is 4 characters, plus a terminating NULL means a 5 element array minimum.

If the temperature is greater than 10, you are writing beyond the end of the array, and stomping on memory you don't own. You have no control over what happens when you do that. So, don't do that.

So, what IS the temperature?

It is room temperature (currently 26.4C). I tried with result[5] nothing happend

veljani: It is room temperature (currently 26.4C). I tried with result[5] nothing happend

You used a larger array, and got worse results? Hard to believe.

Not worse, the same. Nothing new happend. I got number 2, and when temperature changed I got another 2, so on display was 22, and after that 222... When I switch back to Arduino Uno, everything works like it should do.

|500x281

The problem is likely in the code you didn't post, or in how the library is implemented for the non-Arduino.

Ok, when I do next:

char* result="12.3"

it displays properly.

How to convert tempC (float) to result?

How to convert tempC (float) to result?

You are calling dtostrf() already, which does that. Have you printed the array that dtostrf() writes to, to be sure that it contains what you think it should?

    char result[4]; 
    dtostrf(tempC, 3, 1, result); 
    P.setFont(M[0].pFont);
    P.displayText(result, PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);

As explained in the library documentation, the text buffer should be global, or at least static, and persist during the time it takes for animation to complete. Parola does not copy the data to an internal buffer in order to reduce memory requirements.

P.displayText() and the later P.animate() expects the data will be available between the calls. Your result array is local scope and will not be around any more once the animate() method is called, so the results will vary between compiles and architectures, as you have found out. Declaring it as a pointer to a constant means that data is not overriden and retained during the animation.

Your code will work if you use P.print() as the animate() is built into the print() method, or if you use animate() straight after the call to displayText().


That’s it! Problem solved, result should be global variable. Thanks man a lot!

Sorry for opening up an old thread. I am curious what kind of display did you use? Is it LED array? How big panel? I am thinking about driving a 3 panel display each with 4x max7219. Not sure if I will be able to power it with ESP32.