MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

MMM-Motion with RPi3 and RPi Official TFT

  • 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
    PIR_PIN = 22
    GPIO.setup(PIR_PIN, GPIO.IN)
    os.system("echo 0 > /sys/class/backlight/rpi_backlight/bl_power")
    while True:
            if i==1:
                    os.system("echo 0 > /sys/class/backlight/rpi_backlight/bl_power")
            elif i==0:
                    os.system("echo 1 > /sys/class/backlight/rpi_backlight/bl_power")

    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

    I 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/ &
    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
      printf "My IP address is %s\n" "$_IP"
    exit 0

    Also, 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 🙂

Log in to reply