Are there Callback Functions for Piicodev Buttons?

Hi, The PiicoDev components look really cool. I was hoping to incorporate them in a project, but my application needs to be running a bunch of other logic.

I’ve used gpiozero’s button.when_pressed callback functionality in the past and it’s great, because you can set up that button listener at startup of the script and you don’t have to keep coming back to check on the button status every 0.1 seconds.

Is there anyway to set callback functions when using the PiicoDev button so that my program is notified of button pushes without me having to keep checking in a loop? PiicoDev Button | Core Electronics Australia

Thanks in advance!

2 Likes

The Picodev button uses I2C to communicate the state. Gpiozero uses just a on/off setting, so the answer is no.

If you are using Python and a Pi :-
Simple push button.
You could use asyncio to start a process similar to gpiozero that looks at a pin every 0.1s and sets a variable. I have used this with a Pico to check a switch and with a Pi 3B+.

Picodev button.
You could also use the I2C driver in the asyncio process, so the button could be used then.

Regards
Jim

2 Likes

Hi Paul,

Jim’s right about using asyncio, from memory there’s also a .was_pressed attribute for the button.
That should do what you are after

2 Likes

Hi @Paul271180 - I played a part in the PiicoDev Button development.

@James46717 and @Liam120347 are both correct - I’ll just add my own thoughts.

Since the device is I2C it does have to be polled. The .was_pressed property will allow you to never miss the last button press, but won’t give you immediate interrupt-driven interactivity.

We didn’t include an interrupt connection from the Button module because… well… we figured that if users were going to use such a feature they would probably want to just use a simple button in the end.

I hope this has helped :slight_smile:

Best of luck with your project - I’m stoked you’re using PiicoDev :smiley:

4 Likes

Thanks for the response! These are really cool components.

For the future, Here was my logic for wanting to use the I2C. I’ve been using simple buttons, but there’s soldering involved to make them work. I was looking for an easy way to build things out without having do deal with pull-up resisters, ESD protection, and soldering. The way I was looking at it the I2C is for much more than prototyping. It’s for a software guy like me to build without having to worry about the nuances of the hardware that are required for hardening an application.

Thanks again for the response! These are really impressive components.

5 Likes

The Piicodev ecosystem is pretty neat for this. I’m more of a “software guy” too.

2 Likes