The button of the pico in python?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi,

I am not very experienced with Raspberry Pi(co) nor Python. I was given
a R-Pico and enjoy learning about Python (as a former C-Programmer).

Does anybody know how to get a signal if the button on the pico is
pressed? How can a Python-Program detect that the button is pressed?

Or do I think the wrong way?

I have a mad and funny idea which I will publish here ... :-D

FW

Re: The button of the pico in python?
On Wed, 23 Jun 2021 08:27:18 +0200, F. W. wrote:

Quoted text here. Click to load it
Have yo been here:  
https://www.raspberrypi.org/documentation/rp2040/getting-started/

and downloaded the PICO documentation?

Quoted text here. Click to load it
I'd imagine that's covered in the docs, which are generally pretty good.  
Same goes for the RPi range, though for that having a link to the Debian  
documentation may also help:
http://www.debian.org/doc/manuals/debian-reference/


--  
Martin    | martin at
Gregorie  | gregorie dot org


Re: The button of the pico in python?
Am 23.06.2021 um 09:01 schrieb Martin Gregorie:

Quoted text here. Click to load it

Yes, thank you again.

The button is not mentioned. So I think it is not "reachable".

:-(

FW

Re: The button of the pico in python?
Quoted text here. Click to load it


It is mentioned though, depending on which document you read. In the Pico
datasheet for example, it is explained that the "bootsel" button is
connected to "TP6" (test point 6) which is *not* a GPIO pin. It can only be
used to select USB boot at power-up. Its status cannot be read. So yes: not
reachable.


Re: The button of the pico in python?
Quoted text here. Click to load it

Download the book for an introduction to hardware things like buttons:
https://hackspace.raspberrypi.org/books/micropython-pico (free pdf link
from there, or buy a printed version)

Re: The button of the pico in python?
following:


Quoted text here. Click to load it

    As others have already commented as to the actual button, I'll attempt
a general review of the second question.

    Their are a number of ways to read GPIO pins.

SYSFS:
    Old (and being deprecated by Linux development)
https://www.ics.com/blog/gpio-programming-using-sysfs-interface

pi@rpi3bplus-1:~$ ls -l /sys/class/gpio
total 0
-rwxrwx--- 1 root gpio 4096 Jun 19 12:15 export
lrwxrwxrwx 1 root gpio    0 Jun 19 12:15 gpiochip0 ->
../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Jun 19 12:15 gpiochip504 ->
../../devices/platform/soc/soc:firmware/soc:firmware:expgpio/gpio/gpiochip504
-rwxrwx--- 1 root gpio 4096 Jun 19 12:15 unexport
pi@rpi3bplus-1:~$ echo "24" >/sys/class/gpio/export
pi@rpi3bplus-1:~$ ls -l /sys/class/gpio
total 0
-rwxrwx--- 1 root gpio 4096 Jun 23 11:41 export
lrwxrwxrwx 1 root gpio    0 Jun 23 11:41 gpio24 ->
../../devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio24
lrwxrwxrwx 1 root gpio    0 Jun 19 12:15 gpiochip0 ->
../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
lrwxrwxrwx 1 root gpio    0 Jun 19 12:15 gpiochip504 ->
../../devices/platform/soc/soc:firmware/soc:firmware:expgpio/gpio/gpiochip504
-rwxrwx--- 1 root gpio 4096 Jun 19 12:15 unexport
pi@rpi3bplus-1:~$ ls -l /sys/class/gpio/gpio24
lrwxrwxrwx 1 root gpio 0 Jun 23 11:41 /sys/class/gpio/gpio24 ->
../../devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio24
pi@rpi3bplus-1:~$ ls -l /sys/class/gpio/gpio24/
total 0
-rwxrwx--- 1 root gpio 4096 Jun 23 11:41 active_low
lrwxrwxrwx 1 root gpio    0 Jun 23 11:41 device -> ../../../gpiochip0
-rwxrwx--- 1 root gpio 4096 Jun 23 11:41 direction
-rwxrwx--- 1 root gpio 4096 Jun 23 11:41 edge
drwxrwx--- 2 root gpio    0 Jun 23 11:41 power
lrwxrwxrwx 1 root gpio    0 Jun 23 11:41 subsystem ->
../../../../../../../class/gpio
-rwxrwx--- 1 root gpio 4096 Jun 23 11:41 uevent
-rwxrwx--- 1 root gpio 4096 Jun 23 11:41 value
pi@rpi3bplus-1:~$ echo /sys/class/gpio/gpio24/direction
/sys/class/gpio/gpio24/direction
pi@rpi3bplus-1:~$ cat /sys/class/gpio/gpio24/direction
in
pi@rpi3bplus-1:~$ cat /sys/class/gpio/gpio24/value
0
pi@rpi3bplus-1:~$

    Since those appear as "files" any application that can
