GxEPD2 + Waveshare 7.5 (yellow), print text in loop

Hello, this is my first topic on this forum :wink:

Hardware: ESP8266 (nodeMCU 1.0 ESP-12F) (e-paper esp8266 driver board from waveshare)
E-ink: 7.5 inch, 3 colored, 640x384px

What I want to achieve:
I want download text from json and print it on display. For simplified version I use array of chars, i try iterate over it and display this text with small margin on right side.

What's is a problem:
Text is displayed but its shuttered. Preview image is attached.

Code used to display it:

void drawPage1()
{
  int mUp = 90;
  Serial.println("drawPage1 - start");
  const char pl[] = "Lorem Ipsum";
  const char* l[] = {"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n",
                     "in reprehenderit in voluptate velit esse cillum dolore eunon \n",
                     "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\n",
                     "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n",
                     "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
                    };

  display.setTextColor(GxEPD_WHITE);

  display.setRotation(0);
  display.setFullWindow();;
  display.firstPage();

  int16_t tbx, tby; uint16_t tbw, tbh;
  display.setFont(&FreeSansBold12pt7b);
  display.getTextBounds(pl, 0, 0, &tbx, &tby, &tbw, &tbh);
  do
  {
    display.fillScreen(GxEPD_WHITE);
    display.fillRect(display.width() - tbw - 60, 20, tbw + 40, 40, GxEPD_BLACK);
    display.drawLine(20, 60, display.width() - 20, 60, GxEPD_BLACK);
    display.setFont(&FreeSansBold12pt7b);
    display.setCursor(display.width() - tbw - 40, 20 + FreeSansBold12pt7b.yAdvance);
    display.setTextWrap(1);
    display.setTextColor(GxEPD_WHITE);
    display.print(pl);


    for ( int i = 0; i < sizeof(l) / sizeof(char *); i++ )
    {
      if (i != 0) {
        mUp = display.getCursorY();
      }

      display.setFont(&FreeSans9pt7b);
      display.setTextColor(GxEPD_BLACK);
      display.setCursor(20, mUp);
      display.print(l[i]);
      Serial.print(l[i]);
    }
  }
  while (display.nextPage());

  Serial.println(display.getCursorY());
  Serial.println("drawPage1 - done");
}

How should i properly do this ?

OK i get it :wink:
If somone need this. I move text and loop to second function and call they on dp-while statement.
Working code:

void drawPage1()
{

  Serial.println("drawPage1 - start");
  const char pl[] = "Lorem Ipsum";


  display.setTextColor(GxEPD_WHITE);

  display.setRotation(0);
  display.setFullWindow();
  display.firstPage();

  int16_t tbx, tby; uint16_t tbw, tbh;
  display.setFont(&FreeSansBold12pt7b);
  display.getTextBounds(pl, 0, 0, &tbx, &tby, &tbw, &tbh);
  do
  {
    display.fillScreen(GxEPD_WHITE);
    display.fillRect(display.width() - tbw - 60, 20, tbw + 40, 40, GxEPD_BLACK);
    display.drawLine(20, 60, display.width() - 20, 60, GxEPD_BLACK);
    display.setFont(&FreeSansBold12pt7b);
    display.setCursor(display.width() - tbw - 40, 20 + FreeSansBold12pt7b.yAdvance);

    display.setTextColor(GxEPD_WHITE);
    display.print(pl);

    _displayText();

  }
  while (display.nextPage());


  Serial.println(display.getCursorY());
  Serial.println("drawPage1 - done");
}

void _displayText()
{
  int mUp = 90;
  const char *l[] = {"Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n",
                     "in reprehenderit in voluptate velit esse cillum dolore eunon \n",
                     "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\n",
                     "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n",
                     "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
                    };


  for ( int i = 0; i < sizeof(l) / sizeof(char *); i++ )
  {
    if (i != 0) {
      mUp = mUp + FreeSans9pt7b.yAdvance;
    }

    display.setFont(&FreeSans9pt7b);
    display.setTextColor(GxEPD_BLACK);
    display.setCursor(20, mUp);
    display.print(l[i]);
    Serial.print(l[i]);
  }

But now question is... why ? this work instead of first solution ?

@daredzik,

make sure that every iteration of the page loop draws the same.
Most issues are caused by a variable that is initialized outside of the loop but modified and used in the loop.
I suspect it is caused by your mUp.

Jean-Marc

This topic was automatically closed after 120 days. New replies are no longer allowed.