Skip to content

Power Raspberry Pi's display on/off using data from GPIO, like a motion sensor

License

Notifications You must be signed in to change notification settings

ZGrauer/Raspberry-Pi-Motion-Wakeup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Motion Wakeup

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.

Getting Started

Prerequisites

You must have Rust installed and cross-compilation configured for a Raspberry Pi.

  1. Download and install Rust using these instructions.
  2. Setup cross-compilation for Raspberry Pi as needed.

Compilation for Raspberry Pi

  1. Clone this repository using the instructions from GitHub https://github.com/ZGrauer/Raspberry-Pi-Motion-Wakeup.git
  2. Update the BCM_PIN pin constant in main.rs with the input pin from your motion sensor. See below.
  3. Run this command from the project directory to build for a Pi. See ./target/armv7-unknown-linux-gnueabihf/ for the compiled executable.
cargo build

Configure Input GPIO Pin

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;

Optional Display Off Timeout

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

Deployment

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

Disable the Screensaver

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:

  1. Install xscreensaver
sudo apt install xscreensaver
  1. Find the screensaver application under the Preferences option on the main desktop menu, then disable it.

Authors

@ZGrauer.

Contribute

Feel free to dive in! Open an issue or submit PRs.

Raspberry Pi Motion Wakeup follows the Contributor Covenant Code of Conduct.

License

GNU © Zachary Grauerholz

About

Power Raspberry Pi's display on/off using data from GPIO, like a motion sensor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages