I am using an NCD Relay board with a Photon2 plugged in via the NCD Feather to IOT. I can turn all of the relays on and off.
I also have attached the NCD PR2-8 8-channel Digital I/O IoT.
When I run the NCD sample to scan the I2C, I see the address of my two devices as 32 and 33.
I want to set all 8 to be Inputs with pull ups. I need to connect manual switches between the input pins and ground so I can read them and see when they are on.
I suppose this should be easy, but I am not having any success reading those inputs and would appreciate some direction on how to go about this. I am including the code I have pasted into the Photon2 so you can see just where I am at with this. Most grateful for any help with this!!
// 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;
}