MCP cover image
See in Github
2021-06-22

MCP23017/08 raspberrypi的GPIO Expander芯片Python模块

3

Github Watches

8

Github Forks

6

Github Stars

MCP230XX-Python-Module

Python 2.x and 3.x module to use the MCP23017 or MCP23008 GPIO expander chip and the Raspberrypi. This module supports using the interrupt capabilities on the MCP230XX chips

This requires the smbus module for the i2c connection and the RPi.GPIO or compatible module to use the interrupt capabilities.

Included at the end of the module are some example uses of the module

Connection to the MCP230XX from the Pi are as follows

  • Pi SCL to MCP SCL
  • Pi SDA to MCP SDA
  • Pi 3.3V to MCP VDD
  • Pi Gnd to MCP Vss
  • Pi 3.3V to MCP RESET (Could be tied to a Pi GPIO if you want active control of the RESET)
  • Pi 3.3V to MCP A0
  • Pi Gnd to MCP A1
  • Pi Gnd to MCP A2
  • Pi GPIO # to MCP INTA
  • Pi GPIO # to MCP INTB

With the above A0-A2 connections the i2c address is 0x21

For the MCP23008 the MCP GPIOA 0-7 are IO 0-7 in this module For the MCP23017 the MCP GPIOA 0-7 are IO 0-7 and the MCP GPIOB 0-7 are IO 8-15 in this module

Current functions include:

  • interrupt_options(outputType = 'activehigh', bankControl = 'separate')
  • set_register_addressing(regScheme='8bit')
  • set_mode(pin, mode, pullUp='disable')
  • invert_input(pin, invert = False)
  • output(pin, value)
  • input(pin)
  • add_interrupt(pin, callbackFunctLow='empty', callbackFunctHigh='empty')
  • remove_interrupt(pin)
  • register_reset()

Example uses

to initialize the chip

MCP = MCP230XX('MCP23017', i2cAddress, '16bit')

to set up an input and output

MCP.set_mode(0, 'output') # set IO 0 to an output MCP.set_mode(1, 'input') # set IO 1 to an input MCP.set_mode(10, 'input', 'enable') # set IO 10 to an input with the pullup enabled

to set an output

MCP.output(0,1) # set IO 0 high MCP.output(0,0) # set IO 0 low

to read an input

MCP.input(1) # reads current value on IO 1, return 0 for low and 1 for high

to set interrupt options

MCP.interrupt_options(outputType = 'activehigh', bankControl = 'separate')

  • the interrupt pins can be set as either activehigh, activelow or opendrain
  • for the MCP23017 the interrupts for IO 0-7 and IO 8-15 can be trigger INTA and INTB respectively with bankControl = 'seperate' or and an intterupt on any of the IO (0-15) can be sent to both INTA and INTB with bankControl = 'both'

to add and remove an interrupt to an input

MCP.add_interrupt(10, callbackFunctLow=functA, callbackFunctHigh=functB) # add interrupt to IO 10 with call back functions functA and functB

  • separate callback functs can be set for when the pin goes high and low, the same function can be used for callbackFunctLow and callbackFunctHigh

On the Raspberry Pi side using the RPi.GPIO module as IO, the following needs to be included in your program IO.add_event_detect(intPin,IO.RISING,callback=MCP.callbackB)

callback = either MCP.callbackA or MCP.callbackB if using the bankControl = 'seperate' or callback = MCP.callbackBoth if using the bankControl = 'both'

MCP.remove_interrupt(10) # remove interrupt from IO 10

相关推荐

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Lists Tailwind CSS classes in monospaced font

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • n8n-io
  • 具有本机AI功能的公平代码工作流程自动化平台。将视觉构建与自定义代码,自宿主或云相结合,400+集成。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

    Reviews

    5 (1)
    Avatar
    user_qSmxPV4t
    2025-04-17

    As a dedicated user of the MCP230XX-Python-Module, I am extremely impressed with its functionality and ease of use. This Python module, created by owainm713, greatly simplifies integrating MCP230XX I/O expanders into my projects. The documentation is clear, and the GitHub repository is well-maintained, making it an invaluable resource for developers. Highly recommended!