Picoexplorer with Pico W accessing Buttons

I have just got a Pico W and now connecting to my Picoexplorer base.
Using the custom version of Micropython from Pimoroni I have got the display & beeper working but I can’t get the Button functions working. I have yet to try the motor control too.
Please can anyone advise. Just been trying the button example.
I gather the picoexplorer python module has been deprecated and moved.
How do I access the button functions?
Regards
Phil

This is what works for me on my Tufty. It shouldn’t be too hard to pick out the button code and edit it to match the pins used on Pico Explorer.

import time
from pimoroni import Button
from picographics import PicoGraphics, DISPLAY_TUFTY_2040

display = PicoGraphics(display=DISPLAY_TUFTY_2040)

display.set_backlight(1.0)
display.set_font("bitmap8")

button_a = Button(7, invert=False)
button_b = Button(8, invert=False)
button_c = Button(9, invert=False)
button_up = Button(22, invert=False)
button_down = Button(6, invert=False)

WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
TEAL = display.create_pen(0, 255, 255)
MAGENTA = display.create_pen(255, 0, 255)
YELLOW = display.create_pen(255, 255, 0)
RED = display.create_pen(255, 0, 0)
GREEN = display.create_pen(0, 255, 0)

WIDTH, HEIGHT = display.get_bounds()

while True:
    if button_a.is_pressed:                               # if a button press is detected then...
        display.set_pen(BLACK)                            # set pen to black
        display.clear()                                   # clear display to the pen colour
        display.set_pen(WHITE)                            # change the pen colour
        display.text("Button A pressed", 10, 10, WIDTH - 10, 3)  # display some text on the screen
        display.update()                                  # update the display
        time.sleep(1)                                    # pause for a sec

    elif button_b.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(TEAL)
        display.text("Button B pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)

    elif button_c.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(MAGENTA)
        display.text("Button C pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)

    elif button_up.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(YELLOW)
        display.text("Button up pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)

    elif button_down.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(GREEN)
        display.text("Button down pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)

    else:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(RED)
        display.text("Press any button!", 10, 10, WIDTH, 3)
        display.update()

    time.sleep(0.1)  # this number is how frequently Tufty checks for button presses

Thanks for the example.
I have got it to work with the PicoExplorer on my Pico W.
Code shown below.

#Button Test on Pico Explorer using Pico W
import time
from pimoroni import Button
from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER

display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)

display.set_backlight(1.0)
display.set_font("bitmap8")

button_a = Button(12, invert=True)
button_b = Button(13, invert=True)
button_x = Button(14, invert=True)
button_y = Button(15, invert=True)


WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
TEAL = display.create_pen(0, 255, 255)
MAGENTA = display.create_pen(255, 0, 255)
YELLOW = display.create_pen(255, 255, 0)
RED = display.create_pen(255, 0, 0)
GREEN = display.create_pen(0, 255, 0)

WIDTH, HEIGHT = display.get_bounds()

while True:
    if button_a.is_pressed:                               # if a button press is detected then...
        display.set_pen(BLACK)                            # set pen to black
        display.clear()                                   # clear display to the pen colour
        display.set_pen(WHITE)                            # change the pen colour
        display.text("Button A pressed", 10, 10, WIDTH - 10, 3)  # display some text on the screen
        display.update()                                  # update the display
        time.sleep(1)                                    # pause for a sec

    elif button_b.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(TEAL)
        display.text("Button B pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)

    elif button_x.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(MAGENTA)
        display.text("Button X pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)
        
    elif button_y.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(YELLOW)
        display.text("Button Y pressed", 10, 10, WIDTH - 10, 3)
        display.update()
        time.sleep(1)

    else:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(RED)
        display.text("Press any button!", 10, 10, WIDTH, 3)
        display.update()
        
    time.sleep(0.1)

Nice, I was hoping that was going to help. Very similar hardware, display and button wise.
It’s my understanding that things were getting kind of bloated library wise. So with the switch to Pico Graphics, the button function is now a stand alone function. All of the examples likely haven’t caught up just yet though. The piezo buzzer will be the same deal. I think that done with PWM? There are instructions on how to setup the buttons etc. I can’t find them at the moment though?

Good that you got it working :)

I updated the Pico Explorer examples and function reference recently so they should be current - please can you let me know which examples weren’t working and what errors you were getting and I’ll see if I can suss out what’s going wrong? Was it import picoexplorer that was failing?

Hello,
I got the examples from

And yes it was
import picoexplorer

Which was failing and in
button_test.py
I couldn’t access/setup the buttons.
Regards
Phil

Interesting, thanks - I will investigate and update!

Hmm, I’m thinking the import picoexplorer can be removed?

And

button_a = Button(picoexplorer.BUTTON_A)
button_b = Button(picoexplorer.BUTTON_B)
button_x = Button(picoexplorer.BUTTON_X)
button_y = Button(picoexplorer.BUTTON_Y)

replaced with

button_a = Button(12)
button_b = Button(13)
button_x = Button(14)
button_y = Button(15)

Yes you are correct, that’s what I did to get it working.
Many thanks for the support forum.
Regards
Phil