A native app written using Rust that turns a Raspberry Pi's display on/off using data from GPIO pin. This app enables a PIR motion sensor connected to the Pi's GPIO pins to turn its display on/off based on movement. The display is powered off only when there has been a minimum duration of no movement detected. This app can be auto-launched along with Tapslist.io to create an auto-dimming beer tap display.
You must have Rust installed and cross-compilation configured for a Raspberry Pi.
- Download and install Rust using these instructions.
- Setup cross-compilation for Raspberry Pi as needed.
- Instructions for MacOS & Win 10 can be found here.
- Instructions for Linux can be found here
- Clone this repository using the instructions from GitHub
https://github.com/ZGrauer/Raspberry-Pi-Motion-Wakeup.git
- Update the
BCM_PIN
pin constant inmain.rs
with the input pin from your motion sensor. See below. - Run this command from the project directory to build for a Pi. See
./target/armv7-unknown-linux-gnueabihf/
for the compiled executable.
cargo build
Update the below line in main.rs
with the pin number for the PIR sensor. This is not the power or ground pin but the pin with data to the Pi. This uses BCM numbering for the pin, not board numbering. Pin numbering can be found here, https://pinout.xyz/
// BCM GPIO pin number for the motion sensor
const BCM_PIN: u8 = 8;
Launching the app with args -t <seconds>
or --timeout <seconds>
configures the seconds with no motion detected before the display is powered off. These do not need to be included when launching the app. If not included, then the default of 30 seconds is used.
rpi-motion-wakeup -t 60
Add the --release
flag to the to build command to compile for production. This optimizes artifacts for production. See ./target/armv7-unknown-linux-gnueabihf/
for the compiled executable.
cargo build --release
Then copy the executable to your Rapsberry Pi and run. Example:
$ ./rpi-motion-wakeup
PIR motion sensor on BCM GPIO pin 8
Press CTRL + C to exit
2020-05-15T18:34:37.851751162+00:00 | Watching for motion...
2020-05-15T18:34:55.392830162+00:00 | Motion detected!
2020-05-15T18:34:55.392927548+00:00 | Powering display on
display_power=1
2020-05-15T18:35:04.774342873+00:00 | No Motion
2020-05-15T18:35:35.364244063+00:00 | Powering display off
display_power=0
This app doesn't deactivate the default screensaver on the Pi. For this app to work properly you must disable the screensaver. There are a couple ways to do this but the easiest method is this:
- Install
xscreensaver
sudo apt install xscreensaver
- Find the screensaver application under the
Preferences
option on the main desktop menu, then disable it.
Feel free to dive in! Open an issue or submit PRs.
Raspberry Pi Motion Wakeup follows the Contributor Covenant Code of Conduct.
GNU © Zachary Grauerholz