HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Feb 20, 2013, 04:33 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
316 Posts
Discussion
PCF8574P/AP I2C portexpanders

Hi guys,
Following the control unit based on the Arduino, I have also created a little expantion pcb. I want to use it for some nummeric leds, but it can also be used for extra button inputs or extra output pins. The top version is an older version which I used in my ships. Address is defined with the top left pins which can be pulled to 0 or 5V (000 tot 111).
The larger one is just 000. I want to use this one as a default for a channel indicator for my Arduino Control and leave it s simple as possibly for everyone to use (also people with no experience in soldering and programming).
I'm now programming a simple arduino sketch to let you guys test the thingy. Will follow the next couple of days. Any questions or comments, don't hasitate.

I have some issues with the unit in combination with NRF24L01 units, I try to get around that problem. Like another forum said, following the datasheet it should be possible. Keep you posted on that.

grtz
Danny

Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Sign up now
to remove ads between posts
Old Feb 20, 2013, 09:13 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
316 Posts
Sorry slight error in the pcb, will be corrected soon.

Edit: Corrected version



Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Feb 20, 2013 at 09:23 AM.
Reply With Quote
Old Feb 20, 2013, 12:52 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
316 Posts
The Code

And as promised a testprogram to test the duo version of the PCF port expander. Just tested it on an breadboard. You can change addresses by pulling pin 1-3 to 0 or 5V creating 8 different addresses. The PCF8574P and PCF8574AP both have a different startnumbers (100 and 111) so total of 16 PCF's is possible with each 8 i/o ports that can be used for input and output. The test program is for inputs. In the program you can also find a line for writing to the PCF.

grtz.
Danny

Code:
#include <Wire.h>

#define expander1 B0111000  // Address with three address pins grounded.
#define expander2 B0100000  // Note that the R/W bit is not part of this address.
                            // B0111000 = ap
                            // B0100000 = p

int PinValue1; int PinNumber1;
int PinValue2; int PinNumber2;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  expander1Write(B00000000);
  expander2Write(B00000000);
}

void loop() {
//expander1Write(B11111111); // all pins HIGH
//expander1Write(B00000000); // all pins LOW
//expander2Write(B11111111); // all pins HIGH
//expander2Write(B00000000); // all pins LOW

// read expander1 pin (input)
  PinValue1 = (expander1Read());
  PinValue2 = (expander2Read());
 
// First PCF8574 on address 0  
////////////////////////////////// PIN 0 ///////////////////////////////
   if (PinValue1 == 0) {
    PinNumber1 = 0;
    } 
////////////////////////////////// PIN 8 ///////////////////////////////
   if (PinValue1 >= 128) {
    PinNumber1 = 8;
    PinValue1 = (PinValue1 - 128); }
////////////////////////////////// PIN 7 ///////////////////////////////
   if (PinValue1 >= 64) {
    PinNumber1 = 7;
    PinValue1 = (PinValue1 - 64); }  
////////////////////////////////// PIN 6 ///////////////////////////////
   if (PinValue1 >= 32) {
    PinNumber1 = 6;
    PinValue1 = (PinValue1 - 32); }    
////////////////////////////////// PIN 5 ///////////////////////////////
   if (PinValue1 >= 16) {
    PinNumber1 = 5;
    PinValue1 = (PinValue1 - 16); }    
////////////////////////////////// PIN 4 ///////////////////////////////
   if (PinValue1 >= 8) {
    PinNumber1 = 4;
    PinValue1 = (PinValue1 - 8); }    
////////////////////////////////// PIN 3 ///////////////////////////////
   if (PinValue1 >= 4) {
    PinNumber1 = 3;
    PinValue1 = (PinValue1 - 4); }  
////////////////////////////////// PIN 2 ///////////////////////////////
   if (PinValue1 >= 2) {
    PinNumber1 = 2;
    PinValue1 = (PinValue1 - 2); }    
////////////////////////////////// PIN 1 ///////////////////////////////
   if (PinValue1 >= 1) {
    PinNumber1 = 1;
    PinValue1 = (PinValue1 - 1); }   
    
// Second PCF8574 on address 0
////////////////////////////////// PIN 0 ///////////////////////////////
   if (PinValue2 == 0) {
    PinNumber2 = 0;
    } 
////////////////////////////////// PIN 8 ///////////////////////////////
   if (PinValue2 >= 128) {
    PinNumber2 = 8;
    PinValue2 = (PinValue2 - 128); }
////////////////////////////////// PIN 7 ///////////////////////////////
   if (PinValue2 >= 64) {
    PinNumber2 = 7;
    PinValue2 = (PinValue2 - 64); }  
////////////////////////////////// PIN 6 ///////////////////////////////
   if (PinValue2 >= 32) {
    PinNumber2 = 6;
    PinValue2 = (PinValue2 - 32); }    
////////////////////////////////// PIN 5 ///////////////////////////////
   if (PinValue2 >= 16) {
    PinNumber2 = 5;
    PinValue2 = (PinValue2 - 16); }    
////////////////////////////////// PIN 4 ///////////////////////////////
   if (PinValue2 >= 8) {
    PinNumber2 = 4;
    PinValue2 = (PinValue2 - 8); }    
////////////////////////////////// PIN 3 ///////////////////////////////
   if (PinValue2 >= 4) {
    PinNumber2 = 3;
    PinValue2 = (PinValue2 - 4); }  
////////////////////////////////// PIN 2 ///////////////////////////////
   if (PinValue2 >= 2) {
    PinNumber2 = 2;
    PinValue2 = (PinValue2 - 2); }    
////////////////////////////////// PIN 1 ///////////////////////////////
   if (PinValue2 >= 1) {
    PinNumber2 = 1;
    PinValue2 = (PinValue2 - 1); } 

////////////////////////////////// DEBUG ///////////////////////////////
  Serial.print("Pinnumber PCF8574AP is: ");
  Serial.print(PinNumber1);
  Serial.print("  /  Pinnumber PCF8574P is: ");
  Serial.println(PinNumber2);  
  delay(100);
}


void expander1Write(byte _data ) {
  Wire.beginTransmission(expander1);
  Wire.send(_data);
  Wire.endTransmission();
}

byte expander1Read() {
  byte _data;
  Wire.requestFrom(expander1, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}
 
void expander2Write(byte _data ) {
  Wire.beginTransmission(expander2);
  Wire.send(_data);
  Wire.endTransmission();
}

byte expander2Read() {
  byte _data;
  Wire.requestFrom(expander2, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 20, 2013, 01:01 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,604 Posts
Neat. I am using two MCP23017 chips to expnad the ports on the Pi. It's the board Massey posted. Using a pair gets you 32 pins


DATA SHEET for the PCF8574 I/O port expander


Pete
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Feb 20, 2013 at 11:12 PM.
Reply With Quote
Old Feb 20, 2013, 11:13 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,604 Posts
Danny,

Are these PCBs at full size? Or do they have to be resized before using?

Pete
blutoh is offline Find More Posts by blutoh
Reply With Quote
Old Feb 21, 2013, 02:40 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
316 Posts
The PCB's are 1:1 exported from my design program. I just checked, photobucket resized them. I've exported them to PDF. I attached it to this post. Hope it works.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 21, 2013, 10:55 AM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,604 Posts
Thanks, Danny,

I can rescale as well, if necessary, using the dimensions at the top of the diagram i think.

Pete
blutoh is offline Find More Posts by blutoh
Reply With Quote
Old Feb 21, 2013, 12:43 PM
Registered User
Joined Dec 2012
117 Posts
Quote:
Originally Posted by blutoh View Post
Neat. I am using two MCP23017 chips to expnad the ports on the Pi. It's the board Massey posted. Using a pair gets you 32 pins


DATA SHEET for the PCF8574 I/O port expander


Pete
I'm a big fan of the MCP23017 chips. I use them on my Arduino-based MonsterShield halloween prop controller (see http://www.hauntsoft.com) for both input and output.
Skystream is offline Find More Posts by Skystream
Reply With Quote
Old Feb 21, 2013, 01:54 PM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,353 Posts
I'm certainly going to need these things, maybe I can make them myself, might well be cheaper.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Old Feb 21, 2013, 02:59 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,604 Posts
Josse,

Here is the data sheet. But Danny has a;rready done the hard work for a PCB using the PCF8574, why re-invent the wheel?

Pete
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Feb 21, 2013 at 03:11 PM.
Reply With Quote
Old Feb 22, 2013, 06:37 AM
Registered User
tweety777's Avatar
Vlaardingen, The Netherlands
Joined Nov 2008
1,353 Posts
Hi Pete,

I meant building them myself using Danny's design.

Greetings Josse
tweety777 is offline Find More Posts by tweety777
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Help! MikroKopter BL Cntrl vs I2c with simon k Nikhilrobologix Multirotor Electronics 3 Jan 22, 2014 06:28 AM
For Sale converter I2C-PWM ecokopter.pl Aircraft - Electric - Multirotor (FS/W) 2 Mar 28, 2013 03:28 PM
Sold Mikrokoper/ MK clone + I2c Converter kanchana Aircraft - Electric - Multirotor (FS/W) 0 Jan 25, 2013 12:47 AM
For Sale 6 18 amp I2C ESCs jihlein Aircraft - Electric - Multirotor (FS/W) 0 Jan 22, 2013 01:59 PM