• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

MMM-Motion with RPi3 and RPi Official TFT

Scheduled Pinned Locked Moved Troubleshooting
1 Posts 1 Posters 1.1k Views 1 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    markbajaj
    last edited by Jun 12, 2017, 2:07 PM

    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.py
    

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

    1 Reply Last reply Reply Quote 0
    • 1 / 1
    1 / 1
    • First post
      1/1
      Last post
    Enjoying MagicMirror? Please consider a donation!
    MagicMirror created by Michael Teeuw.
    Forum managed by Sam, technical setup by Karsten.
    This forum is using NodeBB as its core | Contributors
    Contact | Privacy Policy