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

Optocouplers problem #13

Closed
mallendeo opened this issue Apr 29, 2020 · 28 comments
Closed

Optocouplers problem #13

mallendeo opened this issue Apr 29, 2020 · 28 comments
Assignees
Labels

Comments

@mallendeo
Copy link
Contributor

mallendeo commented Apr 29, 2020

Hi, the optocoupler I bought isn't working for some reason, so I'm using this relay instead.

The problem I have, is that the logic needs to be inverted for this relay to work, otherwise it will initialized with the "on" state and the PC won't be able to start. Inverting the logic at the relay as "normally open" will work only if the rpi is on.

For the moment I am manually editing the set_output and write methods on
/usr/lib/python3.8/site-packages/kvmd/gpio.py for this to work.

We could use an ENV variable, like GPIO_INVERT_WRITE and GPIO_INVERT_READ.

@mallendeo mallendeo changed the title Option for inverting GPIO relay logic Option for inverting GPIO logic Apr 29, 2020
@mdevaev
Copy link
Member

mdevaev commented Apr 29, 2020

Inverting the logic at the relay as "normally open" will work only if the rpi is on.

I didn't understand the problem. You need to have the relay normally open by default to simulate pressing a button. I didn't understand the problem. You need to have the relay normally open by default to simulate pressing a button. Your relay has a normally open channel, why not use it?

@mallendeo
Copy link
Contributor Author

mallendeo commented Apr 29, 2020

Sorry, my bad. It's actually normally open. When kvmd starts, the relay is closed without inverting the logic.

For my case I had to change

def set_output(pin: int, initial: bool=True) -> int: # <-- True
    assert pin >= 0, pin
    GPIO.setup(pin, GPIO.OUT, initial=initial)
    return pin

def write(pin: int, flag: bool) -> None:
    assert pin >= 0, pin
    GPIO.output(pin, not flag) # <-- not

@mdevaev
Copy link
Member

mdevaev commented Apr 30, 2020

What is the status of the relay before starting kvmd? Starting kvmd immediately changes the relay state from open to closed?

@mallendeo
Copy link
Contributor Author

Before starting kvmd it's off (open), and yes, it immediately changes to closed once the rpi has booted.
With the change above, it keeps its initial state after boot.

@mdevaev
Copy link
Member

mdevaev commented Apr 30, 2020

Ah, I see. Your relay is controlled by zero level. This means that in any uncertain situation, it can close and unexpectedly turn off / turn on your server. I strongly do not recommend using this module. If you are determined to use this particular relay, I will add an option for you. But this is a big source of problems.

@mdevaev mdevaev self-assigned this Apr 30, 2020
@mdevaev mdevaev added the type:feature New feature or request label Apr 30, 2020
@mallendeo
Copy link
Contributor Author

I'm using it only because I didn't have any luck trying with an optocoupler or the 817 module (rpi gpio output is 3.3v and the 817 module requires 5v).

The relay has been working well for now, although thinking about it again, if this option does not makes any sense for the project or makes the code harder to reason about, I wouldn't worry (since this is a workaround for my use case). Thanks anyway for your time! :)

@mdevaev
Copy link
Member

mdevaev commented May 1, 2020

Relay modules for 5V should work well. Give me a link to your module, and I will see what the problem is with my hardware engineer comrade. Also show which optocouplers you use.

@mdevaev
Copy link
Member

mdevaev commented May 1, 2020

Adding this feature is not very difficult, but I would prefer to help you with your problem rather than treat its symptoms :)

@mallendeo
Copy link
Contributor Author

mallendeo commented May 1, 2020

Thank you. I really appreciate this!

These are the ones I tried first

Then I bought this board

It lights up a little, but it doesn't have enough power to fully activate the sensor with 3.3v.

@mdevaev
Copy link
Member

mdevaev commented May 1, 2020

Okay, here's the thing. Your optocouplers are based on transistors. The module you bought uses the same optocouplers that you tried initially. Polarity is also very important for them. Now you have these options:

  1. You may buy optocouplers OMRON G3VM-61A1 as recommended by our instruction. This is not too expensive and we have selected these parts according to their characteristics so that they work well with RPi.
  2. You can also try to modify the mechanical relay module so that it is controlled by a non-zero signal. This will require some soldering and will deprive the module of its factory beauty, but it should work.

In any case, I suggest you go to our discord, where we will help you faster: https://discord.gg/bpmXfz5

@mallendeo
Copy link
Contributor Author

mallendeo commented May 5, 2020

Sorry for the late response.

You may buy optocouplers OMRON G3VM-61A1 as recommended by our instruction.

Awesome!, because I ordered two ten of them a month ago, they seem stuck at customs though :p

Can I just replace the optocouplers with the ones in the 817 module and use the same circuit? (at least for the switches)

@mdevaev
Copy link
Member

mdevaev commented May 5, 2020

No, I told you. They use the same optocouplers that you've tried before. Look at the markings on their body.

@mallendeo
Copy link
Contributor Author

mallendeo commented May 5, 2020

No no, I meant these hahaha

image

They haven't arrived yet though :(

@mdevaev
Copy link
Member

mdevaev commented May 5, 2020

Sorry. Yes, it will work.

@mdevaev mdevaev changed the title Option for inverting GPIO logic Optocouplers problem May 7, 2020
@mdevaev mdevaev added type:question User question and removed type:feature New feature or request labels May 7, 2020
@mdevaev
Copy link
Member

mdevaev commented May 12, 2020

I added information to the documentation that you need to use normal relays. I think this issue can be considered resolved.

@mallendeo
Copy link
Contributor Author

Just wanted to say thank you so much! The optocouplers finally arrived and it's working now, I couldn't make it to work with the existing PCB so I put a 330 Ohm resistor and it worked flawlessly.

@mdevaev
Copy link
Member

mdevaev commented May 21, 2020

Cool!

@myself248
Copy link

Not sure where else to put this, but in every motherboard I've looked at, there's no need for optocouplers. Barely even a transistor, but transistors are pennies. The Power and Reset signals are floating, and their respective pushbuttons just ground them. Since the Raspberry Pi shares a ground with the PC being controlled, these can be tied directly to GPIO. I demonstrate it here:

https://www.youtube.com/watch?v=eXzK3U6huwY

The gate charge of those FETs is only a few pF so a gate resistor isn't even needed. Doesn't get much simpler. (Arguably it does, if you had 5v-tolerant GPIO like certain knockoff boards...)

@mdevaev
Copy link
Member

mdevaev commented Aug 24, 2020

@myself248 The relays are used for galvanic isolation in case the KVM and server are connected to different power outlets. And if you mix up the poles, you can ruin something on both the motherboard and the Pi. You can use this method if you have checked everything carefully, but remember that this way you lose additional protection from errors. And you can manage something non-standard, not quite ATX. In any case, not using the relay is a great way to see the magic smoke.

@HotelMoted
Copy link

@mdevaev just to double check, i've been using optocouplers (PC817 are really common on aliexpress) for a project a while back and it seemed to work fine and what I do is wire them like the attached picture, just wanted to double check if there's any downsides to using this setup...? the reason I do it this way is so I don't need to check for polarity at all
schem

@mdevaev
Copy link
Member

mdevaev commented Oct 23, 2020

@somuchtyler this circuit should work fine, but you need to hang a separate resistor on each anode to limit the current. The value of the resistor must be calculated based on the characteristics of the optocoupler.

@HotelMoted
Copy link

@mdevaev good catch, I did forgot to put in resistors before each of the anodes in my picture. If doing 3.3V logic with a typical forward voltage of 1.2V and a max current of 50mA. If wanting to stay under that at say at 20mA, it would be 105ohms right?
(3.3-1.2)/0.020=105ohms

@mdevaev
Copy link
Member

mdevaev commented Oct 23, 2020

@somuchtyler yep. 120 ohm is standard value. You can usse it I guess.

@atesin
Copy link

atesin commented Nov 14, 2020

hi ... sorry i didnt read completely, but working with arduino i also had some troubles with these chinese relays, too bad they are poorly documented anyway (at least en english)

searching a lot i discovered the correct way to use it .... the mechanical module (the blue little box) is a coil relay with 12v sensitivity, so to get work with 5 or less volt were made with optocopulers in the middle, so you have to feed the optocopulers with a little voltage (5v-2.5v?) and the coil relays with 9v-12v isolated

but the relays module comes by default with these 2 circuits shorted with a jumper, thats because 5v inputs are not enough to trigger the relays (or unpredictable)... so you have to remove the jumper and feed with 12v apart to get the module work properly... read the coil relay and the optocopupler specs to know the optimal voltages

      ---------                             
     | 220v ac |------------------------------, 
     |         |-------------------,          |
      ---------                     |  loads  |
                      ----------    |    |    |
                     |          |   |    v    |
       --------      |        k1|---          |
      | 12v dc |-----|gnd       |---|---(@)--- 
      |        |-----|jd-vcc    |   |         |
       --------      |        k2|---          |
                    ,|vcc       |---|---(@)--- 
                   /,|gnd       |   |         |
 --------------   //,|in1     k3|---          |
|              | /// |in2       |---|---(@)--- 
|            5v|'//  |in3       |   |         |
| arduino   gnd|'/   |in4     k4|--'          |
|          d1-4|'    |          |-------(@)--'
|              |      ----------            
 -------------- 

@DocJr90
Copy link

DocJr90 commented Jan 12, 2024

@mdevaev It appears the G3VM-61A1 has been EOL'ed. Any suggestions on a specific replacement? I'm currently searching through Omron's products but the naming scheme isn't particularly obvious and/or helpful to a novice.

@DocJr90
Copy link

DocJr90 commented Jan 12, 2024

@mdevaev Finally found it after manually navigating Omron's website and locating the datasheet instead of looking for discontinuation notices. Mouser also wasn't immediately helpful due to the generic label ("Solid State Relays - PCB Mount MOS-FET RELAY"). The recommended part number that appears equivalent for new designs is: G3VM-61AY1

@mdevaev
Copy link
Member

mdevaev commented Jan 12, 2024

Added to the list, thank you

@HotelMoted
Copy link

I've been using 2x PC817 per power switch for years now and never had a problem across dozens servers.

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

No branches or pull requests

6 participants