Forum >DFR0013 IIC TO GPIO module
ArduinoGeneral

DFR0013 IIC TO GPIO module

userHead anonymous 2011-01-08 19:48:44 9430 Views2 Replies
I couldn't find any programs written for the DFR0013 IIC TO GPIO module, so I wrote this program. It simply scans the output ports.
I am only using it as an output but I included the commands for input. It works great!!
feel free to use in your projects:
Code: Select all
/******************************************************************************
Test Program for the 12C PCA9555 Board part number DFR0013 IIC TO GPIO module from dfrobot.com
16 outputs that I used to drive this relay board made in Bulgaria
http://www.denkovi.com/product/21/16-relay-board-for-your-pic-avr-project-12v.html
it's a great little expansion board that can be used to drive LEDs or anything you want.
made by [email protected]
January 07th 2011
My biggest problem was figuring out the I2C address of the PCA9555.
If there are no jumpers the address is 1 0 0 '1 1 1'
Jumpers make the address 1 0 0 '0 0 0'. This is opposite of what I expected.
******************************************************************************/
#include <Wire.h>
// with no jumpers the full address is 1 0 0 1 1 1 1 0 0 A2 A1 A0 0x27 is the default address for the DFR0013 board with no jumpers.
#define PCA9555 0x27 // 0x27 is default address for the DFR0013 board with no jumpers.
// 0x20 is address for the DFR0013 board with all jumpers.
// COMMAND BYTE TO REGISTER RELATIONSHIP FROM PCA9555 DATA SHEET
// At reset, the device's ports are inputs with a high value resistor pull-ups to VDD
// If relays turning on during power up are a problem. Add a pull down resistor to each relay transistor base.
#define IN_P0 0x00 // Read Input port0
#define IN_P1 0x01 // Read Input port1
#define OUT_P0 0x02 // Write Output port0
#define OUT_P1 0x03 // Write Output port1
#define INV_P0 0x04 // Input Port Polarity Inversion port0 if B11111111 is written input polarity is inverted
#define INV_P1 0x05 // Input Port Polarity Inversion port1 if B11111111 is written input polarity is inverted
#define CONFIG_P0 0x06 // Configuration port0 configures the direction of the I/O pins 0 is output 1 is input
#define CONFIG_P1 0x07 // Configuration port1 configures the direction of the I/O pins 0 is output 1 is input
#define PAUSE 200
void setup()
{
Wire.begin(PCA9555); // join i2c bus (address optional for master) tried to get working
write_io (CONFIG_P0, B00000000); //defines all pins on Port0 are outputs
write_io (CONFIG_P1, B00000000); //defines all pins on Port1 are outputs
write_io (OUT_P0, B00000000); //clears all relays
write_io (OUT_P1, B00000000); //clears all relays
delay (PAUSE);
}
void loop()
{
write_io (OUT_P0, B00000001);
delay (PAUSE);
write_io (OUT_P0, B00000010);
delay (PAUSE);
write_io (OUT_P0, B00000100);
delay (PAUSE);
write_io (OUT_P0, B00001000);
delay (PAUSE);
write_io (OUT_P0, B00010000);
delay (PAUSE);
write_io (OUT_P0, B00100000);
delay (PAUSE);
write_io (OUT_P0, B01000000);
delay (PAUSE);
write_io (OUT_P0, B10000000);
delay (PAUSE);
write_io (OUT_P0, B00000000);
write_io (OUT_P1, B00000001);
delay (PAUSE);
write_io (OUT_P1, B00000010);
delay (PAUSE);
write_io (OUT_P1, B00000100);
delay (PAUSE);
write_io (OUT_P1, B00001000);
delay (PAUSE);
write_io (OUT_P1, B00010000);
delay (PAUSE);
write_io (OUT_P1, B00100000);
delay (PAUSE);
write_io (OUT_P1, B01000000);
delay (PAUSE);
write_io (OUT_P1, B10000000);
delay (PAUSE);
write_io (OUT_P1, B00000000);
}
void write_io(int command, int value)
{
Wire.beginTransmission(PCA9555);
Wire.send(command),Wire.send(value);
Wire.endTransmission();
}
I updated this code after powering off the project then powering it back on, I discovered that the CONFIG lines in setup() are nescessary
2011-01-11 00:11:30 Well. Really appreciate your work. It makes the world much better and more fun. userHeadPic R2D2C3PO
2011-01-10 16:12:21 Here is another program that uses all 16 bits at a time. You don't need to worry about PORTS let the program do it.
Code: Select all
/******************************************************************************
Test Program for the 12C PCA9555 Board part number DFR0013 IIC TO GPIO module from dfrobot.com
16 outputs that I used to drive this relay board made in Bulgaria
http://www.denkovi.com/product/21/16-relay-board-for-your-pic-avr-project-12v.html
it's a great little expansion board that can be used to drive LEDs or anything you want.
made by [email protected]
January 07th 2011
My biggest problem was figuring out the I2C address of the PCA9555.
If there are no jumpers the address is 1 0 0 '1 1 1'
Jumpers make the address 1 0 0 '0 0 0'. This is opposite of what I expected.
******************************************************************************/
#include <Wire.h>
//  with no jumpers the full address is  1 0 0 1 1 1    1 0 0 A2 A1 A0  0x27 is the default address for the DFR0013 board with no jumpers.
#define PCA9555 0x27 // 0x27 is default address for the DFR0013 board with no jumpers.
                    // 0x20 is address for the DFR0013 board with all jumpers.
// COMMAND BYTE TO REGISTER RELATIONSHIP FROM PCA9555 DATA SHEET
// At reset, the device's ports are inputs with a high value resistor pull-ups to VDD
// If relays turning on during power up are a problem. Add a pull down resistor to each relay transistor base.
#define IN_P0 0x00 // Read Input port0
#define IN_P1 0x01 // Read Input port1
#define OUT_P0 0x02 // Write Output port0
#define OUT_P1 0x03 // Write Output port1
#define INV_P0 0x04 // Input Port Polarity Inversion port0 if B11111111 is written input polarity is inverted
#define INV_P1 0x05 // Input Port Polarity Inversion port1 if B11111111 is written input polarity is inverted
#define CONFIG_P0 0x06 // Configuration port0 configures the direction of the I/O pins 0 is output 1 is input
#define CONFIG_P1 0x07 // Configuration port1 configures the direction of the I/O pins 0 is output 1 is input
#define PAUSE 200
void setup()
{
  Wire.begin(PCA9555); // join i2c bus (address optional for master) tried to get working
  write_io (CONFIG_P0, B00000000); //defines all pins on Port0 are outputs
  write_io (CONFIG_P1, B00000000); //defines all pins on Port1 are outputs 
  write_io (OUT_P0, B00000000); //clears all relays
  write_io (OUT_P1, B00000000); //clears all relays
  delay (PAUSE);
}
void loop()
{
  set_relay (0b0000000000000001);
  delay (PAUSE);
  set_relay (0b0000000000000010);
  delay (PAUSE);
  set_relay (0b0000000000000100);
  delay (PAUSE);
  set_relay (0b0000000000001000);
  delay (PAUSE);
  set_relay (0b0000000000010000);
  delay (PAUSE);
  set_relay (0b0000000000100000);
  delay (PAUSE);
  set_relay (0b0000000001000000);
  delay (PAUSE);
  set_relay (0b0000000010000000);
  delay (PAUSE);
  set_relay (0b0000000100000000);
  delay (PAUSE);
  set_relay (0b0000001000000000);
  delay (PAUSE);
  set_relay (0b0000010000000000);
  delay (PAUSE);
  set_relay (0b0000100000000000);
  delay (PAUSE);
  set_relay (0b0001000000000000);
  delay (PAUSE);
  set_relay (0b0010000000000000);
  delay (PAUSE);
  set_relay (0b0100000000000000);
  delay (PAUSE);
  set_relay (0b1000000000000000);
  delay (PAUSE);
  set_relay (0b0000000000000000);
  delay (PAUSE);
  set_relay (0b1111111111111111);
  delay (PAUSE);
  set_relay (0b0000000000000000);
  delay (PAUSE);
  set_relay (0b1111111111111111);
  delay (PAUSE);
  set_relay (0b0000000000000000);
  delay (PAUSE);
}
  void set_relay (word data) //requires a word for the 16 bits
{
  write_io(OUT_P0,lowByte(data)); // send low byte
  write_io(OUT_P1,highByte(data)); // send high byte
}
  void write_io(int command, int value)
{
  Wire.beginTransmission(PCA9555);
  Wire.send(command),Wire.send(value); // send command then send value
  Wire.endTransmission();
}
userHeadPic anonymous