Raspberry Pi - PCA9536 Input/output Expander Python Tutorial

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

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: 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:

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:

The python code for PCA9536 can be downloaded from our github repository- DCUBE Store.

Here is the link

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

https://pypi.python.org/pypi/smbus-cffi/0.5.1

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 #

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"

time.sleep(0.5)

# 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

time.sleep(0.5)

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.

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020

    Discussions