树莓派配置开机和关机

关机方法:

1、远程登录然后敲命令
2、拔电源(很容易导致文件损坏)
3、Teamviewer远程控制关机(需要用网)
添加电源键的方法,那就是写个脚本、让这个脚本开机启动,程序中一直检测设置为电源键的GPIO,如果被触发则关机。
只要在 /boot/config.txt 中添加相关配置就能实现关机。
现在分享一个简单的方法在/boot/overlays/README里面有提示
在这里插入图片描述

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"
 
        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. Load:   dtoverlay=gpio-shutdown,<param>=<val> Params: gpio_pin                GPIO pin to trigger on (default 3)
 
        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.

简单来说已经将使用GPIO3(这里的GPIO指3BCM GPIO编号,也就是SCL1)作为电源键,下降沿为按下,上升沿为弹起,内部上拉
只要在 /boot/config.txt 中添加相关配置就能实现关机。

vim  /boot/config.txt
然后添加   dtoverlay=gpio-shutdown即可

保存并重启,之后你只需要在GPIO3和GND之间接个按键就能实现关机,不需要添加任何配置,正常关机后不切断树莓派电源,将GPIO3拉到低电平就能开机

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值