We have launched a new Community! Please post any new forum topics there. This forum will remain available as an archive, but we hope you enjoy the new experience and feature set the latest NCD Community will offer!

Why am I getting a stack overflow error on readRelayStatus()?

I have a MCP23008 with a Particle Electron and when I uncomment the readRelayStatus() I get a red blining light on the Electron (13 blinks in between SOS)

WidgetLED relay1LED(1); // LED widget 'type' for Relay 1 (for Blynk app)

int relay1Status = 0;


void turnOffHeater(){
    
    relayController.turnOffRelay(1);
 // relay1Status = relayController.readRelayStatus(1);
    if (relay1Status == LOW) { relay1LED.off(); }
 }

I only get this error when the relay is turning from On to Off.

If I call the function when the relay is Off already, I dont get the error.

T

Hi,

Are you using a ControlEverything relay board?  It is not possible to control on board LEDs on these boards, they are directly connected to the MCP23008 IO lines that control the relays so they automatically turn on when the Relay turns on.  

If you are using our Relay Control library then the readRelayStatus function will return a 1 or a 0 depending on the state of the relay.  I would do your if check comparison against 0 rather than LOW.

Would need more information about your code to investigate further.

G

 

I'm using the NCD2Relay Library on a MCP23008 board.

I'm not trying to control the on-board LED's, I can get the relay to click and see the LED come on. I'm trying to set the state of a LED on the Blynk app. (relay1LED)

I changed the if to check for 1 and added a delay(20) thinking maybe it was asking for the status too quick after switching the relay, but I still get the error.

essentially what I'm doing is turning on a heater (Blynk app Switch) then after a Timer runs out I turn the heater off.

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
#include "NCD2Relay/NCD2Relay.h"

#define BLYNK_DEBUG       // Uncomment this to see debug prints
#define BLYNK_PRINT Serial

NCD2Relay relayController; // Relay Controller Object 

char auth[] = "auth token here";//Authorization Token for blynk

WidgetLED relay1LED(1); // widget 'type' for Relay 1
WidgetLED relay2LED(2); // widget 'type' for Relay 2

int relay1Control = 0;
int relay2Control = 0;
int relay1Status = 0; // relay 1 Status
int relay2Status = 0; // relay 2 Status 

int offDelayMinutes = 10; //Timer for Off delay on Relays

Timer offDelayTimer(10000 , turnOffHeater, true);//Off delay Timer for Heater

//SYSTEM_MODE(SEMI_AUTOMATIC);//runs Code even if there is no cell connection

//*******************************************Setup*************************************
void setup() {
    Serial.println("Setup Started");
    
    Serial.begin(9600);
    relayController.setAddress(0,0,0);// Start Relay Controller Object
    Blynk.begin(auth, IPAddress(45,55,130,102), 8442);//Start Connection to Blynk Servers

    FuelGauge fuel;//Create Battery charged object
    Serial.println( fuel.getSoC() );//Prints the battery Level in Percent
    
    Serial.println("Setup Done");
}
//*************************************Main Loop********************************************
void loop() {
    Blynk.run();// Start Blynk!
    delay(1000);  
}
//**************************************Functions************************************************


void turnOffHeater(){
    Serial.println("Turning Off heater");
    relayController.turnOffRelay(1);
    Serial.println("Ok after relay Off");
    delay(20);
    relay1Status = relayController.readRelayStatus(1);
    Serial.println("Ok after get status");
    if (relay1Status == 0) { relay1LED.off(); }
    Serial.println("Ok after set LED");
}
void turnOnHeater(){
    Serial.println("Turning On Heater");
    relayController.turnOnRelay(1);
    offDelayTimer.reset();
    relay1Status = relayController.readRelayStatus(1);
    if (relay1Status == 1) { relay1LED.on(); }
    }


 BLYNK_WRITE(V1){
    relay1Control = param.asInt();
    Serial.println(relay1Control);//print relay 1 Control
    if (relay1Control == 1){ turnOnHeater(); }
    else if (relay1Control == 0){ turnOffHeater(); }
  } 

 

G

Looks like this was a problem with how I was trying to write to Virtual Blynk Pin. Sorry.

 

T

Glad you got it working.  I could not find anything wrong with the code in relation to the relay board :)

G

Looks like I still can't get an input to show anything but 'null' in particle console or a '0' in Serial Monitor.

I used the code in this Post, but I still can't get anything out of the Board.

I've tried using a different board and diffreent electron, but I still get nothing.

what's the min and max Voltage input for the GPIO Pins?

I've been stuck on this problem for far too long.

thanks in advance for any help.

 

T

Hi,

The inputs are internally pulled high to 5VDC making them suitable for reading dry contact closures to ground.  This is good for buttons, switches, etc.  Just apply a closure between the input and one of the GND terminals and the input should read closed.

If this does not help can you post your current code?