Introduction: Raspberry Pi - PCA9536 Input/output Expander Python Tutorial

The PCA9536 is an 8-pin CMOS device that provides 4 bits of General Purpose parallel Input/Output (GPIO) expansion for I2C-bus/SMBus applications. It consists of a 4-bit Configuration register to serve the purpose of input or output selection, 4-bit Input Port register, 4-bit Output Port register and a 4-bit Polarity Inversion register active HIGH or active LOW operation. Here is its demonstration with the raspberry pi using python code.

Step 1: What You Need..!!

Picture of What You Need..!!

1. Raspberry Pi

2. PCA9536


3. I²C Cable


4. I²C Shield for Raspberry Pi


5. Ethernet Cable

Step 2: Connections:

Picture of Connections:

Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.

Then connect the one end of I2C cable to PCA9536 sensor and the other end to the I2C shield.

Also connect the Ethernet cable to the pi or you can use a WiFi module.

Connections are shown in the picture above.

Step 3: Code:

Picture of Code:

The python code for PCA9536 can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

The datasheet of PCA9536 can be found here:

We have used SMBus library for python code, the steps to install SMBus on raspberry pi is described here:

You can also copy the code from here, it is given as follows:

# Distributed with a free-will license.

# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

# PCA9536

# This code is designed to work with the PCA9536_I2CIO I2C Mini Module available from


import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# PCA9536 address, 0x41(65)

# Select configuration register, 0x03(03)

# 0xFF(255) All pins configured as inputs

bus.write_byte_data(0x41, 0x03, 0xFF)

# Output to screen

print "All Pins State are HIGH"


# PCA9536 address, 0x41(65)

# Read data back from 0x00(00), 1 byte

data = bus.read_byte_data(0x41, 0x00)

# Convert the data to 4-bits

data = (data & 0x0F)

for i in range(0, 4) :

if (data & (2 ** i)) == 0 :

print "I/O Pin %d State is LOW" %i

else :

print "I/O Pin %d State is HIGH" %i


Step 4: Applications:

PCA9536 can be employed as an I/O expander. It provides a simple solution when additional input/output is required. Usually it is employed in systems which require expansion for ACPI power switches, sensors, push buttons, LEDs, fans, etc.


About This Instructable



More by Dcube Tech Ventures:Home Automation with Raspberry Pi using Relay boardMotion Control with Raspberry Pi and LIS3DHTR, 3-Axis Accelerometer, using Python3-Axis Accelerometer, ADXL345 with Raspberry Pi using Python
Add instructable to: