Author Topic: Going from GPIO to relays  (Read 5203 times)

0 Members and 1 Guest are viewing this topic.

Offline rthorntnTopic starter

  • Frequent Contributor
  • **
  • Posts: 506
  • Country: au
Going from GPIO to relays
« on: May 04, 2020, 04:20:54 am »
tl:dr what IC's do I use to configure six DPDT using eight GPIO's.

Hi All,

I'm still a newbie after all this time, I'm sure this is a very basic question but I'm not sure how to find the answer.

Where am I going with this, lets say I want to build a networked R2R volume control (can we please avoid any sound quality discussions).

Say I want to have 128 volume levels, I want to be able to set and query the volume level over the network.

I have an Espressif ESP32-ETHERNET-KIT, let's use that.  Let's say it has eight GPIOs and not much else.

So I want to control all possible combinations of six DPDT (G6K-2F-Y) relays.

I'm thinking I use the GPIO's in parallel, 7 of them to get 128 and 1 GPIO to go high on data ready, stupid?

What do I put in between the GPIO and the relays, a similar volume circuit (relaixedPassive http://www.vaneijndhoven.net/jos/relaixedpassive/) has a PIC18F connected by i2c to an MCP23017 which is connected to a DRV777 and then the relays but I don't have i2c and they are controlling input selection with the MCP23017 also?

I probably want to use ESPHome (hence the ESP32) that allows you to easily set GPIO's over the network and integrate into HASS automation.

Thanks for looking.

Cheers
Richard


« Last Edit: May 04, 2020, 04:22:52 am by rthorntn »
 

Offline radar_macgyver

  • Frequent Contributor
  • **
  • Posts: 777
  • Country: us
Re: Going from GPIO to relays
« Reply #1 on: May 04, 2020, 04:28:12 am »
How about a ULN2003 or similar? It also includes the catch diodes.
 
The following users thanked this post: rthorntn

Offline jackthomson43

  • Contributor
  • Posts: 38
  • Country: us
Re: Going from GPIO to relays
« Reply #2 on: May 04, 2020, 04:38:15 am »
You can use shift registers like 74HC595, it works on serial in and parallel out protocol. Moreover, you can also attach multiple shift registers in parallel so can easily control 128 outputs using 3 pins.
« Last Edit: March 04, 2021, 03:48:19 pm by jackthomson43 »
 
The following users thanked this post: rthorntn

Offline awallin

  • Frequent Contributor
  • **
  • Posts: 694
Re: Going from GPIO to relays
« Reply #3 on: May 04, 2020, 04:39:44 am »
I've used a 16-output SPI IO-expander (MCP13S17T) driving ULN2803a for TE HF3 relays over here:
https://www.ohwr.org/project/rf-mux-8ch/uploads/5241386edf0df7bb423b737b56b15a73/rf-mux-8ch_2018.03_Schematic.pdf
The relay you mentioned G6K-2F-Y seems to require less current, so ULN2803a should be fine.

https://www.microchip.com/wwwproducts/en/MCP23S17
http://www.ti.com/lit/ds/symlink/uln2803a.pdf

Even if you don't have hardware SPI-outputs on your uC it is fairly easy to 'bit-bang' SPI on any three GPIO pins.
There should be plenty of libraries for this on arduino or PIC out there.
 
The following users thanked this post: rthorntn

Offline rthorntnTopic starter

  • Frequent Contributor
  • **
  • Posts: 506
  • Country: au
Re: Going from GPIO to relays
« Reply #4 on: May 04, 2020, 05:39:27 am »
Thanks everyone, what a great bunch you all are!

So this is the relay circuit, VLx comes from an output on the DRV777:

983828-0

The audio signal goes from bottom to top through multiple potential paths through different resistors, giving you different volumes (stereo, with left channel on the left and right channel on the right).

How would the relays be set if you wanted full volume?

Say we chose the ULN2803a, I just need one for six DPDT relays then?

I guess in the circuit I'm confused about the relay's "states" in the diagram, it only has two?

So I look at K209:

983824-1

It has the G6K-2F-Y

What's the symbol between VL2 and +5V on pins 1 & 8 on the relay, a diode?

Pins 2-7 on the relay are the DPDT, what is the schematic showing for K209 the L/R going through 47K resistors, is this low, basically how do the electrons flow through R207, R208, R220 & R221:

 - If VL2 GPIO is low
 - If VL2 GPIO is high

As you can tell I'm not great at reading schematics.  I'm figuring it out as I go along:

We are going through the resistors in parallel?:

220K
100K
47K
18K
5k6
820R
27K always

So we add all of those resistance values together.

Is there an "open-source" or "free for hobby use" way to see the circuit as an animation, so I can understand it?

Thanks.
Richard

 

Offline rthorntnTopic starter

  • Frequent Contributor
  • **
  • Posts: 506
  • Country: au
Re: Going from GPIO to relays
« Reply #5 on: May 04, 2020, 08:48:11 am »
Thanks all, just wondering now, a board I like has 200mA @ 5V free for additional circuits, trying to figure out if the ULN2803A plus six G6K relays needs more than 200mA @ 5V, looking at the respective datasheets isn't making it any clearer haha?
 

Offline rthorntnTopic starter

  • Frequent Contributor
  • **
  • Posts: 506
  • Country: au
Re: Going from GPIO to relays
« Reply #6 on: May 04, 2020, 09:40:58 am »
Polarised relays use the magnetic flux of the permanent magnet in their electromagnetic sections, I think this answers my "what's the symbol between VL2 and +5V on pins 1 & 8 on the relay"

I have 1W (200mA * 5V) budget.

Do the relays each use 100mW (33mA * 3V), so six relays would use 600mA and the ULN2803A dissipation doesn't really factor in because it's just "amplifying" the current to what the relays are drawing (600mA)?



« Last Edit: May 04, 2020, 10:07:12 am by rthorntn »
 

Offline Back2Volts

  • Supporter
  • ****
  • Posts: 495
  • Country: us
Re: Going from GPIO to relays
« Reply #7 on: May 04, 2020, 08:26:31 pm »
tl:dr what IC's do I use to configure six DPDT using eight GPIO's.

Hi All,

I'm still a newbie after all this time, I'm sure this is a very basic question but I'm not sure how to find the answer.

Where am I going with this, lets say I want to build a networked R2R volume control (can we please avoid any sound quality discussions).

Say I want to have 128 volume levels, I want to be able to set and query the volume level over the network.

I have an Espressif ESP32-ETHERNET-KIT, let's use that.  Let's say it has eight GPIOs and not much else.

So I want to control all possible combinations of six DPDT (G6K-2F-Y) relays.

I'm thinking I use the GPIO's in parallel, 7 of them to get 128 and 1 GPIO to go high on data ready, stupid?

What do I put in between the GPIO and the relays, a similar volume circuit (relaixedPassive http://www.vaneijndhoven.net/jos/relaixedpassive/) has a PIC18F connected by i2c to an MCP23017 which is connected to a DRV777 and then the relays but I don't have i2c and they are controlling input selection with the MCP23017 also?

I probably want to use ESPHome (hence the ESP32) that allows you to easily set GPIO's over the network and integrate into HASS automation.

Thanks for looking.

Cheers
Richard

I wonder if a digital potentiometer would be a possibility.
 
The following users thanked this post: rthorntn

Offline themadhippy

  • Super Contributor
  • ***
  • Posts: 4587
  • Country: gb
Re: Going from GPIO to relays
« Reply #8 on: May 04, 2020, 10:19:34 pm »
Quote
What's the symbol between VL2 and +5V on pins 1 & 8 on the relay, a diode?
all i can see is a rectangle with a line through it, thats the relay coil
 
The following users thanked this post: rthorntn

Offline rthorntnTopic starter

  • Frequent Contributor
  • **
  • Posts: 506
  • Country: au
Re: Going from GPIO to relays
« Reply #9 on: May 04, 2020, 10:31:13 pm »
I figured it out in my 4th post...

Polarised relays use the magnetic flux of the permanent magnet in their electromagnetic sections, I think this answers my "what's the symbol between VL2 and +5V on pins 1 & 8 on the relay"
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21608
  • Country: us
Re: Going from GPIO to relays
« Reply #10 on: May 05, 2020, 04:41:08 am »
There's also the TPIC595, it's similar to the 74HC595 except it can switch 150mA per output at up to 50V.
 
The following users thanked this post: rthorntn

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2410
  • Country: ca
Re: Going from GPIO to relays
« Reply #11 on: May 14, 2020, 01:50:05 pm »
I figured it out in my 4th post...

Polarised relays use the magnetic flux of the permanent magnet in their electromagnetic sections, I think this answers my "what's the symbol between VL2 and +5V on pins 1 & 8 on the relay"
Not exactly. A typical relay has no permanent magnet at all. When energized, the magnetic force from the coil pulls the contact one way, and when not energized, a spring action pushes it back the other way. A polarized latching relay does use a permanent magnet. A latching relay "latches" into place and does not need to be constantly powered. Most relays are not latching, and require constant power to the coil in order to close the "normally open" contacts.

The circuit uses DPDT relays. DP is Dual Pole, and means two separate sets of contacts, in this case these are used for the two (stereo) audio signals. DT is Dual Throw and this means that (for each Pole) the relay connects a "common" pin to one contact when idle and to another when energized. So instead of being "on-off", it is "on-on". The schematic symbol is illustrative of function. The triangles on pin 2, 4, 5, and 7 are contacts. The bendy line on pin 3 and 6 is the armature which physically moves toward the coil when you energize the relay. It is illustrated as floating between the two contacts, but actually, it is touching on or the other. When the relay coil is not energized, pin 2 is open/floating (not connected) and pin 3 is connected to pin 4, which is the "normally closed" or NC contact. When energized, the coil (illustrated between pin 1 and 8 ) physically pulls the switch armature away from the NC contact, and toward the NO (normally open) one, on pin 2. Then pin 3 and pin 2 are connected, and pin 4 is open/floating. When you remove power from the coil, it snaps back to connect pin 3 and pin 4 once again. The same thing happens at the same time on pins 5,6,7 on the other side (the other "pole" in the dual-pole relay). If you want to visualize the full path, use a paint program to trace the path through each relay when on or off. Example attached.

Note that with a 6-relay attenuator as pictured, you get 2^6 = 64 steps, not 128 steps.

The ULN2003 suggested above is a good choice to drive the relays. You need only 6 pins from your microcontroller, one for each relay.
 
The following users thanked this post: rthorntn

Online Jeroen3

  • Super Contributor
  • ***
  • Posts: 4607
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Going from GPIO to relays
« Reply #12 on: May 14, 2020, 02:26:00 pm »
You can also use deserializers on spi or i2c. Either directly with power capability like an TLE75008-ESD. Or just use discretes after a SN74LV595APWR or the likes.
 
The following users thanked this post: rthorntn

Offline themadhippy

  • Super Contributor
  • ***
  • Posts: 4587
  • Country: gb
Re: Going from GPIO to relays
« Reply #13 on: May 14, 2020, 03:27:26 pm »
Quote
Is there an "open-source" or "free for hobby use" way to see the circuit as an animation, so I can understand it?

http://www.falstad.com/circuit/circuitjs.html
 
The following users thanked this post: rthorntn

Offline Scrts

  • Frequent Contributor
  • **
  • Posts: 803
  • Country: lt
Re: Going from GPIO to relays
« Reply #14 on: May 14, 2020, 09:01:14 pm »
How about using a shift register? Just use 2 GPIOs. One toggles as a 'clock' another sets outputs as 'data'. Search for "shift register & relay".
 
The following users thanked this post: rthorntn

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2860
  • Country: nz
Re: Going from GPIO to relays
« Reply #15 on: May 15, 2020, 08:05:59 am »
If I was wanting to do something like this, I would mount an RC servo mechanically connected to a potentiometer, acting actimg as a volume control.

Clocking relays to change volumes seems like a terrible idea, due to clicks, pops and thumps as relays  open and close.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 
The following users thanked this post: rthorntn

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2499
  • Country: us
  • Yes, I do this for a living
Re: Going from GPIO to relays
« Reply #16 on: May 16, 2020, 06:33:36 am »
If I was wanting to do something like this, I would mount an RC servo mechanically connected to a potentiometer, acting actimg as a volume control.

Clocking relays to change volumes seems like a terrible idea, due to clicks, pops and thumps as relays  open and close.

Some very high-dollar audio gear (like the Dangerous Monitor) uses relays to change the volume of studio monitors.* They match resistors in the ladders so that gain changes between steps are "exact" values (to some precision) and more importantly so that gain steps for each channel are identical. Channel-to-channel matching is the critical parameter.

A DC blocking cap is used to get mitigate the pops and thumps, possibly with zero-crossing detection to make sure switching happens when they occur. They have to worry about unequal relay turn-on and turn-off times and ensure that the network is always rationally connected, so it doesn't go to full output briefly.

I've heard the Dangerous in a very well done mastering studio (the quietest room I've been in that wasn't an anechoic chamber) and with the switching module buried in the equipment rack (it's driven by a desktop remote) you can't hear the relays clicking. And it doesn't click or pop when you change the volume level.

Whether you need a $2,000 monitor controller depends on your needs. I did up a monitor controller based on four PGA2320s and it works well enough for my use.

* To be clear, the Dangerous operates at line level, and its outputs feed the monitor amplifiers. It doesn't attenuate at speaker level.
 
The following users thanked this post: rthorntn, ajb, I wanted a rude username

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21608
  • Country: us
Re: Going from GPIO to relays
« Reply #17 on: May 17, 2020, 03:46:23 am »
It's not entirely outlandish audiophool territory to do such a thing. It's actually a bit shocking how terrible the tolerances are on typical potentiometers. An audio taper pot is supposedly logarithmic but if you actually graph the resistance through the full rotation it's only a vague approximation of a logarithmic curve and in the case of a double gang pot for stereo audio the two sides may not be all that well matched. Most people are probably never going to notice, but if you're dealing with signals in a recording studio you want everything to be well matched.
 
The following users thanked this post: rthorntn

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2867
  • Country: us
Re: Going from GPIO to relays
« Reply #18 on: May 17, 2020, 05:58:26 am »
Some very high-dollar audio gear (like the Dangerous Monitor) uses relays to change the volume of studio monitors.* They match resistors in the ladders so that gain changes between steps are "exact" values (to some precision) and more importantly so that gain steps for each channel are identical. Channel-to-channel matching is the critical parameter.

I fixed a couple of monitors for a friend recently and noticed the level adjustments on the back had detents, I assumed they were detented pots which I thought was strange, but them actually being rotary switches for better channel-to-channel matching makes a lot more sense.  Thanks for the info!
 
The following users thanked this post: rthorntn

Offline Ground_Loop

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: us
Re: Going from GPIO to relays
« Reply #19 on: May 26, 2020, 01:30:05 am »
I figured it out in my 4th post...

Polarised relays use the magnetic flux of the permanent magnet in their electromagnetic sections, I think this answers my "what's the symbol between VL2 and +5V on pins 1 & 8 on the relay"

Sometimes they are polarized because they have a LED indicator or diode supressor. I’ve never seen a relay with any type of perm magnet.
There's no point getting old if you don't have stories.
 
The following users thanked this post: rthorntn


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->