how to use ZMCP23017 with Arduino SAMD21


i got no connection with my mcp23017, the mcp A0:A1:A2 are HIGH, i was trying different addresses, i always got ‘0’ by digitalRead.
i trying this code:

#include <Wire.h>
#include "ZMCP23017.h"
ZMCP23017 mcp;

void setup()

  mcp.begin(0x27); // 7=0x27
  mcp.pinMode(4, OUTPUT);         mcp.digitalWrite(4, LOW);
  mcp.pinMode(5, OUTPUT);         mcp.digitalWrite(5, HIGH);
  mcp.pinMode(0, INPUT_PULLUP);   //mcp.pullUp(upB, 1);
  mcp.pinMode(1, INPUT_PULLUP);   //mcp.pullUp(doB, 1);
  mcp.pinMode(2, INPUT_PULLUP);   //mcp.pullUp(canB, HIGH);
  mcp.pinMode(3, INPUT_PULLUP);   //mcp.pullUp(setB, 1);

void loop()
  for (int i = 0; i <= 15; i++)

where is the problem?

no idea?

Try a Serial.println(mcp.test()); after the call to mcp.begin() to validate the connection.

its always the same. if the address 0x20 or 0x27, its always the same output.

Post your circuit and exact hardware.

Arduino MKR Zero I2C: MCP23017, SH1106_128x64(OLED), Adafruit_BNOo055(IMU) SPI: SD, Adafruit_GPS

with Adafruit_MCP23017 it works sometimes, but it freezes when i use the SPI. without the MCP it works pretty well.

Well, until you have the MCP23017 working reliably there is no point in having all the other hardware connected and adding to the confusion. You didn't mention it in your original post and the sample code doesn't deal with it anyway.

Since you say it sometimes works the answer is probably yes, but I'll ask anyway: Do you have the appropriate pull-ups on the I2C bus lines?

Are you using the Adafruit library? (It wasn't the first one that came up for me in a search.)

i just use the test code above, i just want to test the MCP23017 with ZMCP, because the Adafruit_MCP code doesnt work in my original code. so i was searching for a better code to work with my samd21, but i think the problem is somewhere in the wire lib.

there are pullups onboard at the mkr zero board, 10k pullups and i think some pullups in the moduls. i have 2.4k pullups in the near of the MCP, but not connected anymore, i think it works more worse with these.

Like I said, I would recommend just testing with the MCU and the MCP23017 with 4.7k pull-ups. Until you get the simple configuration working there is no point in adding all the other fluff.

Sure, there could be a error in the Wire library, but I'd guess that there is more likely to be a problem with something that you are doing, or perhaps in the the MCP23017 libraries.

it doesnt work :/ is there another lib, or get someone the ZMCP-lib working?

Barst: it doesnt work :/

What doesn't work? The simplified setup that I suggested? Post a photo of your hardware and connections.

Barst: is there another lib, or get someone the ZMCP-lib working?

You could just go down a level and use only the Wire library to access a register to see if that works. Check the return codes from the Wire functions to see if and what errors occur.