Wemos D1 mini - which GPIO ports for relays?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

Wemos D1 mini - which GPIO ports for relays?

#1 Post by sawo » 12 Nov 2021, 10:54

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

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

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

#2 Post by dynamicdave » 12 Nov 2021, 11:00

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.

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#3 Post by sawo » 12 Nov 2021, 11:53

Hi dynamicdave,
thanks for your answer, so in this case I think I will use a seperate wemos to controll the relays.
Thanks
sawo

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

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

#4 Post by dynamicdave » 12 Nov 2021, 14:29

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.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

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

#5 Post by ThomasB » 12 Nov 2021, 23:28

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

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#6 Post by sawo » 17 Nov 2021, 20:08

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

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#7 Post by Ath » 17 Nov 2021, 20:46

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.
Last edited by Ath on 17 Nov 2021, 21:08, edited 1 time in total.
/Ton (PayPal.me)

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#8 Post by sawo » 17 Nov 2021, 21:04

I hope that it is okay to post the web link IF NOT PLEASE DELETE
https://wiki.seeedstudio.com/Grove-4-Ch ... PDT_Relay/

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#9 Post by sawo » 17 Nov 2021, 21:12

@ATH

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

sawo

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#10 Post by Ath » 17 Nov 2021, 22:34

There is a start already:

(see below for an updated screenshot)

Most important still to do though, command handling ;)
Last edited by Ath on 18 Nov 2021, 23:19, edited 1 time in total.
/Ton (PayPal.me)

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#11 Post by sawo » 18 Nov 2021, 07:20

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 :)

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#12 Post by Ath » 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.
/Ton (PayPal.me)

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#13 Post by sawo » 18 Nov 2021, 10:26

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

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#14 Post by Ath » 18 Nov 2021, 23:23

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 17735 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 17735 times
And an ESP8266 4M Custom locally created build:
(updated, see below)

If required I can also provide an ESP32 build.
Last edited by Ath on 20 Nov 2021, 14:38, edited 1 time in total.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#15 Post by TD-er » 19 Nov 2021, 00:28

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.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#16 Post by Ath » 19 Nov 2021, 07:51

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:
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#17 Post by TD-er » 19 Nov 2021, 08:17

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.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#18 Post by Ath » 19 Nov 2021, 08:47

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)
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#19 Post by TD-er » 19 Nov 2021, 09:29

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?

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#20 Post by Ath » 19 Nov 2021, 10:35

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));
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#21 Post by Ath » 20 Nov 2021, 14:37

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)
Last edited by Ath on 21 Nov 2021, 22:26, edited 1 time in total.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#22 Post by Ath » 21 Nov 2021, 22:26

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 227 times
/Ton (PayPal.me)

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#23 Post by sawo » 29 Nov 2021, 11:59

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

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#24 Post by sawo » 29 Nov 2021, 15:18

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
Attachments
device.JPG
device.JPG (28.83 KiB) Viewed 17225 times
i2c.JPG
i2c.JPG (20.41 KiB) Viewed 17225 times

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#25 Post by Ath » 29 Nov 2021, 16:57

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
/Ton (PayPal.me)

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#26 Post by sawo » 29 Nov 2021, 18:46

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

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#27 Post by Ath » 29 Nov 2021, 19:13

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?
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#28 Post by Ath » 29 Nov 2021, 21:31

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 17190 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 17190 times
And a local Custom build including these features:
ESP_Easy_mega_20211129_custom_ESP8266_4M1M.zip
(557.94 KiB) Downloaded 232 times
/Ton (PayPal.me)

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#29 Post by sawo » 29 Nov 2021, 21:44

Hi Ath,
will try it tomorrow.
Thanks a lot for your assistance.

Sawo

sawo
Normal user
Posts: 36
Joined: 26 Mar 2020, 12:20

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

#30 Post by sawo » 01 Dec 2021, 15:02

Hi Ath,
everything works fine for me!!!!
Thanks a lot for your help, hope to finally to complete my project!!!!

Sawo

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

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

#31 Post by Ath » 12 Dec 2021, 21:20

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.
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests