Jump to content

Welcome, Guest!

Search the Community

Showing results for tags 'Interrupts'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Fruity Forums
    • News and Chat
    • New Members - Say Hello
    • Technical Support
    • Tips/Tricks/Guides/Resources
    • Project Logs!
    • International Fruity Forums

Categories

  • Raspberry Pi Linux Distributions
  • Guides
  • Raspberry Pi Emulation Software
  • Homebrew Software!

Categories

  • Beginners Guide To The Raspberry Pi
  • Raspberry Pi Tutorials / Guides / How-To's
  • Raspberry Pi Server Guides
  • Raspberry Pi OS Installation Guides

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Location


Interests


Biography


Interests


Occupation

Found 1 result

  1. Thought I would share some of my Raspberry Pi tests. Rather than being project oriented, most of my tests have had an emphasis on specific sensors/devices and simple Python programs to demonstrate their functionality. This was mainly intended to be a personal log of my Raspberry Pi lab tests, but if anyone can benefit or wants to add their observations so much the better. Hardware: Raspberry Pi, Gertboard (not essential to test) and Parallax Motion Sensor #555-28027 (Radio Shack 276-135). While there are library modules (wiringPi and RPi.GPIO for example) available that handle interrupts, I took a more direct approach for this test and used the poll function in the GPIO facility in Linux. For the sake of clarity, I will first show using this method to check the state of a GPIO pin without the benefit of using an interrupt. Before running the program, a user interface must be created for GPIO25 by executing these statements from the prompt: sudo su echo 25 >/sys/class/gpio/export # create a user interface for GPIO25 echo in >/sys/class/gpio25/direction # configure GPIO25 as an input This creates a directory with several files representing the configuration and state of GPIO25. For example, the 'value' file will contain a '0' if GPIO is low or an '1' if GPIO is high. The 'direction' file contains 'in' after GPIO25 is created. We could set the contents of any of these files, but their default values are suitable for this next test. I am using the same Parallax motion sensor tested earlier, except BUF1 is jumpered to GPIO25 on my Gertboard. As before, the motion sensor outputs a high for 3 seconds when it senses motion. Otherwise its output remains at low. gpio25-read.py import time f = open('/sys/class/gpio/gpio25/value', 'r') # create a read file object while 1: f.seek(0) # reset pointer location in file to beginning motion = f.read(1) # read 1st byte of read file object if motion == '1': print('Warning! Motion Detected!') else: print('All is quiet...') time.sleep(1) The above program simply hangs in a loop and reads the pin every second. The downside of this approach is the cpu is given no time to do anything else. Before running the next program using interrupts, we make sure we have created a user interface for GPIO25 by executing these statements from the prompt: sudo su echo 25 >/sys/class/gpio/export # create a user interface for GPIO25 echo in >/sys/class/gpio25/direction # configure GPIO25 as an input echo both >/sys/class/gpio25/edge # configure GPIO25 to recognize both rising & falling transitions gpio25-interrupt.py import time import select import sys f = open('/sys/class/gpio/gpio25/value', 'r') # create a read file object myInterrupt = select.poll() # create a polling object myInterrupt.register(f, select.POLLPRI) # add read file object as a source to satisfy poll requests while 1: myInterrupt.poll() # wait for an interrupt f.seek(0) # reset pointer location in file to beginning motion = f.read(1) # read 1st byte of read file object if motion == '1': print('Warning! Motion Detected!') else: print('All is quiet...') With this method a user would be free to add code putting the cpu to work doing other functions, such as controlling other GPIO pins, performing caculations, etc.

About Us

Bringing you the latest Raspberry Pi news, tutorials and user forum.

The Fruity Computer

×
×
  • Create New...