GithubHelp home page GithubHelp logo

soultaker / rpi-mcp23s17 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from petrockblog/rpi-mcp23s17

0.0 1.0 0.0 22 KB

This Python module abstracts the GPIO expander MCP23S17 for usage on the Raspberry Pi.

License: MIT License

Python 100.00%

rpi-mcp23s17's Introduction

RPiMCP23S17
============

This is a Python module that abstracts the GPIO expander MCP23S17. It is intended for the use on a Raspberry Pi.

Provided Functions
------------------

As a quick overview, the module provides the following functions. Refer to the module documentation for details:

 - open
 - close
 - setPullupMode
 - setDirection
 - digitalRead
 - digitalWrite
 - writeGPIO
 - readGPIO

Installation
------------

If not already done, you need to install PIP via::

    sudo apt-get install python-dev python-pip

Install from `PyPI <https://pypi.python.org/pypi/RPiMCP23S17>`_::

    pip install RPiMCP23S17

Example
-------

The following demo peridically toggles all pins of two MCP23S17 components::

    from RPiMCP23S17.MCP23S17 import MCP23S17
    import time

    mcp1 = MCP23S17(bus=0x00, ce=0x00, deviceID=0x00)
    mcp2 = MCP23S17(bus=0x00, ce=0x00, deviceID=0x01)
    mcp1.open()
    mcp2.open()

    for x in range(0, 16):
        mcp1.setDirection(x, mcp1.DIR_OUTPUT)
        mcp2.setDirection(x, mcp1.DIR_OUTPUT)

    print "Starting blinky on all pins (CTRL+C to quit)"
    while (True):
        for x in range(0, 16):
            mcp1.digitalWrite(x, MCP23S17.LEVEL_HIGH)
            mcp2.digitalWrite(x, MCP23S17.LEVEL_HIGH)
        time.sleep(1)

        for x in range(0, 16):
            mcp1.digitalWrite(x, MCP23S17.LEVEL_LOW)
            mcp2.digitalWrite(x, MCP23S17.LEVEL_LOW)
        time.sleep(1)
        
        # the lines below essentially have the same effect as the lines above
        mcp1.writeGPIO(0xFFF)
        mcp2.writeGPIO(0xFFF)
        time.sleep(1)
        
        mcp1.writeGPIO(0x000)
        mcp2.writeGPIO(0x0000)
        time.sleep(1)

rpi-mcp23s17's People

Contributors

petrockblog avatar romilly avatar jonathan-daniel avatar englbit 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.