Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESPURNA and 8-Channel Relay Module #336

Closed
xoseperez opened this issue Dec 20, 2017 · 7 comments
Closed

ESPURNA and 8-Channel Relay Module #336

xoseperez opened this issue Dec 20, 2017 · 7 comments

Comments

@xoseperez
Copy link
Owner

Originally reported by: laurinaitis (Bitbucket: laurinaitis, GitHub: laurinaitis)


Hello Xose,
I modified ESPURNA to work with 8-Channel Relay Module. Maybe you can include this in a standard package?You can comment on unnecessary relays. It would be much more convenient to update ESPURNA.

File: hardware.h

#!arduino

// -----------------------------------------------------------------------------
// Development boards
// -----------------------------------------------------------------------------

#if defined(NODEMCU_LOLIN)

    // Info
    #define MANUFACTURER        "NODEMCU"
    #define DEVICE              "LOLIN"

    // Buttons
    #define BUTTON1_PIN         3
    #define BUTTON1_MODE        BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_RELAY       1

    // Relays
    #define RELAY1_PIN          3
    #define RELAY1_TYPE         RELAY_TYPE_NORMAL
    #define RELAY2_PIN          15
    #define RELAY2_TYPE         RELAY_TYPE_NORMAL
    #define RELAY3_PIN          13
    #define RELAY3_TYPE         RELAY_TYPE_NORMAL
    #define RELAY4_PIN          12
    #define RELAY4_TYPE         RELAY_TYPE_NORMAL
    #define RELAY5_PIN          14
    #define RELAY5_TYPE         RELAY_TYPE_NORMAL
    #define RELAY6_PIN          4
    #define RELAY6_TYPE         RELAY_TYPE_NORMAL
    #define RELAY7_PIN          5
    #define RELAY7_TYPE         RELAY_TYPE_NORMAL
    #define RELAY8_PIN          16
    #define RELAY8_TYPE         RELAY_TYPE_NORMAL
    //    #define RELAY2_TYPE         RELAY_TYPE_INVERSE

    // LEDs
    #define LED1_PIN            2
    #define LED1_PIN_INVERSE    1

#elif defined(WEMOS_D1_MINI_RELAYSHIELD)

    // Info
    #define MANUFACTURER        "WEMOS"
    #define DEVICE              "D1_MINI_RELAYSHIELD"

    // Buttons
    // No buttons on the D1 MINI alone, but defining it without adding a button doen't create problems
    #define BUTTON1_PIN         0   // Connect a pushbutton between D3 and GND,
                                    // it's the same as using a Wemos one button shield
    #define BUTTON1_MODE        BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_RELAY       1

    // Relays
    #define RELAY1_PIN          14
    #define RELAY1_TYPE         RELAY_TYPE_NORMAL
    #define RELAY2_PIN          12
    #define RELAY2_TYPE         RELAY_TYPE_NORMAL
    #define RELAY3_PIN          13
    #define RELAY3_TYPE         RELAY_TYPE_NORMAL
    #define RELAY4_PIN          15
    #define RELAY4_TYPE         RELAY_TYPE_NORMAL
    #define RELAY5_PIN          1
    #define RELAY5_TYPE         RELAY_TYPE_NORMAL
    #define RELAY6_PIN          3
    #define RELAY6_TYPE         RELAY_TYPE_NORMAL
    #define RELAY7_PIN          5
    #define RELAY7_TYPE         RELAY_TYPE_NORMAL
    #define RELAY8_PIN          4
    #define RELAY8_TYPE         RELAY_TYPE_NORMAL

    // LEDs
    #define LED1_PIN            2
    #define LED1_PIN_INVERSE    1

// -----------------------------------------------------------------------------
// Default values
// -----------------------------------------------------------------------------

#ifndef BUTTON1_RELAY
#define BUTTON1_RELAY       0
#endif
#ifndef BUTTON2_RELAY
#define BUTTON2_RELAY       0
#endif
#ifndef BUTTON3_RELAY
#define BUTTON3_RELAY       0
#endif
#ifndef BUTTON4_RELAY
#define BUTTON4_RELAY       0
#endif
#ifndef BUTTON5_RELAY
#define BUTTON5_RELAY       0
#endif
#ifndef BUTTON6_RELAY
#define BUTTON6_RELAY       0
#endif
#ifndef BUTTON7_RELAY
#define BUTTON7_RELAY       0
#endif
#ifndef BUTTON8_RELAY
#define BUTTON8_RELAY       0
#endif

#ifndef RELAY1_RESET_PIN
#define RELAY1_RESET_PIN      0
#endif
#ifndef RELAY2_RESET_PIN
#define RELAY2_RESET_PIN      0
#endif
#ifndef RELAY3_RESET_PIN
#define RELAY3_RESET_PIN      0
#endif
#ifndef RELAY4_RESET_PIN
#define RELAY4_RESET_PIN      0
#endif
#ifndef RELAY5_RESET_PIN
#define RELAY5_RESET_PIN      0
#endif
#ifndef RELAY6_RESET_PIN
#define RELAY6_RESET_PIN      0
#endif
#ifndef RELAY7_RESET_PIN
#define RELAY7_RESET_PIN      0
#endif
#ifndef RELAY8_RESET_PIN
#define RELAY8_RESET_PIN      0
#endif

#ifndef RELAY1_DELAY_ON
#define RELAY1_DELAY_ON       0
#endif
#ifndef RELAY2_DELAY_ON
#define RELAY2_DELAY_ON       0
#endif
#ifndef RELAY3_DELAY_ON
#define RELAY3_DELAY_ON       0
#endif
#ifndef RELAY4_DELAY_ON
#define RELAY4_DELAY_ON       0
#endif
#ifndef RELAY5_DELAY_ON
#define RELAY5_DELAY_ON       0
#endif
#ifndef RELAY6_DELAY_ON
#define RELAY6_DELAY_ON       0
#endif
#ifndef RELAY7_DELAY_ON
#define RELAY7_DELAY_ON       0
#endif
#ifndef RELAY8_DELAY_ON
#define RELAY8_DELAY_ON       0
#endif

#ifndef RELAY1_DELAY_OFF
#define RELAY1_DELAY_OFF      0
#endif
#ifndef RELAY2_DELAY_OFF
#define RELAY2_DELAY_OFF      0
#endif
#ifndef RELAY3_DELAY_OFF
#define RELAY3_DELAY_OFF      0
#endif
#ifndef RELAY4_DELAY_OFF
#define RELAY4_DELAY_OFF      0
#endif
#ifndef RELAY5_DELAY_OFF
#define RELAY5_DELAY_OFF      0
#endif
#ifndef RELAY6_DELAY_OFF
#define RELAY6_DELAY_OFF      0
#endif
#ifndef RELAY7_DELAY_OFF
#define RELAY7_DELAY_OFF      0
#endif
#ifndef RELAY8_DELAY_OFF
#define RELAY8_DELAY_OFF      0
#endif

#ifndef RELAY1_LED
#define RELAY1_LED          0
#endif
#ifndef RELAY2_LED
#define RELAY2_LED          0
#endif
#ifndef RELAY3_LED
#define RELAY3_LED          0
#endif
#ifndef RELAY4_LED
#define RELAY4_LED          0
#endif
#ifndef RELAY5_LED
#define RELAY5_LED          0
#endif
#ifndef RELAY6_LED
#define RELAY6_LED          0
#endif
#ifndef RELAY7_LED
#define RELAY7_LED          0
#endif
#ifndef RELAY8_LED
#define RELAY8_LED          0
#endif
// -----------------------------------------------------------------------------

File: relay.ino

  // Dummy relays for AI Light, Magic Home LED Controller, H801,
    // Sonoff Dual and Sonoff RF Bridge
    #ifdef DUMMY_RELAY_COUNT

        for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) {
            _relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL});
        }

    #else

    #ifdef RELAY1_PIN
         _relays.push_back((relay_t) { RELAY1_PIN, RELAY1_TYPE, RELAY1_RESET_PIN, RELAY1_LED, RELAY1_DELAY_ON, RELAY1_DELAY_OFF });
    #endif
    #ifdef RELAY2_PIN
        _relays.push_back((relay_t) { RELAY2_PIN, RELAY2_TYPE, RELAY2_RESET_PIN, RELAY2_LED, RELAY2_DELAY_ON, RELAY2_DELAY_OFF });
    #endif
    #ifdef RELAY3_PIN
        _relays.push_back((relay_t) { RELAY3_PIN, RELAY3_TYPE, RELAY3_RESET_PIN, RELAY3_LED, RELAY3_DELAY_ON, RELAY3_DELAY_OFF });
    #endif
    #ifdef RELAY4_PIN
        _relays.push_back((relay_t) { RELAY4_PIN, RELAY4_TYPE, RELAY4_RESET_PIN, RELAY4_LED, RELAY4_DELAY_ON, RELAY4_DELAY_OFF });
    #endif
    #ifdef RELAY5_PIN
        _relays.push_back((relay_t) { RELAY5_PIN, RELAY5_TYPE, RELAY5_RESET_PIN, RELAY5_LED, RELAY5_DELAY_ON, RELAY5_DELAY_OFF });
    #endif
    #ifdef RELAY6_PIN
        _relays.push_back((relay_t) { RELAY6_PIN, RELAY6_TYPE, RELAY6_RESET_PIN, RELAY6_LED, RELAY6_DELAY_ON, RELAY6_DELAY_OFF });
    #endif
    #ifdef RELAY7_PIN
        _relays.push_back((relay_t) { RELAY7_PIN, RELAY7_TYPE, RELAY7_RESET_PIN, RELAY7_LED, RELAY7_DELAY_ON, RELAY7_DELAY_OFF });
    #endif
    #ifdef RELAY8_PIN
        _relays.push_back((relay_t) { RELAY8_PIN, RELAY8_TYPE, RELAY8_RESET_PIN, RELAY8_LED, RELAY8_DELAY_ON, RELAY8_DELAY_OFF });
    #endif

    #endif
// -----------------------------------------------------------------------------

Also I tested MQTTgroups (Switch configuration), with 8 relays it does not work well, I do not really know where to look for a reason (I do not understand this place in your code).

Thank you very much for your excellent work!

Marius

@xoseperez
Copy link
Owner Author

Original comment by Guido Mersmann (Bitbucket: Geit_de, GitHub: Unknown):


Stupid question:

Do all relays have to be switches or pulsemode at the same time?

Even with the dual I ran into the issue that I need one in pulse mode and one in switch mode, which seems to be impossible with current espurna.

Having a 4ch or even 8ch sounds like a waste if you want just 2/2 or 4/4 switch/pulse variants and need two different devices.

Same goes for PowerOn Mode. There may be some lines to be powered on and some not. Maybe the settings on switch page should be converted in a per relay setting to boost flexibility.

@xoseperez
Copy link
Owner Author

Agree. Right now those setting apply to all relays. Let me work on it.

@xoseperez
Copy link
Owner Author

Original comment by laurinaitis (Bitbucket: laurinaitis, GitHub: laurinaitis):


I (with a friend) want to control the supply of power to the sockets with these relays (relays will control magnetic contactors).

@xoseperez
Copy link
Owner Author

I have added all the common code to use up to 8 relays (and buttons and leds), and tested the MQTT groups funtionality. But I won't add the definitions for the two standard boards. Intead I have created a generic 8CH board with all available digital pins (except those for UART and SPI). This is the definition:

#elif defined(GENERIC_8CH)

    // Info
    #define MANUFACTURER        "GENERIC"
    #define DEVICE              "8CH"

    // Relays
    #define RELAY1_PIN          0
    #define RELAY1_TYPE         RELAY_TYPE_NORMAL
    #define RELAY2_PIN          2
    #define RELAY2_TYPE         RELAY_TYPE_NORMAL
    #define RELAY3_PIN          4
    #define RELAY3_TYPE         RELAY_TYPE_NORMAL
    #define RELAY4_PIN          5
    #define RELAY4_TYPE         RELAY_TYPE_NORMAL
    #define RELAY5_PIN          12
    #define RELAY5_TYPE         RELAY_TYPE_NORMAL
    #define RELAY6_PIN          13
    #define RELAY6_TYPE         RELAY_TYPE_NORMAL
    #define RELAY7_PIN          14
    #define RELAY7_TYPE         RELAY_TYPE_NORMAL
    #define RELAY8_PIN          15
    #define RELAY8_TYPE         RELAY_TYPE_NORMAL

@xoseperez
Copy link
Owner Author

Original comment by laurinaitis (Bitbucket: laurinaitis, GitHub: laurinaitis):


thanks, now it will be much easier to update everything!!!

@xoseperez
Copy link
Owner Author

Released with 1.11.0

@xoseperez
Copy link
Owner Author

Removing milestone: 1.11.0 (automated comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant