Coder Social home page Coder Social logo

gpio4's Introduction

gpio4

Control gpio in python on Linux.

Improved version based on Sysfs, features same as RPi.GPIO and gpio3

Support RaspberryPi / OrangePi / BananaPi...

Attention

Don't run this on your PC because gpios of computer are usually protected.

Installation

Install from PyPI is suggested.

pip install gpio4

Or install from source.

git clone [email protected]:hankso/gpio4.git
cd gpio4
python setup.py build && sudo python setup.py install

Usage

Want something like RPi.GPIO?

>>> import gpio4.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup([12, 13], GPIO.IN)
>>> GPIO.input([12, 13])
[0, 0]
>>> p = GPIO.PWN(12) # it will automatically setup this pin to output first
>>> p.start(30) # duty cycle is 30%
...
>>> from gpio4.constants import BOARD_NANO_PI as BOARD
>>> GPIO.setmode(BOARD)
>>> GPIO.setup([6, 7, 9], GPIO.OUTPUT)
>>> GPIO.output([6, 7, 9], [GPIO.HIGH, GPIO.LOW, GPIO.HIGH])
>>> GPIO.add_event_detect(8, GPIO.RAISING, bouncetime=300)

or call functions as you are using Arduino?

>>> from gpio4.arduino import *
>>> pinMode(13, OUTPUT)
>>> pinMode(12, INPUT_PULLUP)
>>> digitalWrite(13, HIGH)
>>> digitalWrite(13, digitalRead(12))
>>> shiftIn(dataPin=12, clockPin=13, bitOrder=MSBFIRST)
170

Try the most basic but fastest Sysfs class

>>> from gpio4 import SysfsGPIO
>>> from gpio4.constants import BOARD_ORANGE_PI_PC
>>> pin_name = 6
>>> pin_num = BOARD_ORANGE_PI_PC[pin_name]
>>> pin = SysfsGPIO(pin_num)
>>> pin.export = True # regist pin through sysfs, same like pinMode()
>>> pin.direction = 'out' # same like pinMode()
>>> print(pin.value) # current level
>>> pin.value = 1 # same like digitalWrite()
>>> pin.export = False # clear this pin from sysfs

If you have any question on usage, it is strongly recommended to directly read well commented source codes. Also check kernel doc of sysfs, and this article.

gpio4's People

Contributors

hankso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

gpio4's Issues

Is hardware PWM planned?

As far as I understand, /sys/classes/pwm/... contains the facilities to initiate hardware PWMs, if available, which would be more practical to use with asyncio.

While reading through the code I can see that the current implementation is software PWM. So, is there any plan for hardware PWM in the future?

Thanks,

Source for 0.1.2 (as published on PyPI)?

Hello, and thanks for what looks like a great library!

This seems to be published on PyPI with a much more recent version than what is in this repository (and the files are indeed different in the wheel). Is the source being developed elsewhere? I couldn't find any other more up-to-date repository.

(I'm interested in packaging this for Guix, for use on a Rock64.)

No module named 'gpio4.GPIO'

Installed gpio4 using "python3 -m pip install gpio4" on OpenWrt.
While importing- gpio4.GPIO as GPIO, the following error occurs:

Traceback (most recent call last):
  File "/usr/pycode/lcd.py", line 38, in <module>
    import gpio4.GPIO as GPIO
ModuleNotFoundError: No module named 'gpio4.GPIO'

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.