Advertisement
mcarrasco

Using PIR and beaglebone

May 19th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. ############################################
  2. # As published in www.internetdelascosas.cl
  3. # Feel free to use and modify
  4. # PIR is connected as follows
  5. # Vdd P9.4
  6. # Gnd P9.1
  7. # Out P9.15
  8. # ref : http://www.gigamegablog.com/2012/03/16/beaglebone-coding-101-buttons-and-pwm/
  9. ############################################
  10.  
  11. import os
  12. from time import sleep
  13.  
  14. os.system("echo 48 > /sys/class/gpio/export")
  15.  
  16. while(True):
  17.  
  18.         f = open("/sys/class/gpio/gpio48/value","r") # reading P9.15
  19.         datos  = f.read()
  20.         vect   = datos.split('\x00')
  21.         switch = int(vect[0])                 # convert to int type
  22.         if switch == 0:
  23.                 print( "Not sensing presence")
  24.                 sleep(1)
  25.         else:
  26.                 print ( "Sensing presence")
  27.                 sleep(1)
  28.         f.close
  29.  
  30. # To disable pin use
  31. # os.system("echo 48 > /sys/class/gpio/unexport")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement