GithubHelp home page GithubHelp logo

sr-murthy / python-sysfs-gpio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from derekstavis/python-sysfs-gpio

0.0 1.0 0.0 10 KB

Pure Python native GPIO access. Edge-triggered interrupts included.

License: MIT License

Python 100.00%

python-sysfs-gpio's Introduction

Linux SysFS GPIO access via Python

This package offer Python classes to work with GPIO on Linux.

System Requirements

As this package relies on modern techniques provided by Linux kernel, so your kernel version should support at least EPoll and SysFS interfaces.

Package Requirements

This package is based on Twisted main loop. To build the package you will also need setuptools.

How to use it

  1. Download this repository
    git clone https://github.com/derekstavis/python-sysfs-gpio.git
  1. Inside it, issue:
    sudo python setup.py install
  1. On your code:
    # Import Twisted mainloop
    
    from twisted.internet import reactor
    
    # Import this package objects
    
    from sysfs.gpio import Controller, OUTPUT, INPUT, RISING
    
    # Refer to your chip GPIO numbers and set them this way
    
    Controller.available_pins = [1, 2, 3, 4]
    
    # Allocate a pin as Output signal
    
    pin = Controller.alloc_pin(1, OUTPUT)
    pin.set()   # Sets pin to high logic level
    pin.reset() # Sets pin to low logic level
    pin.read()  # Reads pin logic level
    
    # Allocate a pin as simple Input signal
    
    pin = Controller.alloc_pin(1, INPUT)
    pin.read()  # Reads pin logic level
    
    # Allocate a pin as level triggered Input signal
    
    def pin_changed(state):
        print("Pin changed to %d state" % state)
    
    pin = Controller.alloc_pin(1, INPUT, pin_changed, RISING)
    pin.read()  # Reads pin logic level
  1. Don't forget to start reactor loop!
    reactor.run()

Contributing

If you think that there's work that can be done to make this module better (and that's the only certainty), fork this repo, make some changes and create a pull request. I will be glad to accept it! :)

python-sysfs-gpio's People

Contributors

derekstavis avatar gdeback avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.