Pico display pack loss of communication and corruption

I have a program that draws different colored lines to the pico display. When I run it from Thonny, I see display corruption along the edge with the B and Y buttons. Also often the code will freeze. The lines will stop drawing and communication with the pico is lost. I have to replug it to do anything. I can also reproduce the freeze using the bouncing ball demo code.

import machine 
import picodisplay as display

width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

# Set the display backlight to 50%
display.set_backlight(0.75)

r = 0
g = 0
b = 0
x = 0
y = 0
xo = 0
yo = 0
xi = 0.99
yi = 1.01
while True:
    r = r + 0.5
    if r > 255:
        g = g + 1
        r = 0
    if g > 255:
        b = b + 1
        g = 0
    if b > 255:
        b = 0
    if display.is_pressed(display.BUTTON_A):
        display.set_pen(0, 0, 0)
        display.clear()
        x = 0
        y = 0
        r = 0
        g = 0
        b = 0
    if display.is_pressed(display.BUTTON_B):
        display.set_pen(0, 0, 0)
        display.clear()
    if display.is_pressed(display.BUTTON_X):
        g = g + 1
    if display.is_pressed(display.BUTTON_Y):
        b = b + 1
    display.set_pen(int(r), int(g), int(b))
    display.set_led(int(r), int(g), int(b))
    #display.rectangle(i, height - (temperature * 4), 5, height)
    display.pixel(int(x),int(y))
    display.update()
    xo = x
    yo = y
    x = x + xi
    y = y + yi
    if x < 0:
        x = 0
        xi = xi * -1
    if y < 0:
        y = 0
        yi = yi * -1
    if x >= width:
        x = width - 1
        xi = xi * -1
    if y >= height:
        y = height - 1
        yi = yi * -1

I’ve seen this also when run from Thonny on my Explorer Base display. Not sure why yet. Does the program run ok when powered up but not connected to a computer?

Yep, if I rename the program main.py and reboot the pico ALL of my programs run just fine. No screen corruption, no freezing.

That is very interesting.
I will give it a try as I’ve been getting similar screen corruption, mainly at the bottom but occasionally at the top, and loss of connection with my PC.

Is it the 264kB of SRAM that is the issue?

Yeah, if you name it main.py, and save it “to the PICO”. It then runs on / from the PICO. Automatically on bootup, all you need is power.

I’ve used the garbage collection library and it shows plenty of room when this is happening. The more changes I make in Thonny the worse it gets but I’ve been running from the Thonny green button not saving as main.py, which is very Mu and Circuitpython.

I saved as main.py once, just to see if I was doing it correctly. Other than that I’ve been running my code from Thonny on my Pi400. I haven’t left it running for any amount of time though. Nothing more than maybe an hour.

I left the Pimoroni display example (bouncing balls) running all day today. Its running from Thonny on my Pi400. I got one lockup early on.

Connection lost (read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port))
Use Stop / Restart to connect.

Doing a Stop and Run in Thonny fixed it. And its been running for several hours now without issue. I didn’t see any corruption when it locked up, the image just froze.
Just a FYI.

EDIT: PICO Display Pack on the Omnibus expander. Nothing plugged into the other spot.

Thanks for trying that and passing on the info.
I’ve been keeping all the programs on my PC and running from the GREEN go button on Thonny. I’m going to try the CP way with main.py on the PICO. This does put more wear on the USB socket on the PC although you always get a re-initialised PICO as it is powered up to run.

I put a female to female jumper on the run pin on the spare socket on my Omnibus. I just connect the other end to a - pin and its reset / rebooted.
One thing I’ve noticed when I do that is, I have to click the Red Stop in thonny. If I don’t, there is no save or Run option they are greyed out. Even if I do a Stop before doing a reset on the PICO.

CircuitPython with Mu does all this so much better and I2C libraries are available.

I’ve used Mu with my BBC MicroBits. And with my Arduino’s too I think?

I updated the .uf2 after noticing there was a newer one from Pimoroni. Things are much better behaved now. I see less screen corruption and demo.py runs much longer without hanging.

Moving to a better place