Skip to content

FlippieCoetser/MCP23018.Python

Repository files navigation

MCP23018.Python

Python Library for Microchip MCP23018 16-bit I/O Expander with Open-Drain Outputs

Dependencies

Boards: USB I2C Click
Libraries:

  1. hidapi
pip install hidapi
  1. blinka
pip install adafruit-blinka

Note: click here for instructions how to setup your environment to use the USB I2C Click with circuitpython

This library is work in progress

The test.py file contains example code which has been tested on windows 10

To use library, instantiate MCP23018 as follows

mcp23018 = MCP23018(RESET_Pin = pin, I2C_Interface=I2C)

MCP23018 API

General

  1. Reset Device
mcp23018.reset()
  1. Wait x seconds
mcp23018.wait(x)

Debugging

Debugging on all modules are by default switched off

  1. Switch External RESET_PIN debugging on
mcp23018.RESET.debug = True
  1. Switch External I2C Interface debugging on
mcp23018.I2C = True
  1. Switch Configuration Module debugging on
mcp23018.Configuration.debug = True
  1. Switch specific GPIO PIN debugging on
mcp23018.GPIO.port[PORT.B].pin[PIN.GP5].debug = True

Device Configuration

  1. Set Configuration Parameter
mcp23018.Configuration.bank = PARAMETERS[PARAMETER.BANK].SEPARATE
  1. Get Configuration Parameter
configuration = mcp23018.Configuration.bank

All GPIO PINS

  1. Set all GPIO Pins value
mcp23018.GPIO.value = STATE.LOW
  1. Get all GPIO Pins value
 state = mcp23018.GPIO.value
  1. Set all GPIO Pins direction
mcp23018.GPIO.direction = DIRECTION.OUT
  1. Get all GPIO Pins direction
direction = mcp23018.GPIO.direction

Specific PORT's GPIO PINS

  1. Set specific PORT GPIO Pins value
mcp23018.GPIO.port[PORT.A].value = STATE.LOW
  1. Get specific PORT GPIO Pins value
state = mcp23018.GPIO.port[PORT.A].value
  1. Set specific PORT GPIO Pins direction
mcp23018.GPIO.port[PORT.A].direction = DIRECTION.OUT
  1. Get specific PORT GPIO Pins direction
mcp23018.GPIO.port[PORT.A].direction = DIRECTION.OUT

Specific GPIO PIN

  1. Set specific GPIO Pins value
mcp23018.GPIO.port[PORT.A].pin[PIN.GP0].value = STATE.LOW
  1. Get specific GPIO Pins value
state = mcp23018.GPIO.port[PORT.A].pin[PIN.GP0].value
  1. Set specific GPIO Pins direction
mcp23018.GPIO.port[PORT.A].pin[PIN.GP0].direction = DIRECTION.OUT
  1. Get specific GPIO Pins direction
direction = mcp23018.GPIO.port[PORT.A].pin[PIN.GP0].direction

About

Python Library for MCP23018

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages