You’ll need to instantiate an instance of the class for each MCP23017 and use the address you assigned them in the mcp.begin(addr) routine. You may not have noticed but it’s overloaded to also take a parameter, the address.
If you’re using the online code editor, there’s a little github icon that shows next to Library name once its selected. This takes you right to the firmware source for the library.
Great @jbeacon and @ScruffR !
I scrolled through the library: it’s a masterpiece!
But it goes far beyond my capabilities to interpret how to use all possibilities without an example…
If I take one of the existing examples “toggle.ino” (LINK), I would like to try it out with a second MCP23017 chip.
So, the first thing I do is set an address with the three pins:
Below is part of the “toggle.ino” sketch.
It says: “// use default address 0”
I guess the default address “0” mentioned in the example is actually HEX address “0x20”, right?
Suppose I select for the second chip address “0x21”, that must then be address “1” to use in my sketch. OK?
The questions for me are:
How do I indicate both address 1 and 2 for my two chips
How do I repeat the same commands for the corresponding pins on the two chips?
Adafruit_MCP23017 mcp;
void setup() { mcp.begin(); // use default address 0
Sorry to bump this thread but is there any way to change the wirespeed for these calls (i need it to be as fast as possible) and perhaps do digitalWriteFast against the chip?
I want to use one of these to control 16 triac devices for ac dimming so increasing the speed of read and writes would be great. The triac relies on millisecond timing so i need to speed my calls up as much as possible
@bigjme, the fastest wire speed supported by the Photon is 400KHz.
All digital writes via the MCP23017 are done via a set of I2C commands so there is no "digitalWriteFast" that can be done.
There is, however, an SPI version of the chip (MCP23S17) that can handle 10MHz SPI. I believe I have seen an SPI library for this version of the chip. At that speed, you could control all 16 channels within the target timeframe.
@bigjme, yes, that is the way to change the speed. The docs about setClockSpeed() say:
Sets the I2C clock speed. This is an optional call (not from the original Arduino specs.) and must be called once before calling begin(). The default I2C clock speed is 100KHz and the maximum clock speed is 400KHz.