open/read-write/close the paths can use it.

libgpiod:
    The intended replacement for the sysfs access. Not installed by default
(based upon my R-Pi -- attempting apt install of gpiod; though I may have a
slightly corrupted apt system.
https://www.ics.com/blog/gpio-programming-exploring-libgpiod-library
    
pi@rpi3bplus-1:~$ gpioinfo
gpiochip0 - 54 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed       unused   input  active-high
        line   3:      unnamed       unused   input  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused   input  active-high
        line   6:      unnamed       unused   input  active-high
        line   7:      unnamed       unused   input  active-high
        line   8:      unnamed       unused   input  active-high
        line   9:      unnamed       unused   input  active-high
        line  10:      unnamed       unused   input  active-high
        line  11:      unnamed       unused   input  active-high
        line  12:      unnamed       unused   input  active-high
        line  13:      unnamed       unused   input  active-high
        line  14:      unnamed       unused   input  active-high
        line  15:      unnamed       unused   input  active-high
        line  16:      unnamed       unused   input  active-high
        line  17:      unnamed       unused   input  active-high
        line  18:      unnamed       unused   input  active-high
        line  19:      unnamed       unused   input  active-high
        line  20:      unnamed       unused   input  active-high
        line  21:      unnamed       unused   input  active-high
        line  22:      unnamed       unused   input  active-high
        line  23:      unnamed       unused   input  active-high
        line  24:      unnamed      "sysfs"   input  active-high [used]
        line  25:      unnamed       unused   input  active-high
        line  26:      unnamed       unused   input  active-high
        line  27:      unnamed       unused   input  active-high
        line  28:      unnamed       unused   input  active-high
        line  29:      unnamed       "led0"  output  active-high [used]
        line  30:      unnamed       unused   input  active-high
        line  31:      unnamed       unused   input  active-high
        line  32:      unnamed       unused   input  active-high
        line  33:      unnamed       unused   input  active-high
        line  34:      unnamed       unused   input  active-high
        line  35:      unnamed       unused   input  active-high
        line  36:      unnamed       unused   input  active-high
        line  37:      unnamed       unused   input  active-high
        line  38:      unnamed       unused   input  active-high
        line  39:      unnamed       unused   input  active-high
        line  40:      unnamed       unused   input  active-high
        line  41:      unnamed       unused   input  active-high
        line  42:      unnamed       unused   input  active-high
        line  43:      unnamed       unused   input  active-high
        line  44:      unnamed       unused   input  active-high
        line  45:      unnamed       unused   input  active-high
        line  46:      unnamed       unused   input  active-high
        line  47:      unnamed       unused  output  active-high
        line  48:      unnamed       unused   input  active-high
        line  49:      unnamed       unused   input  active-high
        line  50:      unnamed       unused   input  active-high
        line  51:      unnamed       unused   input  active-high
        line  52:      unnamed       unused   input  active-high
        line  53:      unnamed       unused   input  active-high
gpiochip1 - 8 lines:
        line   0:      unnamed       unused  output  active-high
        line   1:      unnamed       unused  output  active-high
        line   2:      unnamed       "led1"  output   active-low [used]
        line   3:      unnamed       unused  output  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused  output  active-high
        line   6:      unnamed       unused  output  active-high
        line   7:      unnamed       unused   input  active-high
pi@rpi3bplus-1:~$

    Note that chip0 line 24 shows "sysfs" -- since I exported it using
sysfs commands.

    From Python...

gpiozero library:
    https://www.raspberrypi.org/documentation/usage/gpio/python/README.md
    https://gpiozero.readthedocs.io/en/stable/
    A newer Python binding (there is also a binding for gpiod -- I need to
install that next). It is capable of using a number of low-level libraries
for actual GPIO access

RPi.GPIO:
    Original Python GPIO library

pigpio:
    Relies upon a daemon process with which client programs communicate to
access GPIO http://abyz.me.uk/rpi/pigpio/python.html

Adafruit Blinka:
    An interface layer translating CircuitPython calls into R-Pi GPIO (or
Beaglebone Black if one has one of those too). Adafruit is phasing out
usage of "native" libraries in example programs and device code in favor of
using the CircuitPython GPIO operations.
https://learn.adafruit.com/adafruit-io-basics-digital-input/python-setup (a
bit out-of-date; they still refer to Debian "Stretch")


--  
    Wulfraed                 Dennis Lee Bieber         AF6VN
     snipped-for-privacy@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

Re: The button of the pico in python?
Quoted text here. Click to load it
[snip]

he asked about pico.


Site Timeline