I thought I would post this here as I was trying to get my motion sensor to work with the official RPi TFT 7" screen. The module for motion only turns off the HDMI port and not the TFT that is connected via the display connector on the RPi3. What I did to get it to work is to write a short python script that checks for motion. Please excuse my poor python…it’s the first one I’ve written :)
#!/usr/bin/env python import RPi.GPIO as GPIO import time import os GPIO.setmode(GPIO.BCM) PIR_PIN = 22 GPIO.setup(PIR_PIN, GPIO.IN) os.system("echo 0 > /sys/class/backlight/rpi_backlight/bl_power") while True: i=GPIO.input(PIR_PIN) if i==1: os.system("echo 0 > /sys/class/backlight/rpi_backlight/bl_power") time.sleep(1) elif i==0: os.system("echo 1 > /sys/class/backlight/rpi_backlight/bl_power") time.sleep(1)Basically, the PIR is on GPIO pin 22 and all this script does is to check for motion and if there is any then turn on the backlight, if not it turns it off. The delay is set on the PIR to about 1 min 30 secs before the pin turns off.
I saved it in my home directory (/home/pi). Don’t forget to make it executable by typing:
chmod +x motion.pyI then added an entry in the /etc/rc.local file to run it at boot as below:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address python /home/pi/motion.py & _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi exit 0Also, don’t forget the ‘&’ at the end as the script is intended to run in the background and the Pi may not boot if you forget.
I hopes this helps someone :)