Git Product home page Git Product logo

cymcp23016's Introduction

CyMCP23016

Build Status

An Arduino library for the Microchip MCP2016 I/O Expander IC. Based on the Adafruit library for the MCP23017. I created this library because I didn't find an Arduino library for the MCP23016 that I liked. The Adafruit MCP23017 library would have been ideal, but is only compatible with the MCP23017. This library derived from the Adafruit library to provide the same simplicity and ease of use, but for the MCP23016. This library is compatible with both ATmel AVR and Espressif ESP boards. The Microchip MCP23016 is a 16-bit I/O expander. It provides 16 additional GPIO pins accessible via I2C. See the MCP23016 datasheet. Unlike the MCP23017, the MCP23016 does not have builtin pullup resisters. While interrupts are supported on the MCP23016, they have not been implemented in this library yet.

How to use

Include CyMCP23016.h in your sketch, connect the MCP23016's SDA and SCL pins to your Arduino's SDA and SCL pins and then you can configure and read/write pins similar to a regular Arduino pin as shown in the example below:

#include <Arduino.h>
#include "CyMCP23016.h"

#define LED_PIN MCP23016_PIN_GPIO0_0  // Attach LED to Port 0, Pin 0

CyMCP23016 mcp;

void setup() {
    Serial.begin(9600);

    // Init the MCP23016 at the default address.
    mcp.begin();

    // Init the LED pin.
    mcp.pinMode(LED_PIN, OUTPUT);
    mcp.digitalWrite(LED_PIN, LOW);
}

void loop() {
    delay(1000);

    // Turn the LED on, then read back the state to verify.
    mcp.digitalWrite(LED_PIN, HIGH);
    uint8_t state = mcp.digitalRead(LED_PIN);
    Serial.print(F("LED is ));
    Serial.println(state == HIGH ? "ON", "OFF");

    delay(1000);

    // Turn the LED off, then
    mcp.digitalWrite(LED_PIN, LOW);
    state == mcp.digitalRead(LED_PIN);
    Serial.print(F("LED is ));
    Serial.println(state == HIGH ? "ON" : "OFF");
}

How to install

For PlatformIO:

platformio lib install CyMCP23016

For Arudino IDE: See https://www.arduino.cc/en/Guide/Libraries

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.