i/o expander shield // how to integrate in code

Hello everyone,

I’m quite new to the world of Arduino, trying to learn the code to create my RF project.

Right now I have a basic script, that I’m trying to integrate with the Expander I/O shield module: http://learn.linksprite.com/arduino/shields/io-expander-shield-for-arduino/

The thing is, I don’t understand what is happening in the above installation.

This is the code I have so far, but i’m not sure if it all works. I’m just struggling to convert my current connections from the Arduino, to the I2C connection of the expander. The code isn’t great right now, but I cannot test and fix it without understanding the expander… online links don’t seem to help.

How can I use the pins in the example of my lcd declaration, led, buzzer etc?

transceiver_module.ino (8.22 KB)

chipset MCP23017 communicates with Arduino Uno

Search for examples of an MC23017 library there are a few of them. The examples that come with them should help you use it in your code.

Look up the data sheet for this chip, yes it will look overwhelming at first but you don’t have to understand it all to get a lot of insight into how it works.

I2C - pronounced eye squared cee, is a serial protocol that transfers data one binary bit at a time over two wires one for clock and the other for data. Lots of online tutorials about that.

Hi, thanks for replying.

I’ve taken a look at the Adafruit mcp23017 library and at a ‘button’ script. What confuses me are the comments at the top “connect pin…” and why the mcp pinmodes are using e.g. 0 and 5… aren’t these the standard pins D0-D13?

How could I connect the lcd, in this case, to pins DA6, DB0, DB3, DA5, DA4, DA3, DA2

Sample code:

#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;
 
void setup() {  
 mcp.begin();      // use default address 0

 mcp.pinMode(0, INPUT);
 mcp.pullUp(0, HIGH);  // turn on a 100K pullup internally

 pinMode(5, OUTPUT);  // use the p13 LED as debugging
}



void loop() {
 // The LED will 'echo' the button
 digitalWrite(5, mcp.digitalRead(0));
}

why the mcp pinmodes are using e.g. 0 and 5... aren't these the standard pins D0-D13?

Only on an Arduino. These are extra pins.

How could I connect the lcd, in this case, to pins DA6, DB0, DB3, DA5, DA4, DA3, DA2

Simply the same way as you connect them on an Arduino, Anode to output, then a resistor then to ground.

These pin numbers are telling you they are on the A side of the chip. The chip has two 8 bit input / output ports in it, an A side and a B side.

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

What confuses me are the comments at the top "connect pin..."

These lines are telling you how to connect the chip to the Arduino.

Connect pins #15, 16 and 17 of the expander to ground (address selection)

Each device ( chip ) on the I2C bus has to have a unique address. The bus, that is pins A4 & A5, can control up to 127 devices. One MCP23017 can have its address set to one of eight different numbers. This is done by connecting three pins to 5V or ground. Each of the eight combinations possible results in a different address. For this example they want all three pins connected to ground.

This becomes important once you have more than one chip, you have to make sure each one responds to a different address.