Tetrikus
Posts: 18
Joined: Tue Apr 05, 2016 5:42 am

Switch bipolar relais with MCP23107

Sat Aug 11, 2018 5:59 am

Hi there
I try to switch some bipolar 3V Relais with outputs from a MCP23017. Unfortunately it does not work so far. I've connected Pins 0/1 and 2/3 and 4/5 and 6/7 to the relais, but they never switch.

If I send a

Code: Select all

i2cset -y 1 0x20 0x14 0xaa
to the device, and verify with a

Code: Select all

i2cget
, everything seems fine, but when I measure the voltage with my multimeter, I do only have around 1.5V between Pins 0/1. The idea is actually to set 0 to high(3V) and 1 to low(GND) to switch the Relay ON and vice versa to switch it OFF. Is that just not possible or do I something wrong (which is my guess).

Thanks for any hint!

B.Goode
Posts: 6192
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Switch bipolar relais with MCP23107

Sat Aug 11, 2018 9:36 am

Assuming that your references here are to pins on the mcp23017 port expander, I would expect a connection to a gpio pin to be 'paired' with a return connection to the ground of the mcp23017, not to another gpio pin.

Similarly when measuring potential difference: doesn't a valid measurement need to be between the 'supply' (a gpio pin) and the 'ground'?

Tetrikus
Posts: 18
Joined: Tue Apr 05, 2016 5:42 am

Re: Switch bipolar relais with MCP23107

Sat Aug 11, 2018 10:51 am

Yes, sorry, I talk abou the MCP pins. Since these are bipolar relais, I have to power them with 3V to turn on and with -3V to turn them off. That's why I need the two pins and that's why I measured the voltage between the pins. But even if I measure to GND, i have around 1.5V.

Brandon92
Posts: 133
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Switch bipolar relais with MCP23107

Sat Aug 11, 2018 11:25 am

Do you have a datasheet from the relay.
When I look at the datasheet (page 4). Then the worst case you can expect between two pins of the mcp: 3.3-0.7-0.6 = 2V. So, is this voltage enough to turn you relais on?
Tetrikus wrote: But even if I measure to GND, i have around 1.5V.
Where did you connect the other probe to?

User avatar
DougieLawson
Posts: 33334
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Switch bipolar relais with MCP23107

Sat Aug 11, 2018 1:56 pm

Have you set register 0x00 & 0x01 the iodira/iodirb registers default to all input.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Tetrikus
Posts: 18
Joined: Tue Apr 05, 2016 5:42 am

Re: Switch bipolar relais with MCP23107

Sat Aug 11, 2018 2:36 pm

Brandon92 wrote:
Sat Aug 11, 2018 11:25 am
Do you have a datasheet from the relay.
Where did you connect the other probe to?
Here is the datasheet of the relay: https://www.distrelec.ch/Web/Downloads/ ... _en_dk.pdf I'm not completely sure, what's the minimum voltage to switch.
I've connected the other probe to a pin from the MCP
DougieLawson wrote:
Sat Aug 11, 2018 1:56 pm
Have you set register 0x00 & 0x01 the iodira/iodirb registers default to all input.
No, I've set them to all outputs.

Brandon92
Posts: 133
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Switch bipolar relais with MCP23107

Sat Aug 11, 2018 10:15 pm

Tetrikus wrote:
Sat Aug 11, 2018 2:36 pm

Here is the datasheet of the relay: https://www.distrelec.ch/Web/Downloads/ ... _en_dk.pdf I'm not completely sure, what's the minimum voltage to switch.
I've connected the other probe to a pin from the MCP
Thanks for providing the datasheet. But, this datasheet is for more than one device. However, the 3.3v latch relay will consume between the 33mA and 66 mA depending on the type.
But your MCP* can only deliver 25mA. This means that your relay can't get enough power to turn on.

Tetrikus
Posts: 18
Joined: Tue Apr 05, 2016 5:42 am

Re: Switch bipolar relais with MCP23107

Sun Aug 12, 2018 1:38 pm

Oh, thanks for pointing that out. So I guess I will switch back to regular GPIO pins and use the Expander for simple buttons and so. Sorry I didn't notice that myself in the datasheets. :(

Brandon92
Posts: 133
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Switch bipolar relais with MCP23107

Sun Aug 12, 2018 2:38 pm

Tetrikus wrote:
Sun Aug 12, 2018 1:38 pm
Oh, thanks for pointing that out. So I guess I will switch back to regular GPIO pins and use the Expander for simple buttons and so. Sorry I didn't notice that myself in the datasheets. :(
The pi can't also deliver that kind of power. Its even less than the mcp*. You need a buffer to the output of the mcp* or pi.

Edit
What is the exact type of relais that you use. Its written on the top of your relais.

Tetrikus
Posts: 18
Joined: Tue Apr 05, 2016 5:42 am

Re: Switch bipolar relais with MCP23107

Mon Aug 13, 2018 8:07 am

Thanks for the response. I do have some of them wired to GPIO and some to the MCP*. The switching via GPIO does work very reliable and I never had issues so far. 🤔

I do have a couple of DK1A-L-3V-F relais.

Brandon92
Posts: 133
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Switch bipolar relais with MCP23107

Mon Aug 13, 2018 8:41 am

Ehm okay. The current that the required to enable your relay is 33.3mA and with a minimum voltage of (3*0.7) 2.1V. But you pi "hate" switching inductive loads and those spikes can and will kill you gpio pin in the long term, or almost directly. And beside that, you gpio can only deliver between the 8mA-16mA. (If you use two gpio port, its still the same maximum current).

The other possibility is that you are connection to much load to you 3.3V rail. How much the exact current in that you cant draw from the 3.3V line is, I don't know. But I read somewhere that it's 80mA.
joan wrote:
Wed Mar 06, 2013 9:31 am
Goolschen wrote:I'm trying to use a relay (http://www.conrad-uk.com/ce/en/product/ ... NO-SPST-NO) to switch a circuit via a gpio pin.
While switching the relay with the current from the 3v pin just works fine it does not work when setting any other gpio pin (e.g.: #4) to High.
When setting the pin to HIGH the typical "clicking" noise from the realay can be heard but more quietly compared to the noise the relay makes when connecting to the 3v pin.

I think it is not the amount of current the gpio pin delivers as my voltmeter says it has the same current as the 3v pin (approx 3.35v).
Does anybody know why this is happening?
The 3V rail pin can deliver about 80mA of current. If you try drawing that much from a gpio you are likely to burn it out.

You shouldn't drive a relay directly from a gpio. The collapsing back voltage may destroy the gpio/Pi.

Use a IC such as a ULN2003A (or its equivalent in discrete components) to safely drive the relay from a Pi.

Tetrikus
Posts: 18
Joined: Tue Apr 05, 2016 5:42 am

Re: Switch bipolar relais with MCP23107

Mon Aug 13, 2018 9:29 am

Okay, thanks. I have to re-engineer that. :) I guess it's still working because the relais are bipolar and the current is drawn only a very short time, until the relais has switched. And since I don't switch multiple relais at the very exact same time, the maximum current over all GPIO is not an issue so far as well. So I guess I had a good portion of luck. I switched the relais many times (at least 100 times) in a short amount of time and I never had issues so far.
But of course, I want to build a stable build and will read a bit about the mentioned ICs.

Brandon92
Posts: 133
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Switch bipolar relais with MCP23107

Mon Aug 13, 2018 9:53 am

Tetrikus wrote: But of course, I want to build a stable build and will read a bit about the mentioned ICs.
Unfortunately, this IC will not help you. I can give you a example how you could drive it, if you want. Or you could research by your self first.

Also take a close look to the "REFERENCE DATA" in the datasheet. If you don't switch you relay to fast and you use the correct amount of current though the contact of you relay, (minimum <-> maximum). For example:
Datasheet - Conditions wrote:Max. operating speed (at rated load) 20 times/min.

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: Tetrikus and 8 guests