• Re: The button of the pico in python?

    From Martin Gregorie@3:770/3 to F. W. on Wed Jun 23 07:01:26 2021
    On Wed, 23 Jun 2021 08:27:18 +0200, F. W. wrote:

    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).

    Have yo been here: https://www.raspberrypi.org/documentation/rp2040/getting-started/

    and downloaded the PICO documentation?

    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?

    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

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From F. W.@3:770/3 to All on Wed Jun 23 08:27:18 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From F. W.@3:770/3 to All on Wed Jun 23 10:15:31 2021
    Am 23.06.2021 um 09:01 schrieb Martin Gregorie:

    Have yo been here: https://www.raspberrypi.org/documentation/rp2040/getting-started/

    and downloaded the PICO documentation?


    Yes, thank you again.

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

    :-(

    FW

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From A. Dumas@3:770/3 to F. W. on Wed Jun 23 08:34:00 2021
    F. W. <me@home.com> wrote:
    Am 23.06.2021 um 09:01 schrieb Martin Gregorie:

    Have yo been here:
    https://www.raspberrypi.org/documentation/rp2040/getting-started/

    and downloaded the PICO documentation?


    Yes, thank you again.

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

    :-(


    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.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From A. Dumas@3:770/3 to A. Dumas on Wed Jun 23 08:44:44 2021
    A. Dumas <alexandre@dumas.fr.invalid> wrote:
    It is mentioned though, depending on which document you read. [...]

    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)

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Dennis Lee Bieber@3:770/3 to All on Wed Jun 23 12:14:14 2021
    On Wed, 23 Jun 2021 08:27:18 +0200, "F. W." <me@home.com> declaimed the following:


    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?

    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
    wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Nikolaj Lazic@3:770/3 to All on Wed Jun 23 16:17:12 2021
    Dana Wed, 23 Jun 2021 12:14:14 -0400, Dennis Lee Bieber <wlfraed@ix.netcom.com> napis'o:
    On Wed, 23 Jun 2021 08:27:18 +0200, "F. W." <me@home.com> declaimed the following:


    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?

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

    he asked about pico.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)