adafruit / adafruit/Adafruit-MCP23017-Arduino-Library

Please include an example for using multiple mcp chips

Open Beginner friendly
#90 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
385
Forks
204
PR merge metrics
No merged PRs in 30d

Description

This is specific to the mcp23017 chip
```
#include

Adafruit_MCP23X17 mcp1; //declaration for chip 1
Adafruit_MCP23X17 mcp2; //declaration for chip 2

/*
use the following table to configure A0-2 on your mcp chip to an I2c address

address A2 A1 A0 i2c address
000 low low low 0x20 <-- we will be using this for chip 1
001 low low high 0x21 <-- and this one for chip 2
010 low high low 0x22 every additional address can be used for up to 8 chips total
011 low high high 0x23
100 high low low 0x24
101 high low high 0x25
110 high high low 0x26
111 high high high 0x27
*/
void setup() {
Serial.begin(9600);
mcp1.begin_I2C(0x20); //call for a connection to chips using addresses above
mcp2.begin_I2C(0x21);

mcp1.pinMode(0, INPUT_PULLUP); // table for the pin translation of mcp23 chips can be found on the main page of the library
mcp1.pinMode(8, OUTPUT);
mcp1.pinMode(9, OUTPUT);
mcp2.pinMode(9, OUTPUT);
}

void loop() {

Serial.print("pin0 = "); Serial.println(mcp1.digitalRead(0 ));

if (mcp1.digitalRead(0) == 0){ // check if pin 0 is grounded, if so light up the led on pin 8
mcp1.digitalWrite(8, HIGH);
}
else{
mcp1.digitalWrite(8, LOW);
}

mcp1.digitalWrite(9, HIGH); // make chip 1 pin 9 led blink on and then off
delay(500);
mcp1.digitalWrite(9, LOW);
delay(500);

mcp2.digitalWrite(9, HIGH); // make chip 2 pin 9 led blink on and then off
delay(500);
mcp2.digitalWrite(9, LOW);
delay(500);

}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue includes a complete MCP23017 sketch using two Adafruit_MCP23X17 instances and I2C addresses 0x20 and 0x21. Review the repository's existing example layout and determine where usage examples belong. Done means a discoverable example documents multiple chips and can be compiled for the Arduino library.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
documentation, embedded-iot
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.