Skip to content

Conversation

@Suxsem
Copy link
Contributor

@Suxsem Suxsem commented Apr 21, 2024

This PR adds a new boolean option to the relay settings: open drain.

image

When select, relay pin mode is set to OUTPUT_OPEN_DRAIN instead of normal OUTPUT.

OUTPUT_OPEN_DRAIN: an open-drain or open-collector output. HIGH (1) leaves the output in high impedance state, LOW (0) pulls the output low. Typically used with an external pull-up resistor to allow any of multiple devices to set the value low safely.

This allow driving 5v relay modules (cheap super common Arduino ones) just powering them with 5V and adding an external pull-up resistor between the module input pin and 5V, without risking the esp32 pins (that are not 5v-tolerant) and without additional level converters.

image

Fully tested

@blazoncek
Copy link
Contributor

I have exactly the same (visually) relays in daily use and never experienced any issues with normal OUTPUT setting.
What was your motive or issue to add open-drain option for the GPIO in use?

@Suxsem
Copy link
Contributor Author

Suxsem commented Apr 21, 2024

@blazoncek do you power it from 5V or 3.3V?
If 5V, mine just doesn't work with a 3.3v logic input voltage: both LOW and HIGH turns the relay on.
If 3.3V...those relays are supposed to be powered from 5V to reliably turn on. I have 5 of them and 2 of them when powered with 3.3V often bounces on-off when nudged.

Both problems are fixed when powered with 5V and controlled by a 5V logic level.

@blazoncek
Copy link
Contributor

5V.

Copy link
Contributor

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked my old notes and there was a problem with one particular relay (which I attached to pre-release prototype of Dig-Uno) that didn't work. Since then Dig-Unos include level shifter for relays as should any hardware that mixes 3.3V logic with 5V logic.

That does not mean anything though. 😄

@softhack007
Copy link
Member

When select, relay pin mode is set to OUTPUT_OPEN_DRAIN instead of normal OUTPUT.

Question: does it make sense to combine both inverted/non-inverted with open_drain? If not, then it might be better to have a drop-down with 3 options: normal/inverted/open_drain, instead of two independent checkboxes?

@dosipod
Copy link
Contributor

dosipod commented Apr 21, 2024

@Suxsem Very good ,I have a lot of those exact relays and they would only work if powered from 3.3V ( which as you
stated is not ideal ) or if a level shifter is added , tested your PR and they all work now when powered from 5V .

@blazoncek
Copy link
Contributor

Question: does it make sense to combine both inverted/non-inverted with open_drain? If not, then it might be better to have a drop-down with 3 options: normal/inverted/open_drain, instead of two independent checkboxes?

That is a very good observation!

@Suxsem
Copy link
Contributor Author

Suxsem commented Apr 21, 2024

When select, relay pin mode is set to OUTPUT_OPEN_DRAIN instead of normal OUTPUT.

Question: does it make sense to combine both inverted/non-inverted with open_drain? If not, then it might be better to have a drop-down with 3 options: normal/inverted/open_drain, instead of two independent checkboxes?

@softhack007 @blazoncek I think they should be kept separate: all 4 combinations of inverted / open drain are valid. 3.3V relay modules should not use open drain but some may have an active-low logic and others may have active-high logic. 5V relays should use the open drain option with the pull up resistor but some of them uses an NPN transistor and others a PNP one so open-drain and inverted could be useful

@Suxsem Suxsem requested a review from blazoncek April 21, 2024 18:03
Copy link
Contributor

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with changes.

<div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"><button type="button" class="sml" onclick="uploadFile('/ir.json')">Upload</button><br></div>
<a href="https://kno.wled.ge/interfaces/infrared/" target="_blank">IR info</a><br>
Relay GPIO: <input type="number" min="-1" max="48" name="RL" onchange="UI()" class="xs"> Invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#x2715;</span><br>
Relay GPIO: <input type="number" min="-1" max="48" name="RL" onchange="UI()" class="xs"> Invert <input type="checkbox" name="RM"> Open drain <input type="checkbox" name="RO"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#x2715;</span><br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the X (span) next to input field and then I'll merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blazoncek sure, done!

@dosipod
Copy link
Contributor

dosipod commented Apr 25, 2024

Something might be you could also fix if possible is the multi-relay usermod

@blazoncek blazoncek merged commit b3acc97 into wled:0_15 Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants