Problem with latest MicroPython on Pico Plus 2 W and Display Pack 2.8

I have a clock program based on @Tonygo2’s excellent Explorer Demo ( Pimoroni Explorer Kit Tutorial ), but using the bitmap8 font, running on a Pico Plus 2 W (A4 stepping) with a Display Pack 2.8 and a Multisensor Stick.

It has been working fine on pico_plus2_rp2350-v0.0.12-pimoroni-micropython.uf2 but after I updated to pico_plus2-v1.29.0-2-pimoroni-micropython.uf2 it runs for a few minutes and then hangs, and stops printing my debug messages in the Thonny shell.

Curiously, when I press the Stop button in Thonny, the clock display jumps to the current time before the python prompt appears.

I have tried a different Pico Plus 2 W (A2 stepping) with a different Display Pack, a BME280 and an RV3028, with the same result.

I’ve also checked the sha256 of the micropython download.

When I reflashed the earlier micropython, it worked perfectly again.

Has anyone else seen this problem?

I think I may have those bits of hardware here at home. I will have to hunt around to find them. If I do find them I’ll do some trouble shooting and get back to you.

Thanks, alphanumeric. My full program runs to more than 900 lines, but here is Tony’s original program with initialisation changes to suit the Plus 2 W and Display Pack 2.8, which still shows the problem for me:

# Pimoroni Explorer Demo
# Analog/ Digital clock - Tony Goodhew, Leicester UK - 6 Nov 2024
# Uses the Multi-Sensor Stick (BME280 + LTR559 + LSM6DS3)

#from explorer import display, i2c, button_z, button_x, button_y, BLACK, WHITE, GREEN, RED, BLUE, YELLOW, CYAN
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_RGB565
from pimoroni import RGBLED
from machine import I2C

from breakout_bme280 import BreakoutBME280
from breakout_ltr559 import BreakoutLTR559
import math
import time

display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_RGB565, rotate=0, layers=2)
display.set_font('bitmap8')

i2c = I2C()

BLACK  = display.create_pen(0, 0, 0)
WHITE  = display.create_pen(255, 255, 255)
GREEN  = display.create_pen(  0, 255,   0)
RED    = display.create_pen(255,   0,   0)
BLUE   = display.create_pen(  0,   0, 255)
YELLOW = display.create_pen(255, 255,   0)
CYAN   = display.create_pen(  0, 255, 255)

led = RGBLED(26, 27, 28)
led.set_rgb(0, 0, 0)

# Check sensor stick connected
try:
    bme = BreakoutBME280(i2c, address=0x76)
    ltr = BreakoutLTR559(i2c)
except RuntimeError:
    display.set_layer(0)
    display.set_pen(RED)
    display.clear()
    display.set_pen(WHITE)
    display.text("Multi-Sensor Stick missing", 10, 95, 320, 3)
    display.update()

WIDTH, HEIGHT = display.get_bounds()

# Get current time
year, month, day, h, m, s, wd, _ = time.localtime()
old_m = -1

days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

# Used for minute and hour hands
def hand(ang, long): 
    ang = ang-90
    ls = long/10
    x0 = int(round(long * math.cos(math.radians(ang))))+cx
    y0 = int(round(long * math.sin(math.radians(ang))))+cy
    x1 = int(round(ls * math.cos(math.radians(ang+90))))+cx
    y1 = int(round(ls * math.sin(math.radians(ang+90))))+cy
    x2 = int(round(ls * math.cos(math.radians(ang-90))))+cx
    y2 = int(round(ls * math.sin(math.radians(ang-90))))+cy
    display.triangle(x0,y0,x1,y1,x2,y2)
    display.circle(cx,cy,int(ls))
    
display.set_backlight(1.0)
display.set_layer(0)
display.set_pen(BLACK)
display.clear()
display.set_layer(1)
display.set_pen(BLACK)
display.clear()

cx = 199 # centre of clock
cy = 119
l = 110

# Draw clock face
display.set_pen(BLUE)
display.circle(cx,cy,110)
display.update()

ls = 94
display.set_pen(WHITE)
for angle in range(0,360,6):
    xx = int(round(l * math.cos(math.radians(angle))))
    yy = int(round(l * math.sin(math.radians(angle))))    
    display.line(cx,cy,cx+xx,cy+yy)
display.set_pen(BLACK)
display.circle(cx,cy,100)
display.set_pen(WHITE)

for angle in range(0,360,30):
    xx = int(round(l * math.cos(math.radians(angle))))
    yy = int(round(l * math.sin(math.radians(angle))))    
    display.line(cx,cy,cx+xx,cy+yy)
    
# Sensor titles
display.set_pen(WHITE)
display.text("Temperature",5,40,310,1)
display.text("Lux",5,80,300,1)
display.text("Rel Humidity",5,120,300,1)
display.text("Air Pressure",5,200,300,1)

# === Main Loop ======
while True:
    # Draw face numbers
    display.set_pen(BLACK)
    display.circle(cx,cy,93) # Clear centre of clock face
    display.set_pen(YELLOW)
    display.text("9",118,108,320,3)
    display.text("3",268,108,320,3)
    display.text("10",128,70,320,3)
    display.text("2",258,70,320,3)
    display.text("1",230,45,320,3)
    display.text("11",160,45,320,3)
    display.text("12",190,37,320,3)
    display.text("6",193,186,320,3)
    display.text("7",156,176,320,3)
    display.text("5",230,176,320,3)
    display.text("4",258,150,320,3)
    display.text("8",130,150,320,3)
    
    # Draw hands
    mang = int((m + s/60)* 6)    # angle of minute hand
    hang = int((h + m/60 )* 30 ) # angle of hour hand
    display.set_pen(BLUE)
    hand(mang,90)
    display.set_pen(RED)      
    hand(hang,70)
    sang = 6 * s - 90
    xs = int(round(ls * math.cos(math.radians(sang))))
    ys = int(round(ls * math.sin(math.radians(sang))))
    display.set_pen(WHITE)
    display.line(cx,cy,cx+xs,cy+ys)
    display.circle(cx,cy,3)
    
    # Assemble Digital time
  # dt = "%02d:%02d:%02d" % (h, m, s)
    ss = "0" + str(s)
    lgs =len(ss)
    ss = ss[lgs-2:lgs]
    ms = "0" + str(m)
    lgs = len(ms)
    ms = ms[lgs-2:lgs]
    hs = "0" + str(h)
    lgs = len(hs)
    hs = hs[lgs-2:lgs]
    dt = hs+":"+ms+":"+ss
    
    # Clear sensor text areas
    display.set_pen(BLACK)
    display.rectangle(5,10,127,18)
    display.rectangle(5,50,90,18)
    display.rectangle(5,90,80,18)
    display.rectangle(5,130,80,18)
    display.rectangle(5,210,115,18)
    display.rectangle(5,163,90,28)
    
    # Write digital time & sensor readings 
    display.set_pen(YELLOW)
    display.text(dt,5,10,320,3)
    # read the sensors
    temperature, pressure, humidity = bme.read()
    temp = round(temperature,1)
    display.set_pen(GREEN)
    display.text(str(temp)+" C",5,50,320,3)
    # Convert pressure to hPa
    pressurehpa = int(pressure / 100)
    display.text(str(int(humidity)) +" %", 5,130,320,3)
    display.text(str(pressurehpa)+" hPa",5,210,320,3)
    prox, a, b, c, d, e, lux = ltr.get_reading()
    lux = int(lux)
    display.set_pen(CYAN)
    display.text(str(lux),5,90,320,3)
    
    # Update date/time
    year, month, day, h, m, s, wd, _ = time.localtime()
    display.text(days[wd],5,163,320,1)
    display.text(str(day)+" "+months[month-1],5,173,320,2)
    display.update()

    if old_m < 0 or s == 0 and m != old_m:
        old_m = m
        print(m%10, end='')            # minute markers for debugging
        if m == 59:
            print('')

    time.sleep(0.1)

Your above file only runs about ~15 seconds and just stops? If I run it from Thonny the time / date are correct, but if I run it as main.py on boot it defaults too Jan 1st 12:00.
Pico Plus 2 W, RV3028, Sensor Stick, Display Pack 2.8.

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
89

Usually I just get one digit above when it stops.

Thanks alphanumeric, that’s exactly what I’ve been seeing.

The program has no way of setting the time, except from Thonny, so it will default to Jan 1st when run as main.py.

The numbers displayed are printed each minute, just to show program activity.

Ah OK, you had mentioned an RV3028, but I see now that, that code is not setup to use it. The code goes something like this.

from breakout_rtc import BreakoutRTC
from machine import RTC

rtc = BreakoutRTC(i2c)
if rtc.is_12_hour:
    rtc.set_24_hour()
if rtc.read_periodic_update_interrupt_flag():
    rtc.clear_periodic_update_interrupt_flag()
if rtc.update_time():
    rtc_date = rtc.string_date()
    rtc_time = rtc.string_time()


    hours = rtc.get_hours()
    minutes = rtc.get_minutes()
    month = rtc.get_month()
    date = rtc.get_date()
    weekday = rtc.get_weekday()
      

In Micro Python anyway.

Thanks again, alphanumeric.

That program was a short example to demonstrate the problem. My full program includes support for an optional RV3028 and also setting the time from NTP via WiFi.

However, I really appreciate you taking the time to provide that information :o)

Going back over this thread I do see where you mentioned that your full file is over 900 lines of code. O_O wow. =). And what you posted was the clif notes version. ;)
I have a bunch of Pimoroni bits and bytes here, so some times it’s not too hard to rig up some test hardware and run some code. And then help somebody with an issue. It keeps the old brain going as they say.

Having the same program stop on alphanumeric’s setup is useful evidence for a bug report. I’d include the program, the exact UF2 filenames for the working and failing builds, and the hardware list from both setups in a pimoroni-pico issue. The release notes document the pico_plus2 move from pimoroni-pico-rp2350 to pimoroni-pico, but that alone doesn’t identify the cause of the hang. Has either of you already opened an issue for this? If so, keeping the reproduction details together there would help.

I haven’t opened an issue for this yet, though I have emailed support@pimoroni.com, which has been acknowledged.

If I don’t hear any more by tomorrow, I’ll raise a bug report.

I’m seeing this too.

Adding

import gc

and then

gc.collect()

into the main loop seemed to improve things for me, which makes me think the issue is the board running out of memory. You can also do print(gc.mem_free()) to show the remaining free memory each time round the loop.

PEN_RGB565 and multiple layers are both memory intensive, but if the same code was working on the previous version of the firmware that probably warrants opening an issue. A concise code snippet demonstrating the problem would probably be appreciated by our software folks :)

Thanks hel, that was really interesting.

I removed the second layer, changed the pen type to PEN_P8 and added print(gc.mem_free()) every tenth time around the loop.

The sample program ran for about a minute and then hung. The mem_free was 8509968 when it started and had come down to 7974640 when it stopped.

I’m not sure how much more concise I can make it, but I will try cutting bits out until it stops failing.