MCP Status without device

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Micha_he
Normal user
Posts: 372
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

MCP Status without device

#1 Post by Micha_he » 15 Sep 2022, 16:11

I use a MCP23017 via I2C, without configured devices. The internal command's like 'MCPGPIO,4,1' works. But when i use the command 'Status,MCP,4' or 'Status,M,4' I get a state of '0'.

Code: Select all

{
"log": "",
"plugin": 9,
"pin": 4,
"mode": "input",
"state": 0
}
Is this command don't work without a device is setup ?

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: MCP Status without device

#2 Post by iron » 15 Sep 2022, 19:45

You initiate monitor at/after boot ?

Monitor,MCP,<MCPGPIO>
-D

User avatar
chromo23
Normal user
Posts: 838
Joined: 10 Sep 2020, 16:02
Location: germany

Re: MCP Status without device

#3 Post by chromo23 » 15 Sep 2022, 20:05

I am also not sure this command works correctly ... but the project i used the mcp23017 for is already deployed and i only have remote access to the software...so i can do no proper testing.

Edit: but there also seems to be a discrepancy in the mode... it seems that you use the the mcp23017 as an output but the log states the gpio as an input.. did you also set the mode?

Micha_he
Normal user
Posts: 372
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: MCP Status without device

#4 Post by Micha_he » 15 Sep 2022, 20:22

Yes, the mode is set to output at start.

@iron: Yes, I set the monitor at start and the monitor works, event is generated.

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

Re: MCP Status without device

#5 Post by Ath » 15 Sep 2022, 20:49

Micha_he wrote: 15 Sep 2022, 16:11 Is this command don't work without a device is setup ?
The "status" command is (also) an ESPEasy core command and doesn't need a device/task to be set up, only connected (but that shouldn't be a problem :lol:), as it directly reads the status via the I2C bus.
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#6 Post by Smotek7 » 11 Jun 2024, 11:46

Hi,
sorry for the beginner's question.
I don't want to start a new topic.

I have an MCP23017 connected, I scan the I2C and see it at 0x20.
I will send MCPGPIO,2,1 from the command line and it will return Failed
I tried to define
On System#Boot Do
MCPmodeRange,1,16,0
MonitorRange,MCP,1,16
Endon
but it didn't help.
Build: ESP_Easy_mega_20240414_collection_A_ESP32_4M316k Apr 14 2024
Where am I doing wrong?

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#7 Post by Smotek7 » 12 Jun 2024, 08:11

The problem was in HW.
Strange behavior of ESP32, I tried it on another and it works there.

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

Re: MCP Status without device

#8 Post by TD-er » 12 Jun 2024, 09:35

Ah good to know, as I already discussed it with Ton as I couldn't find anything obviously wrong in what you tried to do.

Maybe you're using some pins for I2C which are better not used on ESP32?

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#9 Post by Smotek7 » 23 Jul 2024, 13:53

Information, feedback.
I had the same problem again.
The rule
On System#Boot Do
MCPModeRange,17,32,1
MonitorRange,MCP,17,32
Endon
It did not work.
The I2C scanner detected an MCP on the bus.

Defining in Devices didn't work either.
I had to tick
Force slow I2C speed,
to make it work.

Then I changed the I2C speed in hardware to 100,000.
Now it works even after entering the rules.

MCP23017 can't handle the default speed of 400k?
But at least I know what "Force slow I2C speed" is.

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

Re: MCP Status without device

#10 Post by Ath » 23 Jul 2024, 15:13

According to the datasheet an MCP23017 should be able to handle up to 1.7 MHz clockspeed on the I2C bus. (And even 10 MHz for an MCP23S017, using the SPI bus; same chip, but with different interface)

Maybe there is an issue/something interfering with your wiring?
- Do you use short I2C wiring (max. up to 30 cm)?
- Do you have appropriate pull-up resistors on the SDA and SCL connections? (10k is often used, for longer wires it can be lowered to min. 2.2k)
- Are there other devices on the I2C bus that might interfere with the MCP23017? (AHT10/AHT15 are known culprits :o)

The documentation indeed states that the Force slow I2C speed uses the Low setting from the Hardware page (default at 100 kHz) and that setting is also used during an I2C scan, so all devices responding to that (I've recently found an I2C device that doesn't :shock:) can be found, as 100 kHz is the lowest maximum being supported by all devices, AFAIK.
Setting the regular I2C speed to 100 kHz might slow down other I2C devices that will benefit from that speed, like the OLED displays. Using that Force... checkbox is advised on individual devices that don't work as expected.
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#11 Post by Smotek7 » 23 Jul 2024, 16:24

It's on one board. Along with Lilygo ETH lite.
Road 100mm.
Pollup 10k.
Chips on the bus, 2x MCP23017, 1xADS1115, 1xPCA9685
In this context, I remembered that the one MCP23017 is like OUT.
The one via http worked, I tested that first.
Then I added a second MCP23017 as IN, and it had problems at 400000.

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

Re: MCP Status without device

#12 Post by Ath » 23 Jul 2024, 16:57

If you have pull-up resistors on all I2C boards, then the resulting pull-up resistance will be 2k5. That can be rather low for some chips, so maybe when removing the pull-ups from 1 or more boards will improve the situation (for testing you can ofcourse just disconnect 1 or more of the other boards). If the situation remains the same for just that board, then it may be a (somewhat) defective chip (ESD safe handled?).
/Ton (PayPal.me)

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

Re: MCP Status without device

#13 Post by TD-er » 24 Jul 2024, 00:20

Also check to see if the voltage applied to the chips is constant.
It for sure never hurts to add some 100 nF capacitors as close as possible to the chip's Vcc and GND pin.

Anyway, this is not the first time I hear anyone mention some GPIO expander is not able to run stable on 400 kHz, so maybe we do query those chips a bit too fast and when running at a lower clock speed the chip might be able to handle it better?

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#14 Post by Smotek7 » 24 Jul 2024, 00:45

I designed the boards, they are two boards above each other through the header.
But it has no effect on the function.
@Ath
there is only 1x 10k, for the bus

@TD-er
100nF is a matter of course for every chip.

The MCP23017 has a 5V power supply.
ESP32 has 3.3V
Pollup are about 5V.
They should probably be about 3.3V with ESP32.

A friend tried this board with ESPHOME and it worked there.
I just looked and there is a default of 50000 on I2C.

I'll see how it works on 100000.
In principle, that speed is enough for me.

Otherwise MCP23017 bought original, I think with Digikey 100 new chips.
No Ali boards.

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

Re: MCP Status without device

#15 Post by TD-er » 24 Jul 2024, 08:50

The ESP may be 5V tolerant, but are all other devices on the I2C bus?

Also could it be the MCP chip has its low- and high-level defined relative to the applied voltage?
If so, then it may be that the "high" time of the pulses sent by the ESP are a bit too short.

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#16 Post by Smotek7 » 07 Aug 2024, 00:19

@TD-er I forgot to reply too.
All devices are 5V.
Now I swapped on the I2C board with GPIO2 and 4 to GPIO4 and 14.
And it works for me at 400k. I will follow it and if I come across something I will give info.

But I have one question.
I asked this a long time ago, but since then the MCP commands have been added.
I use:
MCPModeRange,17,32,1
MonitorRange,MCP,17,32
But I need it to go to the defined controller as well.
This used to only work with Devices.
Is it possible to create rules to send it to the controller?
I use Generic UDP.
I would imagine something like the MonitorRangeToControler statement.

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

Re: MCP Status without device

#17 Post by Ath » 07 Aug 2024, 08:24

Monitoring a gpio should generate an event on change. From there you can activate output to the controller.
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#18 Post by Smotek7 » 07 Aug 2024, 09:47

@Ath
I can see events in the log.
I have the controller set.
Do I still have to write a rule?
IF "event" do .....
I need a kick.

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

Re: MCP Status without device

#19 Post by TD-er » 07 Aug 2024, 12:54

When acting on events in rules, the typical rules block looks like this:

Code: Select all

on ... do

endon
To trigger events based on pin state changes of a GPIO pin or a pin on a GPIO expander, you need to call "monitor"
See: https://espeasy.readthedocs.io/en/lates ... al-mcpgpio

This can be done manually on the tools page in the command input field, or more structurally started from the rules when the system boots.

Code: Select all

on System#Boot do
  Monitor,MCP,<MCPGPIO> // Need to fill in the pin(s) you would like to monitor
endon

on mcp#1 do   // Act on MCP pin #1
  if %eventvalue1%=0 
    // pin state low
    ...
  else
    // pin state high
    ...
  endif
endon


N.B. you can also refer to the current state of a pin by using [Plugin#MCP#Pinstate#N]
See: https://espeasy.readthedocs.io/en/lates ... task-names

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#20 Post by Smotek7 » 07 Aug 2024, 14:03

@Td-er
I have the monitor defined

Code: Select all

On System#Boot Do
 MCPModeRange,17,32,1
 MonitorRange,MCP,17,32
Endon
I can see events in the log on the web and uart
I have Controller 1 set to Generic UDP.
cont1.png
cont1.png (11.44 KiB) Viewed 8990 times
I just don't know how to set those events to be sent to the controller.

Do I have to set for each pin?

Code: Select all

on mcp#1 do // Act on MCP pin #1
 if %eventvalue1%=0
 // pin state low
 ...
 otherwise
 // pin state high
 ...
 endif
endon
I did not find the command how to enter so that it goes to the controller.

Basically, I need this check box for all MCP pins.
As in devices.
cont.png
cont.png (3.91 KiB) Viewed 8990 times

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

Re: MCP Status without device

#21 Post by Ath » 07 Aug 2024, 16:54

Hm, that's one of the controllers that doesn't have a direct command to send out values.

(Best) alternative is to use the SendToUDP command from rules, but you'll have to manually provide the url and format the payload (also part of the url...) as intended.

Code: Select all

on mcp#1 do // Act on MCP pin #1
  SendToUDP,<destination-ip>,<port>,'%sysname%_mcp_1_state=%eventvalue1%'
endon

// Or alternatively for all pins in a single rule:
on mcp do
  SendToUDP,<destination-ip>,<port>,'%sysname%_mcp_%eventpar%_state=%eventvalue1%'
endon
Last edited by Ath on 07 Aug 2024, 18:55, edited 1 time in total.
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#22 Post by Smotek7 » 07 Aug 2024, 17:53

@Ath
I know that SendToUDP exists.
I just don't like that I have to write settings in the rules
<destination-ip>,<port>

That's why I'm asking if it can't be made cleaner.
I will test this as well.

I found another option in tools
cont2.png
cont2.png (6.24 KiB) Viewed 8975 times
Only the whole log goes there again, everything.

I was hoping for something like:
on mcp do
SendToControler,<Nr>,'%_state=%eventvalue1%'
endon

Thanks for help.
I will try the alternative rule for all pins.

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

Re: MCP Status without device

#23 Post by TD-er » 07 Aug 2024, 18:24

It can be shortened in rules, but I have to run now, will post later.

... unless Ton will beat me to it :)

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

Re: MCP Status without device

#24 Post by TD-er » 07 Aug 2024, 21:09

Hmm I did check what Ton has written and he already was using the short-hand notation for having only a single event block for all mcp events.

What is the problem of having the hostname/IP and port nr in the rules?

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#25 Post by Smotek7 » 07 Aug 2024, 21:34

@TD-er
It's not a problem.
I just want it "user friendly".
When I preset the module, and then someone has to rewrite the "Code" to convert it to their own network.
If it were to go through the Controller tab, it is "clean" friendly.

