Pr2-8 8-Channel Digital I/O with I2C and particle Photon2

I have a 8-Channel Relay board with IoT interface using a FeatherIOT and a Particle Photon2.
I am able to control the relays but need some direction connecting the PR2-8 Digital I/O and reading these ports with this Photon2 configuration.

I assume I would Use External 12VDC power with the 5VDC pullup jumper, then read my switches by looping 5VDC thru my switch and then to the terminal on the board>

I need some direction in getting the proper library located loaded to read the Digital I/O Board.

Thanks so much!!

Hi,

I don’t have a library setup for that specific board. However there are multiple MCP23008 libraries out there available. You can set all the I/O directions to inputs, then you can set the internal pull up to up and use the I/Os to read dry contact closures to ground.

I am able to run the utility that reports seeing the relay board and 8-port I/O board on ports 32 and 33.

I am trying to use the rickkus i2c library but am not having any luck figuring out how to read those inputs. Not sure what belongs in the loop() to capture the values of the inputs.

Could you give additional direction on how to proceed to read the inputs and use those results in my Photon code? I get the idea this should be easy, but I need more direction please!
Here is my current code. Thanks!!

// This #include statement was automatically added by the Particle IDE.

#include <MCP23008-RK.h>

/* Includes ------------------------------------------------------------------*/
#include “NCD8Relay.h”
#include “spark_wiring_print.h”

MCP23008 gpio(Wire,0);

SYSTEM_MODE(AUTOMATIC);
NCD8Relay relayController;
int triggerRelay(String command);

/* This function is called once at start up ----------------------------------*/
void setup()
{
Serial.begin(115200);
relayController.setAddress(0,0,0);
Spark.function(“controlRelay”, triggerRelay);

gpio.begin();
gpio.pinMode(0, INPUT);
gpio.digitalWrite(0, HIGH);
 gpio.pinMode(1, INPUT);
gpio.digitalWrite(1, HIGH);
 gpio.pinMode(2, INPUT);
gpio.digitalWrite(2, HIGH);
 gpio.pinMode(3, INPUT);
gpio.digitalWrite(3, HIGH);
 gpio.pinMode(4, INPUT);
gpio.digitalWrite(4, HIGH);
 gpio.pinMode(5, INPUT);
gpio.digitalWrite(5, HIGH);
 gpio.pinMode(6, INPUT);
gpio.digitalWrite(6, HIGH);
 gpio.pinMode(7, INPUT);
gpio.digitalWrite(7, HIGH);

}

/* This function loops forever --------------------------------------------*/
void loop()
{

// triggerRelay(“1off”);
// relayCommand(“1”,“on”);
// delay(2000);
// triggerRelay(“1off”);
// relayCommand(“1”,“off”);
// delay(2000);
}

int triggerRelay(String command){
if(command.equalsIgnoreCase(“turnonallrelays”)){
relayController.turnOnAllRelays();
return 1;
}
if(command.equalsIgnoreCase(“turnoffallrelays”)){
relayController.turnOffAllRelays();
return 1;
}
if(command.startsWith(“setBankStatus:”)){
int status = command.substring(14).toInt();
if(status < 0 || status > 255){
return 0;
}
Serial.print("Setting bank status to: ");
Serial.println(status);
relayController.setBankStatus(status);
Serial.println(“done”);
return 1;
}
//Relay Specific Command
int relayNumber = command.substring(0,1).toInt();
Serial.print(“relayNumber: “);
Serial.println(relayNumber);
String relayCommand = command.substring(1);
Serial.print(“relayCommand:”);
Serial.print(relayCommand);
Serial.println(”.”);
if(relayCommand.equalsIgnoreCase(“on”)){
Serial.println(“Turning on relay”);
relayController.turnOnRelay(relayNumber);
Serial.println(“returning”);
return 1;
}
if(relayCommand.equalsIgnoreCase(“off”)){
relayController.turnOffRelay(relayNumber);
return 1;
}
if(relayCommand.equalsIgnoreCase(“toggle”)){
relayController.toggleRelay(relayNumber);
return 1;
}
if(relayCommand.equalsIgnoreCase(“momentary”)){
relayController.turnOnRelay(relayNumber);
delay(300);
relayController.turnOffRelay(relayNumber);
return 1;
}
return 0;
}

Hi,

I would recommend posting on the Particle Community which is quite active or perhaps the Arduino Forum. These are extremely low cost devices which are not cost effective to provide support for. We do not have an active community of users here to provide support.

Thank you,
Travis