# Picoexplorer with Pico W accessing Buttons

**URL:** <https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972>\
**Category:** Support\
**Created:** [August 6, 2022, 11:41am UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972 "2022-08-06T11:41:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilG1300](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@PhilG1300](https://forums.pimoroni.com/u/PhilG1300)\
**Post date:** [August 6, 2022, 11:41am UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/1 "2022-08-06T11:41:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [August 6, 2022, 3:59pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/2 "2022-08-06T15:59:37Z")

</div>

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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![PhilG1300](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@PhilG1300](https://forums.pimoroni.com/u/PhilG1300)\
**Post date:** [August 6, 2022, 5:08pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/3 "2022-08-06T17:08:38Z")

</div>

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

```auto
#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)

```

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [August 6, 2022, 5:34pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/4 "2022-08-06T17:34:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)\
**Post date:** [August 8, 2022, 10:38am UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/5 "2022-08-08T10:38:47Z")

</div>

Good that you got it working :)

I updated the Pico Explorer [examples](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples/pico_explorer) and [function reference](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/pico_explorer) 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?

---

<div class="post-metadata">

**Author:** ![PhilG1300](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@PhilG1300](https://forums.pimoroni.com/u/PhilG1300)\
**Post date:** [August 8, 2022, 1:55pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/6 "2022-08-08T13:55:10Z")

</div>

Hello,  
I got the examples from

> **[pimoroni-pico/micropython/examples/pico\_explorer at main ·...](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples/pico_explorer)**
>
> main/micropython/examples/pico\_explorer

And yes it was  
import picoexplorer

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

---

<div class="post-metadata">

**Author:** ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)\
**Post date:** [August 8, 2022, 2:06pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/7 "2022-08-08T14:06:37Z")

</div>

Interesting, thanks - I will investigate and update!

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [August 8, 2022, 5:43pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/8 "2022-08-08T17:43:42Z")

</div>

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

And

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![PhilG1300](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@PhilG1300](https://forums.pimoroni.com/u/PhilG1300)\
**Post date:** [August 8, 2022, 6:42pm UTC](https://forums.pimoroni.com/t/picoexplorer-with-pico-w-accessing-buttons/19972/9 "2022-08-08T18:42:01Z")

</div>

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