Problem with connecting a MCP23017 with arduino Uno

hello everyone,
I have been working, for the laste 2 days, on how ti expand inputs and outputs of an arduino Uno and I use a GPIO MCP23017

MCP23017/MCP23S17 Data Sheet (microchip.com)

I found this code on github I followed all the steps . here is the link
GitHub - makersdigest/T05-MCP23017-GPIO-Expander

but it doesn’t work for me I do not have signals in the outputs .
can some one help me fixe this problem please?

thank you very much.

Hi, @thalesmaissa
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.

Can you please post a copy of your circuit please, not the circuit that is published, but a circuit drawn by you of YOUR project.
If you have any wiring problems, reverse engineering will probably find it.
How are you monitoring the outputs of the 23017?

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Hi @TomGeorge ,
I am monitoring the outputs with LEDs and also i use an oscilloscope to visualize the outputs signals .
i didn’t drew a circuit yet because i still looking for the solution i did the samething like in the github link. I can send you a picture of my circuit.

also the pin 20 of the MCP23017 (INTA) is always high. I can see it from the oscilloscpe.
thank you.

As you are using the I2C version of the I/O expander, is it detected using one of the I2C scanner sketches?

hello @markd833,

I tried with this sketch , i found it in the iDE exemples, the I2C scanner.
it seems that there is something wrong . the compilation is not finished it’s blocked as you can see in the screenshoot!

Hi,
The link I posted will show you how to post your code.
You need 4k7 resistors on each SDA and SCK line to 5V.

Tom… :grinning: :+1: :coffee: :australia: :woozy_face:

ok I’ll try with the resistors.
thank you so much.
I’ll send a msg as soon as I get the resistors and try them.

Hi,
What resistors do you have to hand?

Tom… :grinning: :+1: :coffee: :australia:

I added 2 resistors 4K7ohm for each of the SDA and SCK. but it did change anything .


here is the code that i used I added serial.print to see where the compilation is blocked
</>
<
#include <Wire.h>

void setup() {
Serial.begin(19200);
Serial.println(“before”);
Wire.begin(); //creates a Wire object//Wake up i2c bus
Serial.println(“Wake up i2c bus”);
// set I/O pins to outputs
Wire.beginTransmission(0x20); //begins talking to the slave device// MCP23017 Adress
Serial.println(“begins talking to the slave device”);
Wire.write(0x00); //selects the IODIRA register
Serial.println(“selects the IODIRA register”);
Wire.write(0x00); //this sets all port A pins to outputs
Serial.println(“set all port A pins to outputs”);
//**********************//
Wire.endTransmission(); //stops talking to device
Serial.println(“stop talking to device”);
Serial.println(“end stup”);
}

void loop(){
Serial.println(“begin loop”);
Wire.beginTransmission(0x20); //starts talking to slave device
Serial.println(“starts talking to slave device 2”);
Wire.write(0x12); //selects the GPIOA pins
Serial.println(“selects the GPIOA pins 2”);
Wire.write((byte)0X01); // turns on pins 0 and 1 of GPIOA
Serial.println(" turns on pins 0 of GPIOA");
Wire.endTransmission(); //ends communication with the device
Serial.println(“ends communication with the device 2”);
Serial.println(“end loop”);
}
</>

The compilation stops here //***********************//

Hi,
Sorry no.
You leave the SDA and SCK wires connected as in the first image.
But connect one resistor between SDA and 5V, and another resistor between SCK and 5V.

Tom… :grinning: :+1: :coffee: :australia:

I am sorry for the code I didn’t understand how to use the code tags
<#include <Wire.h>>

#include <Wire.h>

void setup() {
Serial.begin(19200);
Serial.println(“before”);
Wire.begin(); //creates a Wire object//Wake up i2c bus
Serial.println(“Wake up i2c bus”);
// set I/O pins to outputs
Wire.beginTransmission(0x20); //begins talking to the slave device// MCP23017 Adress
Serial.println(“begins talking to the slave device”);
Wire.write(0x00); //selects the IODIRA register
Serial.println(“selects the IODIRA register”);
Wire.write(0x00); //this sets all port A pins to outputs
Serial.println(“set all port A pins to outputs”);
//**********************//
Wire.endTransmission(); //stops talking to device
Serial.println(“stop talking to device”);
Serial.println(“end stup”);
}

void loop(){
Serial.println(“begin loop”);
Wire.beginTransmission(0x20); //starts talking to slave device
Serial.println(“starts talking to slave device 2”);
Wire.write(0x12); //selects the GPIOA pins
Serial.println(“selects the GPIOA pins 2”);
Wire.write((byte)0X01); // turns on pins 0 and 1 of GPIOA
Serial.println(" turns on pins 0 of GPIOA");
Wire.endTransmission(); //ends communication with the device
Serial.println(“ends communication with the device 2”);
Serial.println(“end loop”);
}

There we go.

Hi,
I am surprised you are not using a MCP23017 library.

google

mcp23017 arduino library

Tom… :grinning: :+1: :coffee: :australia:

i tried with both this code ysed the lib <wire .h> and I used also the lib adafruit_MCP23017 in an other code i’ll send it
just tell me how should i put the code tags ?

Hi,
If you go to the IDE and select Edit ,then select Copy for Forum.
This will automatically copy your code to the clipboard with the needed tags.
Then you go to your post and just paste.
It should be in its own scrolling screen.

Tom… :grinning: :+1: :coffee: :australia:

Hi,
Try this Adafruit library code I have edited.
It compiles but I have not run it.
It should make output 0 on the 23017 turn on and off each second, the UNO onboard LED should also flash with it.

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

// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!

// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)

// Input #0 is on pin 21 so connect a button or switch from there to ground

Adafruit_MCP23017 mcp;
int OnboardLED =13; 
void setup() {  
  mcp.begin();      // use default address 0

  mcp.pinMode(0, OUTPUT);
   pinMode(OnboardLED, OUTPUT);  // use the p13 LED as debugging
  
}



void loop() {
  // The LED will 'echo' the output
 // digitalWrite(13, mcp.digitalWrite(0));
  mcp.digitalWrite(0,HIGH);
  digitalWrite(OnboardLED,HIGH);
  delay(1000);
   mcp.digitalWrite(0,LOW);
  digitalWrite(OnboardLED,LOW);
  delay(1000);

}

Tom… :grinning: :+1: :coffee: :australia:
PS. Make sure you have the 4K7 resistors installed.

Ah okay I see . actually I’m using 2 pcs that why I can’t copy and paste the code .

the compilation is not blocked anyways . Now I can see the output signals via the oscilloscope and the LEDs by adding the 2 resistors.

Thank you so much .
Maissa.

I have an other question please.
why the signals that i visualize in the oscilloscope are lower than 5 v (i have 2.2V) ?

Hi,
Which signals?
What does the 5V supply on the 23017 measure as on the scope?
You do have DC coupling selected on the scope?

Tom… :grinning: :+1: :coffee: :australia:

@TomGeorge I compiled your code and it works correctly .
thank you