Giter VIP home page Giter VIP logo

pyrpio's Introduction

PyRPIO

./icon.png

A Python 3 addon which provides high-speed access to the Raspberry Pi GPIO interface, supporting regular GPIO as well as i²c, PWM, SPI, and MDIO.

This package is inspired by node-rpio which is a node.js addon.

PyPI

Compatibility

  • Raspberry Pi Models: A, B (revisions 1.0 and 2.0), A+, B+, 2, 3, 3+, 3 A+, 4, Compute Module 3, Zero.
  • Python 3.7+

Install

Install the latest from PyPi:

pip install pyrpio

Supported Interfaces

  • GPIO
  • PWM
  • I2C
  • MDIO
  • SPI

Examples

from pyrpio.i2c import I2C
from pyrpio.mdio import MDIO
from pyrpio.i2c_register_device import I2CRegisterDevice
### I2C Operations ###

i2c_bus = i2c.I2C('/dev/i2c-3')
i2c_bus.open()

i2c_bus.set_address(0x50)

i2c_bus.read_write(data=bytes([0x23]), length=1)

i2c_dev = I2CRegisterDevice(bus=i2c_bus, address=0x50, register_size=1, data_size=1)

# Read register
val = i2c_dev.read_register(register=0x23)

# Read sequential registers
vals = i2c_dev.read_register_sequential(register=0x23, length=4)

# Close up shop
i2c_bus.close()

### MDIO Operations ###

# Create bus using GPIO pins 23 and 24 (bit-bang)
mdio_bus = mdio.MDIO(clk_pin=23, data_pin=24, path='/dev/gpiochip0')
mdio_bus.open()

# Read register 0x10 from device 0x30 (CLAUSE-45)
mdio_bus.read_c45_register(0x30, 0x00, 0x10)

# Read register set from device 0x30 (CLAUSE-45)
mdio_bus.read_c45_registers(0x30, 0x00, [0,1,2,3,4])

# Close up shop
mdio_bus.close()

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Maintainers

pyrpio's People

Contributors

adamtec 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.