Pico Explorer: rgb5x5 and matrix11x7 breakouts with on-board display

I’m using the standard Pimoroni UF2 image on the Pimoroni Pico Explorer product, and have got the RG5x5 and Matrix11x7 Breakouts working.

Loading the PicoGraphics and DISPLAY_PICO_EXPLORER modules, etc, works fine, along with the Breakout modules.

It goes wrong when I initiate a display, ie:

display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)

The Python program works fine with the two Breakouts, without initiating the display, but things go wrong when the display is initiated. The program stops functioning and the COM port disconnects.

I don’t think this is a memory issue, as I’ve got 157k remaining before I initiate the display.

I’m assuming the display is SPI, so I don’t think it’s conflicting with the I2C Breakouts. The display works if I initiate this by itself.

Any ideas, or things to check?

============================

Here is the program:

#!/usr/bin/env python

import random
import time
import gc

from pimoroni_i2c import PimoroniI2C
from breakout_rgbmatrix5x5 import BreakoutRGBMatrix5x5
from breakout_matrix11x7 import BreakoutMatrix11x7
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
from pimoroni import Button
from pimoroni import Analog, Buzzer
from pimoroni import PICO_EXPLORER_I2C_PINS

i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)

print(“Initialising Breakouts…”)
matrix11x7 = BreakoutMatrix11x7(i2c)
rgbmatrix5x5 = BreakoutRGBMatrix5x5(i2c)

print(“Initialising Display…”)
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)

You’d be surprised how much memory a display can use.
Try display = PicoGraphics(display=DISPLAY_PICO_EXPLORER, pen_type=PEN_RGB332)

Thanks for the suggestion, but that option isn’t supported it seems.

So, I’ve made a little progress on when the issue arises. The following program always works:

#!/usr/bin/env python
from pimoroni_i2c import PimoroniI2C
from breakout_rgbmatrix5x5 import BreakoutRGBMatrix5x5
from breakout_matrix11x7 import BreakoutMatrix11x7
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
from pimoroni import PICO_EXPLORER_I2C_PINS

i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)

matrix11x7 = BreakoutMatrix11x7(i2c)
rgbmatrix5x5 = BreakoutRGBMatrix5x5(i2c)
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)

The program executes fine. At this point, we have 126k free.

However, we have problems when adding the following:

rgbmatrix5x5.update()
matrix11x7.update()
display.update()

It works if only the breakouts are updated, or if only the display is updated. If one or more of the breakouts is updated and the display together, the pico crashes.
Perhaps someone can comment on the memory use increase when update() is called?

I have one setup running two Display Pack’s on the one Pico. They share the one display buffer, I did this to free up some memory for other things. Plus, prior to the update to Pico Graphics, it was the only way I could run two displays.

code that writes to display one
    display.update()
    display.set_pen(black)
    display.clear()

code that writes to display two
    display2.update()
    display2.set_pen(black)
    display2.clear()

I can understand re-using a buffer for two LCD displays. But, the breakouts I’m using are LED matrices, so the buffer for them should be relatively tiny (5x5 pixels, and 11x7 pixels).

But, I’m no expert. Perhaps the breakout slots on the Explorer are more for sensors which I would think use less memory.

Thanks for the replies.

I’m far from being any kind of expert, just relating what I ran into.
Just for the onboard display its 240 x 240 x 2 = 115.2 kb used of your 264kB.

For me it was 320 x240 x2 = 152.6 kb x 2 for 307 kb.

If you’re happy limiting yourself to 16 colours on the LCD, switching to a 4 bit colour palette will save you a bunch of RAM:

display = PicoGraphics(display=DISPLAY_PICO_EXPLORER, pen_type=PEN_P4)

You could also try some garbage collection between updates to reclaim some RAM:

gc.collect()

Unfortunately, setting the pen_type isn’t working:

NameError: name ‘PEN_P4’ isn’t defined

I’ve tried other pen_types, with the same error. I tried an older UF2, but the same.

I’m running the program via Thonny rather than main.py. Does that make a difference?

Shouldn’t make a difference - are you importing the pen types you want to use at the top of your code?

from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER, PEN_P4

No, I wasn’t importing it. :)

Makes no difference, though. Even loading a single breakout (11x7 led) crashes the Pico when loading the screen also. I even tried PEN_1BIT.

Assuming this is a memory issue, rather than some bug, I’m happy to restrain my need for lots of flashing lights.

I’m happy to restrain my need for lots of flashing lights.

Aw, that’s sad :( I’ll try and have a play with this combo of breakouts when I get a moment and see if I can figure out how if it’s possible to get them to co-exist. Are you using a Pico or a Pico W?

Thank you. Don’t spend too much time, as this exercise was just for fun.

I tried both Pico and Pico W, with appropriate firmware.

Thanks again.

Humor me and try. Assuming you haven’t already tried it.

    display.update()
    display.set_pen(black)
    display.clear()
    rgbmatrix5x5.update()
    matrix11x7.update()

The
display.set_pen(black)
display.clear()
only clears the buffer, it won’t blank the screen.

@hel maybe time to think about a redesign of the picographics library?! This library seems to be fat in the sense that it includes drivers for various displays. Sure, a one-fits-all lib is nice from a user perspective, but given the memory constraints it might be better to only load the necessary modules.

I could be wrong, but I believe all that gets loaded into memory is what you import?
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
Just loads what is needed for the Pico Explorer display.

Correct, but:

take a look at the examples: do you see any import statement for the display driver? You don’t, because the driver is baked into PicoGraphics. Very convenient, but not optimized.

Is not DISPLAY_PICO_EXPLORER the display driver ?

No, this is just a string constant.