multiplexer recommending

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
edstobi
Normal user
Posts: 55
Joined: 28 May 2020, 20:33

multiplexer recommending

#1 Post by edstobi » 01 Mar 2025, 17:43

Hello,
can anyone recommend a multiplexer? I have 16 IOs with active pull-up and 16 IOs with active pull-down. I would like to connect them to an ESPeasy.

Can anyone recommend a hardware module that is supported by ESPeasy?
Thanks a lot!

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

Re: multiplexer recommending

#2 Post by Ath » 01 Mar 2025, 20:31

It's of only little concern, but are those input or output pins? (or both)

There are several IO extenders supported by ESPEasy, a few even in core-commands like monitor, to name most: PCF8574 (8 I/Os), PCF8575 (16 I/Os, no internal pull-up), PCA9685 (16 I/Os, on/off and PWM support) and MCP23017 (16 I/Os) all using I2C and allowing multiple boards connected, and also some shift-registers for input (74HC165, up to 128 inputs, 8 inputs per chip, daisy-chainable) and output (74HC595, up to 128 outputs, 8 outputs per chip, daisy-chainable).
The full list of plugins is here

So it mainly depends on what you want to use it for ;)
/Ton (PayPal.me)

edstobi
Normal user
Posts: 55
Joined: 28 May 2020, 20:33

Re: multiplexer recommending

#3 Post by edstobi » 01 Mar 2025, 21:28

Thank you.
I will work through the suggested list and pick out the best fit for me.
Regarding your question, pure input status messages are either high or low active.
THX EDSTOBI

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

Re: multiplexer recommending

#4 Post by Ath » 01 Mar 2025, 21:35

So, having something as simple as either a pair of MCP23017 or a few 74HC165 chips would suffice here.
/Ton (PayPal.me)

edstobi
Normal user
Posts: 55
Joined: 28 May 2020, 20:33

Re: multiplexer recommending

#5 Post by edstobi » 15 Mar 2025, 21:49

Hello!
My PCF8574s arrived today. Now I have a question for understanding. Do I need to query each port (P0 to P7) individually? If so, I can't use two modules with an ESP8266 since I only have 12 query possibilities. I thought the 8 pin states would be combined and transmitted as a binary, hexadecimal, or decimal number? :(
Is ther a function lik read all.

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

Re: multiplexer recommending

#6 Post by TD-er » 15 Mar 2025, 22:47

Please have a look at the documentation: https://espeasy.readthedocs.io/en/lates ... al-pcfgpio
Here you can see how you can use those GPIO pins on this PCF chip using commands.
This way you don't need to setup tasks per GPIO.

N.B. the GPIO pin numbering is based on the used I2C address of the PCF chip.
The lowest possible address (0x20) refers to the pins starting at '1' ... '8'
The next one (I2C address 0x21) refers to pin nr. '9' ... ' 16', etc.

edstobi
Normal user
Posts: 55
Joined: 28 May 2020, 20:33

Re: multiplexer recommending

#7 Post by edstobi » 16 Mar 2025, 01:49

Thank you very much!
I have now created a rule where I wrote:

Code: Select all

On System#Boot Do //When the ESP boots, do
  PCFmodeRange,1,16,1
  MonitorRange,PCF,1,16
 Publish %sysname%/IP,%ip%
  timerSet,2,30      //Set Timer 2 for the next event in 30 seconds
endon

On Rules#Timer=2 do  //When Timer2 expires, do
 Publish %sysname%/IP,%ip%
  timerSet,2,30       //Resets the Timer21 for another 30 seconds
endon
On PCF#1 Do
  let,1,%eventvalue%
  timerSet,1,1
Endon
On PCF#2 Do
  let,2,%eventvalue%
  timerSet,1,1
Endon
On PCF#3 Do
  let,3,%eventvalue%
  timerSet,1,1
Endon
On PCF#4 Do
  let,4,%eventvalue%
  timerSet,1,1
Endon
On PCF#5 Do
  let,5,%eventvalue%
  timerSet,1,1
Endon
On PCF#6 Do
  let,6,%eventvalue%
  timerSet,1,1
Endon
On PCF#7 Do
  let,7,%eventvalue%
  timerSet,1,1
Endon
On PCF#8 Do
  let,8,%eventvalue%
  timerSet,1,1
Endon
On PCF#9 Do
  let,9,%eventvalue%
  timerSet,1,1
Endon
On PCF#10 Do
  let,10,%eventvalue%
  timerSet,1,1
Endon
On PCF#11 Do
  let,11,%eventvalue%
  timerSet,1,1
Endon
On PCF#12 Do
  let,12,%eventvalue%
  timerSet,1,1
Endon
On PCF#13 Do
  let,13,%eventvalue%
  timerSet,1,1
Endon
On PCF#14 Do
  let,14,%eventvalue%
  timerSet,1,1
Endon
On PCF#15 Do
  let,15,%eventvalue%
  timerSet,1,1
Endon
On PCF#16 Do
  let,16,%eventvalue%
  timerSet,1,1
Endon
On Rules#Timer=1 Do
  let,20,(%v1%<<0)|(%v2%<<1)|(%v3%<<2)|(%v4%<<3)|(%v5%<<4)|(%v6%<<5)|(%v7%<<6)|(%v8%<<7)|(%v9%<<8)|(%v10%<<9)|(%v11%<<10)|(%v12%<<11)|(%v13%<<12)|(%v14%<<13)|(%v15%<<14)|(%v16%<<15)
  Publish monitor/pcf8574/bitmask,[var#20]
Endon
I can also see the changes for each pin in the ESPeasy log.
341084: EVENT: PCF#12=1
341283: EVENT: PCF#13=0
341383: EVENT: PCF#13=1
343984: EVENT: PCF#15=0
367391: EVENT: PCF#2=-1
367398: EVENT: PCF#3=-1
I see the IP in mqtt
However, I can't manage to get the pins as a bitmask, nor can I publish them to MQTT to then combine them into a bitmask in Node-RED.
Could you give me a tip on how to proceed here?
THX EDSTOBI

edstobi
Normal user
Posts: 55
Joined: 28 May 2020, 20:33

Re: multiplexer recommending

#8 Post by edstobi » 16 Mar 2025, 02:37

found my mistake :P

Code: Select all

On System#Boot Do //When the ESP boots, do
  PCFmodeRange,1,16,1
  MonitorRange,PCF,1,16
 Publish %sysname%/IP,%ip%
  timerSet,2,30      //Set Timer 2 for the next event in 30 seconds
endon

On Rules#Timer=2 do  //When Timer2 expires, do
 Publish %sysname%/IP,%ip%
  timerSet,2,30       //Resets the Timer21 for another 30 seconds
endon


On PCF#1 Do
  let,1,%eventvalue%
  timerSet,1,1
Endon
On PCF#2 Do
  let,2,%eventvalue%
  timerSet,1,1
Endon
On PCF#3 Do
  let,3,%eventvalue%
  timerSet,1,1
Endon
On PCF#4 Do
  let,4,%eventvalue%
  timerSet,1,1
Endon
On PCF#5 Do
  let,5,%eventvalue%
  timerSet,1,1
Endon
On PCF#6 Do
  let,6,%eventvalue%
  timerSet,1,1
Endon
On PCF#7 Do
  let,7,%eventvalue%
  timerSet,1,1
Endon
On PCF#8 Do
  let,8,%eventvalue%
  timerSet,1,1
Endon
On PCF#9 Do
  let,9,%eventvalue%
  timerSet,1,1
Endon
On PCF#10 Do
  let,10,%eventvalue%
  timerSet,1,1
Endon
On PCF#11 Do
  let,11,%eventvalue%
  timerSet,1,1
Endon
On PCF#12 Do
  let,12,%eventvalue%
  timerSet,1,1
Endon
On PCF#13 Do
  let,13,%eventvalue%
  timerSet,1,1
Endon
On PCF#14 Do
  let,14,%eventvalue%
  timerSet,1,1
Endon
On PCF#15 Do
  let,15,%eventvalue%
  timerSet,1,1
Endon
On PCF#16 Do
  let,16,%eventvalue%
  timerSet,1,1
Endon

On Rules#Timer=1 Do
   // Binärstring bauen
  let,21,%v16%%v15%%v14%%v13%%v12%%v11%%v10%%v9%%v8%%v7%%v6%%v5%%v4%%v3%%v2%%v1%
  Publish ESP_pcf8574/binary,[var#21]
Endon
What I still don't understand is why the value ends with binary = 1111111111101111.04 :?:
Log:
609163: EVENT: Rules#Timer=1,1
609185: ACT : let,21,1111111111110111
609192: ACT : Publish ESP_pcf8574/binary,1111111111110111.04

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

Re: multiplexer recommending

#9 Post by TD-er » 16 Mar 2025, 08:39

You're running out of number of decimals you can use as a double type.
Why set it to a variable and not directly publish those bits?

Code: Select all

On Rules#Timer=1 Do
   // Binärstring bauen
  Publish ESP_pcf8574/binary,%v16%%v15%%v14%%v13%%v12%%v11%%v10%%v9%%v8%%v7%%v6%%v5%%v4%%v3%%v2%%v1%
Endon

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

Re: multiplexer recommending

#10 Post by TD-er » 16 Mar 2025, 08:48

When you set the timer on each pin state change, you also reset any current timer.
So if you change a pin (or multiple) with an interval of less than 1 sec, you will never see this publish happening.

Also may I hint you to this part of the docs :)
https://espeasy.readthedocs.io/en/lates ... obin-tohex

Especially the bitwrite and tobin functions :)

Edit:
Just some idea:

Code: Select all

on system#boot do
  PCFmodeRange,1,16,1
  MonitorRange,PCF,1,16
  Publish %sysname%/IP,%ip%
  timerSet,2,30      //Set Timer 2 for the next event in 30 seconds
  looptimerset,2,1   // publish changed every second
endon

on PCF* do
  // %eventpar% is pin nr, starting from 1
  // Thus need to subtract 1 to get the range 0...15
  let,3,%eventpar%-1
  let,4,[int#1]  // For logging
  let,1,{bitwrite:[int#3]:[int#1]:%eventvalue1%}
  logentry,"%eventname%: Set bit [int#3] to %eventvalue1%: [int#4] -> [int#1]" 
endon

on Rules#Timer=2 do
  if [int#2] != [int#1]
    let,2,[int#1]
    publish, ESP_pcf8574/binary,{toBin:[int#1]:16}
  endif
endon
See:
https://espeasy.readthedocs.io/en/lates ... g-wildcard
https://espeasy.readthedocs.io/en/lates ... r-eventpar
https://espeasy.readthedocs.io/en/lates ... l#bitwrite

Not 100% sure the :16 for the toBin will work as the documentation only mentioned this optional parameter for toHex

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests