Flickering 1.3" SPI Colour Round LCD

Hi all, I am using the 1.3" round LCD as a display for a project. Everything on it works fine until I connect the Backlight wire to the BL GPIO. Once its connected it causes the screen to flicker slightly. I can adjust the backlighting fine with an encoder, but it still flickers at all settings. As soon as I disconnect the BL line from its GPIO it stops flickering and is steady again.

Here is the code in my header file. I have checked the Pimoroni driver code and it definitely sets up the BL GPIO as a PWM.


#define SPI0_CS     5
#define SPI0_RX     4
#define SPI0_TX     3
#define SPI0_SCK    2
#define BACKLIGHT   1

const int SPI0_DC = SPI0_RX;

SPIPins SPI_gpio_pins = {PIMORONI_SPI_DEFAULT_INSTANCE, SPI0_CS, SPI0_SCK, SPI0_TX, SPI0_RX, SPI0_DC, BACKLIGHT};
ST7789 st7789(DISPLAY_WIDTH, DISPLAY_HEIGHT, ROTATE_0, IS_ROUND, SPI_gpio_pins);

The main function is a fairly simple WHILE loop to update the display. I have left alot of unrelated code out for clarity.


int main(){
    stdio_init_all();
    multicore_launch_core1(core1_entry);

    st7789.set_backlight(255);
    graphics.set_pen(BLACK);
    graphics.clear();
    st7789.update(&graphics);
    sleep_ms(500);

    while(true){
        drawBG_Image(_binary_gauge_tga_start, 240, 240);
        displayAlt(Altitude);
        st7789.update(&graphics);
    }
}

You may want to post the full code?
Code like the following can cause flickering if its called in the While True loop.

    graphics.set_pen(BLACK);
    graphics.clear();
    st7789.update(&graphics);

Don’t see why it would make a difference as it works fine with no flickering as long as the backlight (BL) cable isn’t connected to the BL GPIO. Here’s the full ‘while’ loop though:


    while(true){
        AltBug += 500 * enc.delta();        // Change AltBug by 500'
        if(AltBug > 25000) AltBug = 25000;  // Max - Set to max cabin altitude without supplementary O2 available.
        if(AltBug < 5000) AltBug = 5000;    // Min - Arbitrarily set to 5000' **** Readjust as necessary ****

        drawBG_Image(_binary_gauge_tga_start, 240, 240);
        displayTemp(Temperature);                    // Display the temp in Fahrenheit
        displayAlt(Altitude);                        // Display the numerical altitude in feet
        drawPointer(Altitude);                       // Draw the needle pointer of the cabin altitude
        drawAltBug(AltBug);                          // Draw the Altitude Bug
        st7789.update(&graphics);
    }
}

I only call st7789.update(&graphics); once within the while() loop.

Ok, apologies, it’s not that then. It got me on my Interstate 75, more of a flash though than a flicker.
I see that you have PWM setup on that GPIO Pin to control the backlight.
It sounds like that pin is being “slowly” cycled hi, lo, hi, lo?
Too slow a PWM maybe?

No worries and I appreciate that you looked at it. It has really gotten me befuddled. The Pimoroni ST7789 driver should work as written:


  void ST7789::set_backlight(uint8_t brightness) {
    // gamma correct the provided 0-255 brightness value onto a
    // 0-65535 range for the pwm counter
    float gamma = 2.8;
    uint16_t value = (uint16_t)(pow((float)(brightness) / 255.0f, gamma) * 65535.0f + 0.5f);
    pwm_set_gpio_level(bl, value);
  }

But the flickering happens whenever the wire is connected to the GPIO. Pull it out and I get full, steady brightness with zero flickering. If I put a sleep_ms() in the while(true) loop, the flickering slows down (oddly enough), so it may have something to do with one of the display/draw functions, but I just can’t see how. I’ll keep investigating.

I have several of the Pimoroni SPI LCD displays on the go here. I haven’t bothered to setup PWM adjustable backlights on any of the Pi connected ones. Just to lazy if I’m honest.
I do make good use of the backlights on my Pico setups though. Mainly because its easy peasy to set the level compared to on a Pi.

1 Like

SOLVED: In a strange twist-of-fortune I decided to move the backlight control to a different GPIO (Not GPIO 0 or 1) and the flickering is gone. It seems the flickering started once I enabled STDIO USB or UART in CMakeLists, Changing the GPIO stopped it, as did removing those lines in CMakeLists.

GP0 and GP1 can be used for UART on a Pico. It must have defaulted to those pins when enabled?
Raspberry Pi Pico GPIO Pinout