few features I wish to add on a pi base Lora gateway
My second one is with 2245, and pi zero, since the pi zero W, the whole system takes about 225-250mA at 5V side, and the temp is low...
1. Adding power button
https://www.youtube.com/watch?v=qAzheiZlB9k&t=344s&ab_channel=AndreasSpiess
sudo nano /boot/config.txt
and add the following line to the file:
dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up
ctrl-X and Yes and, after a reboot, it should work.
No, Andreas' trick does not work on rak gateway...
But this does work on 2021-10-30 raspios bull eye....
I made it on gpio26, since I want to use GPIO3 as IIC for OLED
This one use a py service, and it works on the rakgateway.
http://blog.itist.tw/2017/03/diy-power-and-reset-button-for-raspberry-pi.html
1.
新增一支 Python 程式來讓 GPIO 讀取 Power 開關的動作。
sudo nano /usr/local/bin/halt.py
##### 我是分隔線 #####
#!/usr/bin/env python# Import Libraries
import RPi.GPIO as GPIO
import subprocess
# Define GPIO Pin Number
gpioPin=3
# Define GPIO Function
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpioPin, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(gpioPin, GPIO.FALLING)
# Command
subprocess.call(['shutdown', '-h', 'now'], shell=False)
##### 我是分隔線 #####
2.
新增一支 Shell Script 讓我們方便管理。
sudo vi /etc/init.d/listening-for-shutdown.sh
##### 我是分隔線 #####
#! /bin/sh
### BEGIN INIT INFO
# Provides: listen-for-shutdown.py
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
case "$1" in
start)
echo "Starting listening-for-shutdown"
sudo python /usr/local/bin/halt.py &
;;
stop)
echo "Stopping listening-for-shutdown"
sudo killall python
;;
*)
echo "Usage: service listening-for-shutdown {start|stop}"
exit 1
;;
esac
exit 0
##### 我是分隔線 #####
3.
讓 shell excutable
sudo chmod u+x listening-for-shutdown.sh
4.
讓程式在開機後自動啟動。
sudo update-rc.d listening-for-shutdown.sh defaults
也可以手動啟動服務。
sudo /etc/init.d/listening-for-shutdown.sh start
sudo apt-get install python3-setuptools
- sudo python3 setup.py install
- sudo python3 setup.py install
sudo apt-get install python3-pil
still error:
Traceback (most recent call last):
File "/home/pi/OLED_example.py", line 15, in <module>
from PIL import Image, ImageDraw, ImageFont
File "/home/pi/.local/lib/python3.9/site-packages/PIL/Image.py", line 114, in <module>
from . import _imaging as core
ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory
here is the solution:
sudo apt-get install libopenjp2-7
then the example works, and the
python3 stats.py works
- sudo apt-get install git
- sudo apt-get update
- sudo apt-get upgrade
sudo apt-get install python3-setuptools
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install libopenjp2-7
- sudo apt-get install python-smbus
- i2c tools not really needed
- sudo apt-get install i2c-tools
- both help to find the iic device using
- this command help to find IIC
- sudo i2cdetect -y 1
- git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
sudo apt-get install python-pip
pip freeze | grep RPi
For python3
sudo apt-get install python3-dev python3-rpi.gpio
this will do the trick , do not istall the picap mentioned in the link
Running Stats.py on Startup
You can easily make it so this program runs every time you boot your Raspberry Pi.
The fastest and easiest way is to put it in /etc/rc.local. Run the bellow command on terminal:
- sudo nano /etc/rc.local
Scroll down, and just before the exit 0 line, enter the following:
sudo python3 /home/pi/Adafruit_Python_SSD1306/examples/stats_temp.py &
Save and exit.
Reboot to verify that the screen comes up on boot!
Here is another post, seems a little bit simpler, but I did not test.
https://gist.github.com/rfong/2c36b87ff22077f8dd9afd513c519a80
3. Adding power off indicator
I tested on my Pi2, with dtoverlay setting as following.
dtoverlay=gpio-shutdown,gpio_pin=13,active_low=1,gpio_pull=up
dtoverlay=gpio-poweroff
the gpio-poweroff is preset at pin 26, I tried to change it to pin13, but it did not work. So I changegpio-shutdown to pin13, and keep gpio-poweroff at 26, both works as set.
the gpio-poweroff pin is high, when poweroff ,so my LED is connected with - at pin26 and + at 3.3V, it will light up when pi running, and off at poweroff
For RAK boards, according https://docs.rakwireless.com/Product-Categories/WisLink/RAK2245-Pi-HAT/Datasheet/#hardware
with SX1301
Pin 13 and Pin26 are not connected on rak pi hat
For smaller board(some times I don't really understand their naming)
https://shop.marcomweb.it/images/stories/virtuemart/product/RAK7246%20datasheet2.pdf
This one is with SX1308
留言
張貼留言