I asked about it 2 years ago and I know that since then some things have been added to the MCP. For example Monitor range...
That's why I asked if it was possible to send events to the Controller.
Maybe write it in your head to edit the 999 position, if something was added to the MCP, it would be possible to do something similar. Or in general the command for rules command SendToController.
But don't waste time on that at all, it's not important.

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#26 Post by Smotek7 » 07 Aug 2024, 23:42

I tested a

Code: Select all

on mcp do
doesn't work for me

I gave it a try

Code: Select all

on mcp#26 do
It works

Is there a mass MCP event?

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

Re: MCP Status without device

#27 Post by TD-er » 07 Aug 2024, 23:47

See: https://espeasy.readthedocs.io/en/lates ... r-eventpar

Code: Select all

on mcp* do
  SendToUDP,<destination-ip>,<port>,'%sysname%_mcp_%eventpar%_state=%eventvalue1%'
endon
Ton missed a *

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#28 Post by Smotek7 » 08 Aug 2024, 00:02

@TD-er

Code: Select all

on mcp* do
it works

I tried mcp#state, mcp#all :D

Thanks for help

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#29 Post by Smotek7 » 10 Sep 2024, 15:37

Question about sending UDP.
I have Pollup resistors there, reverse logic.
Can it be overturned in the rules?

I tried this but I can't make the correct code.
That is, if such a thing is possible.

Code: Select all

