Page 1 of 1

Wemos D1 mini - which GPIO ports for relays?

Posted: 12 Nov 2021, 10:54
by sawo
Hi all,
I hope you can help me with my current issue.
I need to connect 2 more relays to my wemos d1 mini runnig espeasy.
The only GPIO ports which are free / not used are GPIO 0/1/2/3/15
Which ones would you use to connect a relays?

thx
sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 12 Nov 2021, 11:00
by dynamicdave
Have a look at this excellent document.

https://randomnerdtutorials.com/esp8266 ... nce-gpios/

It also depends how you are driving the relay.
I suspect you are using a transistor driven from a D-pin.
You have to be mindful of what happens to certain pins during boot-up.
This is because you can stop the Wemos from booting-up if you "pull" a pin the wrong way.
Read the above document as it explains it all.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 12 Nov 2021, 11:53
by sawo
Hi dynamicdave,
thanks for your answer, so in this case I think I will use a seperate wemos to controll the relays.
Thanks
sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 12 Nov 2021, 14:29
by dynamicdave
No idea what you are using the other pins for - but if you have I2C running on them you could consider the PCF8574A I2C Port Expander.
Probaly not a lot of difference in cost between this chip and a Wemos D1 Mini.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 12 Nov 2021, 23:28
by ThomasB
If you would like to avoid adding more hardware then just disable serial log and use GPIO1 and GPIO3.

FWIW, the relays might momentarily turn on during boot and you won't be able to use serial log. Sometimes this matters, sometimes it doesn't.

- Thomas

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 17 Nov 2021, 20:08
by sawo
Hi all,
thanks a lot your your answers.
I have decided to use a separate Wemos D1 since I changed my plans, to get my pool solar Control to work.

But now I have a different problem, I bought a 4 channel SPDT relay v1.0 board from seeed, this connects via I2C interface.
My problem now is that it is not recongnized, it just shows the value 0x11 but no supported device.
Do I need to include a special driver or library to get this running?

Thanks
sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 17 Nov 2021, 20:46
by Ath
I don't think that I2C device is supported, at least I don't see its address 0x11 handled in the I2C Scanner source code.
Do you have any data sheet for that device available?

Edit:
Found the Seeed github library for these devices (they have 2 and 4 relay boards, and 2, 4 and 8 port solid state versions, all supported by this lib), but it will need a little work to implement, as the library does things not ESPEasy compatible (initialization of the I2C bus is handled by ESPEasy already), but that's fixable.
I will put it on my TODO list, but that will take a little time.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 17 Nov 2021, 21:04
by sawo
I hope that it is okay to post the web link IF NOT PLEASE DELETE
https://wiki.seeedstudio.com/Grove-4-Ch ... PDT_Relay/

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 17 Nov 2021, 21:12
by sawo
@ATH

sorry haven´t read your previous post.
Thanks for your info and your effort!!!!
I try to be patient. :lol:

sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 17 Nov 2021, 22:34
by Ath
There is a start already:

(see below for an updated screenshot)

Most important still to do though, command handling ;)

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 18 Nov 2021, 07:20
by sawo
Ath wrote: 17 Nov 2021, 22:34 There is a start already:

Screenshot - 17_11_2021 , 22_32_08.png

Most important still to do though, command handling ;)
this looks promising :)

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 18 Nov 2021, 09:38
by Ath
There will be some more options, like initial state of a relay, and also an output value holding the current state (as a bitmap), that can optionally be sent to a Controller.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 18 Nov 2021, 10:26
by sawo
Ath wrote: 18 Nov 2021, 09:38 There will be some more options, like initial state of a relay, and also an output value holding the current state (as a bitmap), that can optionally be sent to a Controller.
PERFECT exactly what I was looking for!!!!
Thanks so much

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 18 Nov 2021, 23:23
by Ath
I've put in some legwork, so this is what I've ended up with:

The settings screen:
Screenshot - 18_11_2021 , 22_57_10.png
Screenshot - 18_11_2021 , 22_57_10.png (43.56 KiB) Viewed 19421 times
The Devices overview (not actually tested as I don't own the hardware)
Screenshot - 18_11_2021 , 22_55_55.png
Screenshot - 18_11_2021 , 22_55_55.png (7.58 KiB) Viewed 19421 times
And an ESP8266 4M Custom locally created build:
(updated, see below)

If required I can also provide an ESP32 build.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 19 Nov 2021, 00:28
by TD-er
What is "startup" ?
A call to PLUGIN_INIT?
This is also called if you press save on the task settings page and then this might not be what you want.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 19 Nov 2021, 07:51
by Ath
Yes, that's at PLUGIN_INIT, and it does have that 'side-'effect. Not sure if it's possible to suppress that behavior when saving, so that's going to be a fair warning in the documentation :geek:

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 19 Nov 2021, 08:17
by TD-er
Sure you can.
Define a static int32_t with initial value of 0 in the .ino file, which may act as a task index bitmap.
When you call PLUGIN_INIT, check the bit for this task and if it is not set, call the @setup stuff you need to do and set the bit to 1.
This protection could be made optional too in the settings of course.

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 19 Nov 2021, 08:47
by Ath
OK, I'll fix that as suggested.

For a documentation preview, there are a few commands supported:

Code: Select all

multirelay,on,<channel> (channel 1..8, max. accepted as configured)
multirelay,off,<channel>
multirelay,set,<bit-relay-8..1> (value in decimal, 0xnn hex or 0bnnnnnnnn binary)

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 19 Nov 2021, 09:29
by TD-er
I do get why you're counting from 1...N for the relais, but the bit labelling feels a bit strange.
I know it should be consistent and you are, but still describing bit positions with an index 1 too high (for computer nerds like me ;) ) seems itching...
Not sure how it should be described, but maybe you have some idea?

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 19 Nov 2021, 10:35
by Ath
The numbering in the used library is already that way, and the same for the labeling on the hardware, AFAICS.

