I2C device trouble (MCP23018)

Hello!
New here, so hi everyone :smiley:

I’ve got a MCP23018 I/O expander (datasheet >HERE<) that I want to use with my Arduino UNO rev3.

Right now, the goal is to simple get an output working.
I’ve checked all wires for bad ones, and the MCP23018 is sitting properly in the breadboard.
I’ve got a good understanding of all my code, so it’s not something i just copy pasted :3

This is my code and circuit:

#include <Wire.h> 
 
void setup() {
  Serial.begin(9600);
  while(!Serial); //wait for Serial to start
  Serial.print("Voltage at Arduino analog A0 BEFORE: ");
  Serial.println(analogRead(A0));
  Wire.begin(); //join i2c bus (no parameters=join as master)
 
  Wire.beginTransmission(0x20); //connect to MCP23018, with address 0x20 (ADDR to GND)
  Wire.write(0x0D); //talk to GPPUB register
  Wire.write(0xFF); //enable pullup on all IO-B pins (1=enabled, 0=disabled)
  Wire.endTransmission();
   
 
  Wire.beginTransmission(0x20);
  Wire.write(0x13); //talk tao GPIOB register
  Wire.write(0x00); //sets all outputs HIGH
  Wire.endTransmission();
 
 
  Wire.beginTransmission(0x20);
  Wire.write(0x01);  //talk to IODIRB register
  Wire.write(0x00); //set GPB0-GPB7 as outputs
  Wire.endTransmission();
 
  delay(400);
 
  Serial.println("------------------------");
  Serial.print("Voltage at Arduino analog A0 AFTER: ");
  Serial.println(analogRead(A0));
  Serial.println("------------------------");
}
 
void loop() {
  delay(1000);
  Serial.println(analogRead(A0));
}

Really appreciate every help you want to give me. Even if you have ideas or complete solutions, I’d like that too.

Thank you all in advance!
~ Cap

BUUMP

please, someone? =/

Hi Captain_E

To start with, try running this I2C scanner program to check that the MCP23018 is responding on the I2C bus: https://github.com/RobTillaart/Arduino/tree/master/sketches/MultiSpeedI2CScanner

I assume you are trying to set outputs high on the MCP23018 and then measure the level of one of them using the Arduino's analog input? Couple of suggestions:

  • Try a lower value pullup resistor on the MCP23018 open drain output - 10K for example.

  • Test using one of the Arduino's digital inputs rather than analog.

  • I've not checked back the opcodes with the datasheet, but your comments say you are setting outputs high before making the IO pins outputs. Maybe try swapping those two blocks of code round.

ADDED ...

Wire.write(0x00); //sets all outputs HIGH

To output all 1s, shouldn't this write 0xFF?

And searching old posts, I found a thread from last year with basic code to turn an output on and off:

http://forum.arduino.cc/index.php?topic=288619.msg2020671#msg2020671

Regards

Ray

Deleted because I was an idiot, I miss identified the chip as a MCP32017

Chuck.