Bonjour,
J'avais fait un tuto ici :
viewtopic.php?f=44&t=4423&start=10
Je vois aussi des solutions avec des résistances pullup (ou pulldown)
Les résistances, c'est pour faire électronicien professionnel, je dirai (dans le bons sens du terme). C'est pour faire propre, physiquement parlant, dans le sens scientifiquement.
Sans résistances, la tension aux bornes est variable et sujette aux conditions extérieures (T°, humidité...).
A l'oscilloscope, lors de l'appui, on voit des 10e voire plus, des traces d'amorçage parasite puis une belle droite lors du vrai contact.
Avec les résistances, on a tout de suite la belle droite. Ce qui à l'avantage de moins calaminer la surface de contact et donc ton bouton durera plus longtemps.
Je viens de relire le readme :
Code : Tout sélectionner
Name: gpio-shutdown
Info: Initiates a shutdown when GPIO pin changes. The given GPIO pin
is configured as an input key that generates KEY_POWER events.
This event is handled by systemd-logind by initiating a
shutdown. Systemd versions older than 225 need an udev rule
enable listening to the input device:
ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \
SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \
ATTRS{keys}=="116", TAG+="power-switch"
Alternatively this event can be handled also on systems without
systemd, just by traditional SysV init daemon. KEY_POWER event
(keycode 116) needs to be mapped to KeyboardSignal on console
and then kb::kbrequest inittab action which is triggered by
KeyboardSignal from console can be configured to issue system
shutdown. Steps for this configuration are:
Add following lines to the /etc/console-setup/remap.inc file:
# Key Power as special keypress
keycode 116 = KeyboardSignal
Then add following lines to /etc/inittab file:
# Action on special keypress (Key Power)
kb::kbrequest:/sbin/shutdown -t1 -a -h -P now
And finally reload configuration by calling following commands:
# dpkg-reconfigure console-setup
# service console-setup reload
# init q
This overlay only handles shutdown. After shutdown, the system
can be powered up again by driving GPIO3 low. The default
configuration uses GPIO3 with a pullup, so if you connect a
button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
you get a shutdown and power-up button. Please note that
Raspberry Pi 1 Model B rev 1 uses GPIO1 instead of GPIO3.
Load: dtoverlay=gpio-shutdown,<param>=<val>
Params: gpio_pin GPIO pin to trigger on (default 3)
For Raspberry Pi 1 Model B rev 1 set this
explicitly to value 1, e.g.:
dtoverlay=gpio-shutdown,gpio_pin=1
active_low When this is 1 (active low), a falling
edge generates a key down event and a
rising edge generates a key up event.
When this is 0 (active high), this is
reversed. The default is 1 (active low).
gpio_pull Desired pull-up/down state (off, down, up)
Default is "up".
Note that the default pin (GPIO3) has an
external pullup. Same applies for GPIO1
on Raspberry Pi 1 Model B rev 1.
debounce Specify the debounce interval in milliseconds
(default 100)
Une résistance de pull-up est déjà programmé dans le GPIO3 donc il est inutile d'en rajouter.
De plus, il est maintenant inutile de rajouter physiquement des résistances, elles sont programmables, cf
gpio-control et
inputs
Et je rajouterai, si j'ai bien compris, les résistances de pull sont de 5K :
https://www.raspberrypi.com/documentati ... #boot-flow
Mais comme je débute sur Raspberry, je comprends pas grand chose.
Comment un bouton connecté entre 2 pins peut faire quelque chose sans être programmé quelque part. Je suppose que c'est dans le fichier cmdline.txt
Mais il est ou ce fichier?
Très bonne question. C'est la première que j'ai été cherchée lors de mon tuto. Comme il faut activer l'option avec "gpio-shutdown" dans le cmdline.txt, le fichier s'appelle gpio-shutdown et il est dans /boot/overlays/
Voici son contenu : (j'ai été cherché la source :
https://github.com/raspberrypi/linux/bl ... verlay.dts)
Code : Tout sélectionner
// Definitions for gpio-poweroff module
/dts-v1/;
/plugin/;
// This overlay sets up an input device that generates KEY_POWER events
// when a given GPIO pin changes. It defaults to using GPIO3, which can
// also be used to wake up (start) the Rpi again after shutdown.
// Raspberry Pi 1 Model B rev 1 can be wake up only by GPIO1 pin, so for
// these boards change default GPIO pin to 1 via gpio_pin parameter. Since
// wakeup is active-low, this defaults to active-low with a pullup
// enabled, but all of this can be changed using overlay parameters (but
// note that GPIO3 has an external pullup on at least some boards).
/ {
compatible = "brcm,bcm2835";
fragment@0 {
// Configure the gpio pin controller
target = <&gpio>;
__overlay__ {
// Define a pinctrl state, that sets up the gpio
// as an input with a pullup enabled. This does
// not take effect by itself, only when referenced
// by a "pinctrl client", as is done below. See:
// https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
// https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
pin_state: shutdown_button_pins@3 {
brcm,pins = <3>; // gpio number
brcm,function = <0>; // 0 = input, 1 = output
brcm,pull = <2>; // 0 = none, 1 = pull down, 2 = pull up
};
};
};
fragment@1 {
// Add a new device to the /soc devicetree node
target-path = "/soc";
__overlay__ {
shutdown_button: shutdown_button@3 {
// Let the gpio-keys driver handle this device. See:
// https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt
compatible = "gpio-keys";
// Declare a single pinctrl state (referencing the one declared above) and name it
// default, so it is activated automatically.
pinctrl-names = "default";
pinctrl-0 = <&pin_state>;
// Enable this device
status = "okay";
// Define a single key, called "shutdown" that monitors the gpio and sends KEY_POWER
// (keycode 116, see
// https://github.com/torvalds/linux/blob/v4.12/include/uapi/linux/input-event-codes.h#L190)
button: shutdown {
label = "shutdown";
linux,code = <116>; // KEY_POWER
gpios = <&gpio 3 1>;
debounce-interval = <100>; // ms
};
};
};
};
// This defines parameters that can be specified when loading
// the overlay. Each foo = line specifies one parameter, named
// foo. The rest of the specification gives properties where the
// parameter value is inserted into (changing the values above
// or adding new ones).
__overrides__ {
// Allow overriding the GPIO number.
gpio_pin = <&button>,"gpios:4",
<&shutdown_button>,"reg:0",
<&pin_state>,"reg:0",
<&pin_state>,"brcm,pins:0";
// Allow changing the internal pullup/down state. 0 = none, 1 = pulldown, 2 = pullup
// Note that GPIO3 and GPIO2 are the I2c pins and have an external pullup (at least
// on some boards). Same applies for GPIO1 on Raspberry Pi 1 Model B rev 1.
gpio_pull = <&pin_state>,"brcm,pull:0";
// Allow setting the active_low flag. 0 = active high, 1 = active low
active_low = <&button>,"gpios:8";
debounce = <&button>,"debounce-interval:0";
};
};
Pour info, mon Raspberry fonctionne sous Ubuntu. Il héberge mon site WEB. Jusque là tout va bien.
Mais, de temps en temps, j'ai besoin de l’arrêter sans passer par mon PC via PuTTY et c'est la le problème.
Est-ce quelqu'un a une solution complète, et valide?
Oui, ajouter un bouton poussoir

Sinon, il existe aussi des modules qui font ça en infrarouge donc avec une télécommande mais je n'ai plus le nom.