on mcp* do
  If  [mcp*#eventvalue1]=1 Do
      SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=0'
  Endif
  If  [mcp*#eventvalue1]=0 Do  
      SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=1'
  Endif
endon

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

Re: MCP Status without device

#30 Post by Ath » 10 Sep 2024, 15:55

Smotek7 wrote: 10 Sep 2024, 15:37

Code: Select all

on mcp* do
  If  [mcp*#eventvalue1]=1 Do
      SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=0'
  Endif
  If  [mcp*#eventvalue1]=0 Do  
      SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=1'
  Endif
endon
Could be as simple as this: (eventvalueX must be wrapped with % signs)

Code: Select all

on mcp* do
  SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=!%eventvalue1%'
endon
(Mind the exclamation mark I inserted! That inverts the 1/0 value.)
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#31 Post by Smotek7 » 10 Sep 2024, 16:08

exclamation mark
didn't help
send it as text
28637: ACT : SendToUDP,192.168.1.100,5555,'DI-ext_mcp_13_state=!0'
28736: ACT : SendToUDP,192.168.1.100,5555,'DI-ext_mcp_13_state=!1'

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

Re: MCP Status without device

#32 Post by Ath » 10 Sep 2024, 16:14

Hm, don't have an ESP here, but maybe this could work:

Code: Select all

on mcp* do
  let,1,!%eventvalue1%
  SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=%v1%'
endon
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#33 Post by Smotek7 » 10 Sep 2024, 16:29

That's exactly what I thought then :D

Code: Select all

on mcp* do
   Let,1,!%eventvalue1%
   SendToUDP,192.168.1.100,5555,'%sysname%_mcp_%eventpar%_state=%v1%'
endon

There is a question
Dummy devices and String value.
I can't find details or an example.

Can I do something like this?
I have Dummy String
TaskValueSet 1,1,'%sysname%_mcp_%eventpar%_state=%v1%'

I also tried
TaskValueSet 1,1,'%sysname%'

But it doesn't do anything for me in Devices.

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

Re: MCP Status without device

#34 Post by TD-er » 10 Sep 2024, 16:31

Yep, calculations are not done in strings.
You need to store it in a variable using let.

There are some exceptions like as a direct command parameter, then you need to prefix it using an = sign.
For example:

Code: Select all

gpio,1,=!%eventvalue1%
But this is not done (for obvious reasons) in string parsing replacements.

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

Re: MCP Status without device

#35 Post by TD-er » 10 Sep 2024, 16:33

You can only set numerical values using taskvalueset.
And when you want to use taskvalueset on tasks which are not dummy tasks, then you have to enable this on the tools->Advanced page.

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#36 Post by Smotek7 » 10 Sep 2024, 17:01

@TD-er
He meant that I would use a dummy string to send to the controller.

I will create a string of Dummy devices
I will make a rule
on mcp* do
Let,1,!%eventvalue1%
TaskValueSet 1,1,'%sysname%_mcp_%eventpar%_state=%v1%'
endon

So that I don't have to enter the IP and port in the rules.
We dealt with that before.
It was just a thought whether it is not possible to use a dummy string.
How to use Dummy devices string?

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

Re: MCP Status without device

#37 Post by TD-er » 10 Sep 2024, 18:09

You cannot set strings using taskvalueset.
Only numbers

If you need to store a complete IP-address, in a task, then you must do this per taskvalue.

I assume you need to keep it in a dummy task, to keep it to survive a reboot?

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#38 Post by Smotek7 » 10 Sep 2024, 18:33

@TD-er
No IP

I should have put the thought in a dummy string

'%sysname%_mcp_%eventpar%_state=%v1%'

But now that I'm writing it, something occurred to me.
I have to try it.

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#39 Post by Smotek7 » 10 Sep 2024, 19:03

This was a thought

Code: Select all

on mcp* do
 Let,1,!%eventvalue1%
 TaskValueSet,1,1,%eventpar%
 TaskValueSet,1,2,%v1%
endon
It also works, I can see the values ​​in devices.

But why doesn't this work?
Generic - Dummy Device
dummy.png
dummy.png (30.36 KiB) Viewed 2595 times
It does not send it to the controller when the event occurs.
The last values ​​are sent on reboot.

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

Re: MCP Status without device

#40 Post by Ath » 10 Sep 2024, 19:35

When do you use the taskrun command on that dummy device? The interval of 0 causes that to not happen automatically. You can use the TaskValueSetAndRun command as the last command so the values are set and sent to the controller(s).
/Ton (PayPal.me)

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#41 Post by Smotek7 » 10 Sep 2024, 20:04

@Ath
TaskValueSetAndRun works.

The last problem is that it does not work
Single event with all values:

Smotek7
Normal user
Posts: 165
Joined: 01 Aug 2020, 16:18
Location: SK

Re: MCP Status without device

#42 Post by Smotek7 » 10 Sep 2024, 20:18

I solved it mathematically

Code: Select all

TaskValueSetAndRun,1,1,%eventpar%*10+%v1%
I will deal with it further on the receiving side.

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

Re: MCP Status without device

#43 Post by Ath » 10 Sep 2024, 20:40

Smotek7 wrote: 10 Sep 2024, 20:04 @Ath
TaskValueSetAndRun works.

The last problem is that it does not work
Single event with all values:
2 things are probably mixed up here:
1) "Single event with all values" will generate an event: <TaskName>#All, that has, in this case, 2 values, %eventvalue1% (=IN) and %eventvalue2% (=ST), but the way the values are handled by the controller depends on how the controller works, not on this checkbox. In general, Controllers send each value separate, as there's no 'generic' way of sending multiple values, except when a receiving end of such controller explicitly supports that. And Generic UDP is (way) too generic to be able to support that, as there is no explicit definition of the receiving side.

2) When using TaskValueSet for 1 value, and TaskValueSetAndRun for the second value, both values will be sent to the controller, as designed and intended.
/Ton (PayPal.me)

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

Re: MCP Status without device

#44 Post by TD-er » 10 Sep 2024, 21:12

Also better not use "int32(2x)" unless you really need the extra bits to store your values.
Not all controllers might be able to handle types which differ from the default float type.

So if you need to store integer values which exceed 21 bits (roughly 2 million) you can switch this output type to some int variant to store the extra bits.
Integer values which are typically smaller will not loose any resolution when stored as float.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest