Test program for MCP23017

I'm building a modified open source liquid handling robot based on evobot using ramps hardware. While testing, it's not registering the MCP23017 chip that it's using for I/O expansion. I'm trying to write a program to test to see if the chip is working at all. Preferably I can have an output toggle between high and low that I can test with a multimeter or alternately I can add an LED. Please tell me that there's something wrong with my code, I'm getting the fail notification each time.
https://bitbucket.org/afaina/evobliss-software/wiki/Home

#include <Wire.h>
#include "Adafruit_MCP23X17.h"

Adafruit_MCP23X17 mcp;

void setup() { 
  Serial.begin(9600);
   
  mcp.begin_I2C();      // use default address 0
if (!mcp.begin_I2C())
  {
    Serial.println("fail");
while(1);
  }
  mcp.pinMode(8, OUTPUT);
   pinMode(LED_BUILTIN, OUTPUT);  // use the p13 LED as debugging
  
}



void loop() {

  mcp.digitalWrite(8,HIGH);
  digitalWrite(LED_BUILTIN,HIGH);
  delay(1000);
   mcp.digitalWrite(8,LOW);
  digitalWrite(LED_BUILTIN,LOW);
  delay(1000);

}

Step one:

  • Check with an I2C Scanner if you have wired your mcp correctly and tell us the reported I2C address.
  • Show your circuit diagram how you have wired your mcp
  • show real pictures wherein we can see all components and each wiring.

What does that mean? A failure to compile? If so, post the entire error message. If not, explain what that means and where the message comes from.

A good I2C scanner sketch:

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Did you look at the mcp23017 examples that come with the library?

  mcp.begin_I2C();      // use default address 0
if (!mcp.begin_I2C())
  {
    Serial.println("fail");
while(1);
  }
  mcp.pinMode(8, OUTPUT);
   pinMode(LED_BUILTIN, OUTPUT);  // use the p13 LED as debugging
  
}

You do realize you called mcp.begin() twice, don't you?
And, I don't believe you'll find it at address zero. Addresses 0x20 through 0x27 are where they usually are. IF you haven't set any jumpers, it's probably at 0x27.

is the chip wired with the 4.7k pullup resistors (can work without them) and what are the address pins pulled to?

I had it serial printing "fail" if mcp.begin didn't complete.
I ran your program and it didn't find any devices.

I checked with the I2C scanner shown in the comments and it found nothing. also note that there internal pull up resistors and the ramps board

I used a spare board that I had, same program and wiring and it worked. I may have a dud chip.

image

Why a voltage divider on the A1 (address) pin?

Where are the pullups for SDA and SCL?

Pull ups are located on the ramps board that is powering it. No idea why there is a voltage divider as I didn't design this but I do know that the design has previously worked.

not a divider, one should not populated

Please elaborate?

the pin should be either pulled high or low.
having only one resistor makes that choice

I don't know why it's like that, it's someone else's design which previously worked.

is the value of 1 of the resistors 0 ohms?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.