element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Python script behaves differently from command line
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 2 replies
  • Answers 1 answer
  • Subscribers 674 subscribers
  • Views 849 views
  • Users 0 members are here
  • pir_sensors
  • python
  • pi-noir
  • raspberry_pi
  • command-line
  • raspberry pi
  • python3
Related

Python script behaves differently from command line

ntewinkel
ntewinkel over 9 years ago

Hi All,

 

I'm hoping someone can help shed some light on this issue I'm having.

 

I have a Raspberry Pi model B (original Pi 1) that I have set up as a webcam (using Pi Noir), with an added PIR sensor to detect motion.

 

The app takes a picture once every 5 minutes and uses FTP to load it to my website.

Also, when motion is detected it takes a picture immediately and then uploads it to the website, and sends me an email with a URL to the picture.

 

When developing and testing, I'm running the app from the IDLE3 Python Shell. I've set up IDLE3 to run as sudo so that GPIO works.

When running "live", I run it from the command line, with this command:

sudo python3 motionwebcam.py

 

The idea is that I can then start it up automatically when the RPi starts up.

 

The webcam works properly in both cases, but the PIR sensor doesn't work when I run from the command line. It works fine when running from the IDLE3 environment.

 

I've tested this a few times, going back and forth between running from IDLE and from the command line, and it consistently ignores motion when run from the command line.

 

Has anyone run into this before? Does anyone have any suggestions?

 

ps, I did make sure that it's the same script running both times

 

Thanks!

-Nico

  • Sign in to reply
  • Cancel
  • ntewinkel
    0 ntewinkel over 9 years ago

    More information:

     

    I'm detecting motion using "add_event_detect":

         GPIO.add_event_detect(PIRSensor, GPIO.RISING, callback=motionHandler, bouncetime=1000)

     

    Oddly enough, when I separate it out in a test app, it works there.

     

    This is the test app:

     

    #

    #  RPi with PIR Motion detector

    #

    #  Testing

    #

     

     

    import RPi.GPIO as GPIO

    import time

     

    PIRSensor = 15

     

    # setup

     

    GPIO.setmode(GPIO.BOARD)

    GPIO.setup(PIRSensor, GPIO.IN)

     

     

    def motionHandler(PIR_PIN):   

        print("Motion detected!")

     

     

     

    GPIO.add_event_detect(PIRSensor, GPIO.RISING, callback=motionHandler, bouncetime=1000)

     

     

    try:

        print("Starting Testing PIR sensor (CTRL-C to exit) ...")

     

        while True:

    #        if GPIO.input(PIRSensor):

    #            print("Motion Detected!")

               

            time.sleep(1)  # sleeps 1 second

     

     

    except KeyboardInterrupt:

        print("Shutting down...")

        GPIO.cleanup()

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago

    Here is one difference http://stackoverflow.com/questions/32629367/is-there-a-difference-using-python3-in-idle3-or-in-ubuntu-14-04-terminal .

    Since it work separately, why not have one detect motion and invoke the other with a param teling the toher to perform a one time function and email.

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube