Usage GPIO with I2C I/O expander

There is no GPIO on external I/O port of ODROID-H2. But, You can use GPIO with I2C I/O expander.

16 Port I2C GPIO Board Header Pin
VCC Power Supply Input (1.8V ~ 5.0V)
GND Ground
SCL I2C Serial Clock Input
SDA I2C Serial Data Input/Output
RST MCP23017 Reset (Active Low)
ITA Interrupt Output for Port A (PA0 ~ PA7), Output Configurable
ITB Interrupt Output for Port B (PB0 ~ PB7), Output Configurable
I2C Address configuration
A0 A1 A2 I2C Address
GND GND GND 0x20 (Default)
GND GND VCC 0x22
GND VCC GND 0x24
GND VCC VCC 0x26
VCC GND GND 0x28
VCC GND VCC 0x2A
VCC VCC GND 0x2C
VCC VCC VCC 0x2D

Wiring

We're going to make an LED example with the GPIO expander(MCP23017 Datasheet).


Download fritzing
- MCP23017 board part ☞ i2c_io_expander.fzpz
- ODROID-H2 part ☞ odroid-h2.fzpz
- fritzing parts ☞ i2c_io_expander.fzz

Connection Check

If you have done the wiring well, you can see the device as the following commands.

sudo apt install i2c-tools
  • If you're using an older kernel than 4.18, tap the “Old kernel version”.

kernel 4.18 or higher

When you have wired the GPIO expander to Pin #18(SCL) and #20(SDA).

sudo i2cdetect -y -r 2

When you have wired the GPIO expander to Pin #13(SCL) and #15(SDA).

sudo i2cdetect -y -r 3

Old kernel version

When you have wired the GPIO expander to Pin #18(SCL) and #20(SDA).

sudo i2cdetect -y -r 5

When you have wired the GPIO expander to Pin #13(SCL) and #15(SDA).

sudo i2cdetect -y -r 6

Install & build python packages

sudo apt install git python3-dev libi2c-dev python3-smbus

If you got this error.

E: Unable to locate package python3-smbus

Build the python3-smbus package.

git clone https://github.com/tkurbad/python3-smbus.git
cd python3-smbus
python3 setup.py build
python3 setup.py install

Get source code

git clone https://github.com/hardkernel/16port_i2c_gpio.git

Run led_example

chmod +x mcp23017.py
./mcp23017.py -h
odroid@odroid:~/work/mcp23017_python$ ./mcp23017.py -h
Usage:  mcp23017.py I2CBUS blink
	mcp23017.py I2CBUS -w GPIO [1|0]
	mcp23017.py I2CBUS -r GPIO

Options:
  -h, --help   show this help message and exit
  -w, --write  Write HIGH or LOW to GPIO
  -r, --read   Read from GPIO
  -a, --all    All off or on
  • If you're using an older kernel than 4.18, tap the “Old kernel version”.

kernel 4.18 or higher

When you have wired the GPIO expander to Pin #18(SCL) and #20(SDA).

sudo ./mcp23017.py 2 blink
sudo ./mcp23017.py 2 -w 0 1
sudo ./mcp23017.py 2 -r 5

When you have wired the I/O expander to Pin #13(SCL) and #15(SDA).

sudo ./mcp23017.py 3 blink
sudo ./mcp23017.py 3 -w 0 1
sudo ./mcp23017.py 3 -r 5

Old kernel version

When you have wired the GPIO expander to Pin #18(SCL) and #20(SDA).

sudo ./mcp23017.py 5 blink
sudo ./mcp23017.py 5 -w 0 1
sudo ./mcp23017.py 5 -r 5

When you have wired the I/O expander to Pin #13(SCL) and #15(SDA).

sudo ./mcp23017.py 6 blink
sudo ./mcp23017.py 6 -w 0 1
sudo ./mcp23017.py 6 -r 5

GPIO toggle frequency on mcp23017

1MHz I2C Speed

400kHz I2C Speed

100kHz I2C Speed

GPIO output current

Output Low : 8.0mA
Output High : 3.0 mA