mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-12-08 20:39:01 +00:00
Tidy up faqs page
This commit is contained in:
97
docs/faq.rst
97
docs/faq.rst
@@ -7,6 +7,50 @@ Frequently Asked Questions
|
|||||||
.. currentmodule:: gpiozero
|
.. currentmodule:: gpiozero
|
||||||
|
|
||||||
|
|
||||||
|
.. _keep-your-script-running:
|
||||||
|
|
||||||
|
How do I keep my script running?
|
||||||
|
================================
|
||||||
|
|
||||||
|
The following script looks like it should turn an LED on::
|
||||||
|
|
||||||
|
from gpiozero import LED
|
||||||
|
|
||||||
|
led = LED(17)
|
||||||
|
led.on()
|
||||||
|
|
||||||
|
And it does, if you're using the Python (or IPython or IDLE) shell. However,
|
||||||
|
if you saved this script as a Python file and ran it, it would flash on
|
||||||
|
briefly, then the script would end and it would turn off.
|
||||||
|
|
||||||
|
The following file includes an intentional :func:`~signal.pause` to keep the
|
||||||
|
script alive::
|
||||||
|
|
||||||
|
from gpiozero import LED
|
||||||
|
from signal import pause
|
||||||
|
|
||||||
|
led = LED(17)
|
||||||
|
led.on()
|
||||||
|
|
||||||
|
pause()
|
||||||
|
|
||||||
|
Now the script will stay running, leaving the LED on, until it is terminated
|
||||||
|
manually (e.g. by pressing Ctrl+C). Similarly, when setting up callbacks on
|
||||||
|
button presses or other input devices, the script needs to be running for the
|
||||||
|
events to be detected::
|
||||||
|
|
||||||
|
from gpiozero import Button
|
||||||
|
from signal import pause
|
||||||
|
|
||||||
|
def hello():
|
||||||
|
print("Hello")
|
||||||
|
|
||||||
|
button = Button(2)
|
||||||
|
button.when_pressed = hello
|
||||||
|
|
||||||
|
pause()
|
||||||
|
|
||||||
|
|
||||||
My event handler isn't being called?
|
My event handler isn't being called?
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
@@ -96,65 +140,22 @@ version of gpiozero is available in your Python environment like so:
|
|||||||
|
|
||||||
>>> from pkg_resources import require
|
>>> from pkg_resources import require
|
||||||
>>> require('gpiozero')
|
>>> require('gpiozero')
|
||||||
[gpiozero 1.3.2 (/usr/lib/python3/dist-packages)]
|
[gpiozero 1.4.0 (/usr/lib/python3/dist-packages)]
|
||||||
>>> require('gpiozero')[0].version
|
>>> require('gpiozero')[0].version
|
||||||
'1.3.2'
|
'1.4.0'
|
||||||
|
|
||||||
If you have multiple versions installed (e.g. from ``pip`` and ``apt``) they
|
If you have multiple versions installed (e.g. from ``pip`` and ``apt``) they
|
||||||
will not show up in the list returned by the ``require`` method. However, the
|
will not show up in the list returned by the ``require`` method. However, the
|
||||||
first entry in the list will be the version that ``import gpiozero`` will
|
first entry in the list will be the version that ``import gpiozero`` will
|
||||||
import.
|
import.
|
||||||
|
|
||||||
If you receive the error "No module named pkg_resources", you need to install
|
If you receive the error ``No module named pkg_resources``, you need to install
|
||||||
the ``pip`` utility. This can be done with the following command in Raspbian:
|
``pip``. This can be done with the following command in Raspbian:
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
$ sudo apt install python-pip
|
$ sudo apt install python3-pip
|
||||||
|
|
||||||
Alternatively, install pip with `get-pip`_.
|
Alternatively, install pip with `get-pip`_.
|
||||||
|
|
||||||
.. _get-pip: https://pip.pypa.io/en/stable/installing/
|
.. _get-pip: https://pip.pypa.io/en/stable/installing/
|
||||||
|
|
||||||
|
|
||||||
.. _keep-your-script-running:
|
|
||||||
|
|
||||||
How do I keep my script running?
|
|
||||||
================================
|
|
||||||
|
|
||||||
The following script looks like it should turn an LED on::
|
|
||||||
|
|
||||||
from gpiozero import LED
|
|
||||||
|
|
||||||
led = LED(17)
|
|
||||||
led.on()
|
|
||||||
|
|
||||||
And it does, if you're using the Python (or IPython or IDLE) shell. However,
|
|
||||||
if you saved this script as a Python file and ran it, it would flash on
|
|
||||||
briefly, then the script would end and it would turn off.
|
|
||||||
|
|
||||||
The following file includes an intentional :func:`~signal.pause` to keep the
|
|
||||||
script alive::
|
|
||||||
|
|
||||||
from gpiozero import LED
|
|
||||||
from signal import pause
|
|
||||||
|
|
||||||
led = LED(17)
|
|
||||||
led.on()
|
|
||||||
pause()
|
|
||||||
|
|
||||||
Now the script will stay running, leaving the LED on, until it is terminated
|
|
||||||
manually (e.g. by pressing Ctrl+C). Similarly, when setting up callbacks on
|
|
||||||
button presses or other input devices, the script needs to be running for the
|
|
||||||
events to be detected::
|
|
||||||
|
|
||||||
from gpiozero import Button
|
|
||||||
from signal import pause
|
|
||||||
|
|
||||||
def hello():
|
|
||||||
print("Hello")
|
|
||||||
|
|
||||||
button = Button(2)
|
|
||||||
button.when_pressed = hello
|
|
||||||
pause()
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user