I acknowledge that itch about the numbering, and initially even implemented it wrong :shock: had to fix by not subtracting 1 when passing the argument for the on and off commands...
Tried to 'compensate' for that by adding the bit-wise Relay state presentation in the Devices overview page.

Edit:
From the library code (in the turn_on_channel/turn_off_channel methods):

Code: Select all

channel_state |= (1 << (channel - 1));

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 20 Nov 2021, 14:37
by Ath
sawo wrote: 18 Nov 2021, 10:26 exactly what I was looking for!!!!
Hi sawo,
Any chance you have been able to test the workings of this plugin? As so often, I don't own the required hardware, so am unable to test it myself ;)

Just to be sure you have the latest version available, here's an updated build:
(Updated, see below)

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 21 Nov 2021, 22:26
by Ath
I did some more work on this plugin the last couple of days, so here's an updated build:
ESP_Easy_mega_20211121_custom_ESP8266_4M1M.zip
(559.31 KiB) Downloaded 231 times

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 11:59
by sawo
Hi Ath,

sorry I was quite busy in the last days.
No I didn´t had the time to test ist yet. But will do in the evening.
Thanks so far!
Sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 15:18
by sawo
Hi Ath,

I updated my wemos with your version.
The relay modul is conencted and recognized.
But how do I controll them?
What is the command?

Regards
Sascha

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 16:57
by Ath
A direct link to the help(source), as it will be included in ESPEasy: https://github.com/letscontrolit/ESPEas ... fa02R2-R30

in short:

Code: Select all

multirelay,on,<channel>
multirelay,off,<channel>
multirelay,set,<channel_bitmap>
Channel is 1..8 (or 4 or 2, depending on the number set)
Channel_bitmap is 1 bit per relay from 8..1, can be set in decimal, hex or binary notation, f.e. 0b0011 = 0x3 = 3 (decimal) will turn on relay 1 and 2, or 0b10000100 = 0x84 = 132 (decimal) will turn on relay 8 and 3

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 18:46
by sawo
Hi Ath,
thx works for me so far!!!
Is it possible to get the status of each relay seperatly?
Instead of in one state.

thx
sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 19:13
by Ath
sawo wrote: 29 Nov 2021, 18:46 Is it possible to get the status of each relay seperatly?
Instead of in one state.
Well, ESPEasy only supports 4 output values, and though technically that number can be changed, that would make migration from/to other versions nearly impossible, because the settings file structure would have to change, so that's not an option.

I can add a command like multirelay,get,channel that will put the channel number in value 3, and the state in value 4 (to get a relation between the on/off state and the involved channel), or maybe even loop the (configured) channel numbers on each read, but I'm not sure if that matches with what you have in mind?

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 21:31
by Ath
I implemented both options, so you can use the command "multirelay,get,<channel>" and get the Channel and Get state (0/1) in 2 extra variables. Or use the command "multirelay,loop,1" to enable updating the channel on each Interval and read the next channel state. That last feature is also an option in the Device Configuration.

A snippet from the help:
Screenshot - 29_11_2021 , 21_24_05.png
Screenshot - 29_11_2021 , 21_24_05.png (27.64 KiB) Viewed 18876 times
And a snippet from the Devices page:
Screenshot - 29_11_2021 , 21_30_46.png
Screenshot - 29_11_2021 , 21_30_46.png (10.03 KiB) Viewed 18876 times
And a local Custom build including these features:
ESP_Easy_mega_20211129_custom_ESP8266_4M1M.zip
(557.94 KiB) Downloaded 237 times

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 29 Nov 2021, 21:44
by sawo
Hi Ath,
will try it tomorrow.
Thanks a lot for your assistance.

Sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 01 Dec 2021, 15:02
by sawo
Hi Ath,
everything works fine for me!!!!
Thanks a lot for your help, hope to finally to complete my project!!!!

Sawo

Re: Wemos D1 mini - which GPIO ports for relays?

Posted: 12 Dec 2021, 21:20
by Ath
sawo wrote: 01 Dec 2021, 15:02 everything works fine for me!!!!
The plugin has been merged into the main 'mega' branch of ESPEasy today, and a formal release will most likely be made available in the coming days.