Interacting with display in loop function does not work #148
-
Hardware
Setup
IssueThe code in the When I uncomment the code in the
I also lose the connection to the board if I shrink the void showValue(String s)
{
display.firstPage();
display.nextPage();
} In this simplified case, calling Why can I not interact with the display in the Code#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
// The pinouts were obtained from the "e-Ink Logic Pins" section in
// the following:
// https://learn.adafruit.com/adafruit-rp2040-feather-thinkink/pinouts#e-ink-logic-pins-3143653
#define EPD_DC PIN_EPD_DC
#define EPD_CS PIN_EPD_CS
#define EPD_BUSY PIN_EPD_BUSY
#define EPD_RESET PIN_EPD_RESET
#define EPD_SCK PIN_EPD_SCK
#define EPD_MOSI PIN_EPD_MOSI
// The display constructor was copy/pasted from the following:
// https://github.com/ZinggJM/GxEPD2/blob/1.6.4/examples/GxEPD2_HelloWorld/GxEPD2_display_selection.h#L138
GxEPD2_BW<GxEPD2_213_GDEY0213B74, GxEPD2_213_GDEY0213B74::HEIGHT> display(
GxEPD2_213_GDEY0213B74(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY)
);
void showValue(String s)
{
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
uint16_t box_x = 10;
uint16_t box_y = 15;
uint16_t box_w = 70;
uint16_t box_h = 20;
uint16_t cursor_y = box_y + box_h - 6;
display.setPartialWindow(box_x, box_y, box_w, box_h);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.setCursor(box_x, cursor_y);
display.print(s);
}
while (display.nextPage());
}
void setup()
{
// The handling of alternate SPI pins was adopted from the following example:
// https://github.com/ZinggJM/GxEPD2/blob/1.6.4/examples/GxEPD2_Example/GxEPD2_Example.ino#L174
SPIClassRP2040 SPIn(spi0, EPD_BUSY, EPD_CS, EPD_SCK, EPD_MOSI);
display.epd2.selectSPI(SPIn, SPISettings(4000000, MSBFIRST, SPI_MODE0));
display.init();
showValue("0");
// This block of code works.
delay(1000);
showValue("1");
delay(1000);
showValue("2");
delay(1000);
showValue("3");
}
void loop() {
// The same block of code as above but does not work.
// delay(1000);
// showValue("1");
// delay(1000);
// showValue("2");
// delay(1000);
// showValue("3");
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Is local to setup() in your code. It is no longer valid outside setup(). Needs to be in global scope. |
Beta Was this translation helpful? Give feedback.
Is local to setup() in your code. It is no longer valid outside setup(). Needs to be in global scope.