Iot: Relay device

Created on 16 May 2020  Â·  12Comments  Â·  Source: dotnet/iot

I would like to add support for some different relay boards. These devices are super simple and support for this would be to add consistency for code in projects more than anything.

This device would simply keep track of what port a relay is on, and provide methods for turning it on and off by setting that pin high and low.

image

api-suggestion untriaged

Most helpful comment

The RelayType should probably be provided in the ctor (and be read-only later).

All 12 comments

Sounds good, but make it such that the number of relay channels is configurable. There are such boards with 1, 2, 4, or even 8 channels.

I have mixed feelings on these since this will have very little logic compared to GpioController, if you guys feel like this is useful please at least add support for normally open/closed types of relays so that user doesn't have to invert the value

@kwkraus I like that idea. I would agree that there isn't much more logic than GpioController. However, it would be more readable and also easier for entry-level people to understand.

Sounds good, but make it such that the number of relay channels is configurable. There are such boards with 1, 2, 4, or even 8 channels.

So have it RelayBoard instead of Relay? That could make sense.

Perhaps something along the lines of

RelayBoard b = new RelayBoard(numberOfRelays: 6);
var r1 = b.CreateRelay(RelayType.NormallyOpen); // this could default to normally closed
r1.On = true;

but honestly not sure if it makes sense to have board at all - you can connect pins completely randomly so just Relay could be sufficient (also you might want to only connect 2 out of 4 pins if that's only relay board you got)

that would look more or less like

Relay r = new Relay(4, gpioController: ..., type: RelayType.NormallyOpen);
r.On = false;

Here is the plan for Relay:

Methods:
Relay(int pin, GpioController controller)
TurnOn()
TurnOff()
Toggle()
SetState(bool on)

Properties
bool On (get & set, calls SetState)
int Pin (get)
RelayType RelayType

And the RelayType enum:
NormallyOpen (default)
NormallyClosed

I agree RelayBoard is probably uncesessary; the only thing I could see it being useful for is setting all Relays to the same RelayType. However, I don't think it will add enough code clarity (as the Relay class will) to bother adding it.

@frogcrush generally speaking we usually don't add redundancy to the methods, so I'd recommend to either stick with property On or method SetState or similarly named. (sorry for late response, I'm currently on vacation)

The RelayType should probably be provided in the ctor (and be read-only later).

There is another relay module that is controlled via SPI using a shift register such as 74595. Does the control of this module also need to be implemented here?

There is another relay module that is controlled via SPI using a shift register such as 74595. Does the control of this module also need to be implemented here?

I guess in this case https://github.com/dotnet/iot/tree/master/src/devices/ShiftRegister would be your friend?

There is another relay module that is controlled via SPI using a shift register such as 74595. Does the control of this module also need to be implemented here?

Do you happen to have a link to info on one of these? I think support could be added for those; however, would too many separate types of devices then be covered by the one project?

And in this case, should we have an IRelay/IRelayBoard? (this _would_ help if you're using DI or unit testing...) and have GpioRelay/SpiRelay/I2cRelay/etc... I feel like there is a benefit to beginners if we did this, but...

I was too worried about the finished module. Previously found on Taobao some SPI relay design(using keyword 继电器 SPI), thought there will be a lot of such boards. However, when I searched for relay SPI on Amazon, I didn't get any results.
So these designs look more like the product of personal DIY.

But I was surprised to find that the TLE7234SE chip completely realized the function of using SPI to control the 8 relays. So I think it's a good choice to abstract relay devices into interfaces and then let developers and users implement specific models.

http://www.leomodulos.com.br/datasheets/Datasheet-Infineon-TLE-7234-SE.pdf

Was this page helpful?
0 / 5 - 0 ratings