RPI I2C GPIO Extend Board SKU:EP-0013

From 52Pi Wiki
Jump to navigation Jump to search

RPI I2C GPIO Extend Board

Description

There is a PCF8574 chip as main chip in this I2C GPIO extend board, it can offer 8bit GPIO and can select address by plugging a small jumper.
It can be connected with 8 same board, and you have a change to select the voltage in 5V and 3V.
It can prevent high voltage caused GPIO damage problem.
Warnning

DO NOT USE IT IN Raspberry Pi 3 B, Because of unsupported by wiringPi library.

Feature

  • 1)Extend GPIO
  • 2)Support both 5V and 3V power supply
  • 3)Support I2C protocol
  • 4)Dimensions: 3.4cm × 4cm

Presentation

Ep0013.jpg



Package includes

  • 1x RPI B+ to B GPIO Downgrade Board

How to use

WiringPi supports an extension module for the PCF8574 8-bit GPIO expander IC.
The Raspberry Pi has one I2C bus and the PCF8574 has a 3-bit address select port, so in-theory you can connect up 8 PCF8574’s to your Pi.
The PCF8574 is described as having “Quasi Bidirectional IO” ports, however wiringPi takes care of the procedure neccessary to turn a pin from output (the default) to input.

#include <wiringPi.h>
#include <pcf8574.h>

pcf8574Setup (int pinBase, int i2cAddress) ;
#The pinBase can be any number you like above 64 and the i2cAddress is the address of the device in the I2C bus – 0x38  is the default but they can change if you have multiple devices. 
Use the i2cdetect command (gpio i2cd) to probe your I2C bus to work out the right address to use.

You can call pcf8574Setup() as many times as needed for each PCF8754 you have in the system – just give it a different pin base and I2C bus address.

You don’t need to specify the number of pins here – the PCF8754 has 8 pins.

Notes

You need to load the I2C kernel modules before you can use I2C devices. Use the gpio command: gpio load i2c
Use the i2cdetect program to scan your I2C bus to make sure the Pi can see your devices.
If you have a Rev 1 Pi, then the i2cdetect command is: i2cdetect -y 0 if you have a Rev. 2 Pi, then use i2cdetect -y 1
The gpio command supports the i2cdetect command and automatically caters for board revision. Simply type: gpio i2cd
The wiringPi PCF8574 driver knows which revision Pi you have, so you know need to take any special precautions – your code will work on either a Revision 1 or 2 Pi.
The PCF8574 does not have programmable internal pull-up resistors, but the pins when in input mode effectively have an internal pull-up active.
The maximum current sourced of sunk on any pin is 20mA, however the chip can only source or sink a maxmum on 100mA.

How to drive PCF8574 with I2C

  • Create a C file and compile it

sudo vim.tiny PCF8574.c

#include <bcm2835.h>
char WriteBuf[1] = {0x00};
 
int main(int argc, char **argv)
{
    if (!bcm2835_init())
    return 1;
    bcm2835_i2c_begin();
   bcm2835_i2c_setSlaveAddress(0x20);
   bcm2835_i2c_set_baudrate(10000);
   
   while(1)
    {
        WriteBuf[0] = 0x00;
        bcm2835_i2c_write( WriteBuf , 1);
        bcm2835_delay(500);
 
        WriteBuf[0] = 0x01;
        bcm2835_i2c_write( &WriteBuf[0] , 1);
        bcm2835_delay(500);
    }

    bcm2835_i2c_end();
    bcm2835_close();
 
    return 0;
    }


  • Change Directory to PCF8574 in wiringPi and Compile it and run:

gcc -o PCF8574 PCF8574.c -lbcm8574
sudo ./PCF8574