Monitor GPIO - question

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Monitor GPIO - question

#1 Post by pw444 » 31 Dec 2020, 20:57

Hya,

i was using Monitor GPIO and also had this GPIO defined in a virtual button under devices, and while testing, results where weird, and i finally removed the Monitor GPIO and all worked like a charm.

Is there any incompatibility with GPIO monitoring when this GPIO is being used (define) in a device?

Which is the main purpose of Monitor GPIO? verifying the state when this GPIO is not defined under devices?

Thx in advance for any explanation.

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

Re: Monitor GPIO - question

#2 Post by TD-er » 01 Jan 2021, 12:34

Hmm I may need a bit more info on what's "weird" and how you're using it.
The reason to use the monitor command is to get events when the state of a monitored pin has changed.
Handling events does take quite some resources, so you should not do it on any pin by default.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Monitor GPIO - question

#3 Post by pw444 » 01 Jan 2021, 15:23

on the following code i had Monitor GPIO,4

Code: Select all

On System#Boot do
//  GPIO,2,0  // status led - inversed - 1 OFF, 0 ON  
//  Monitor GPIO,4  // D2
  timerSet,1,5
  gpio,12,0
  gpio,13,0
  gpio,14,0
  let,1,0
  let,2,1
endon

on MQTT#Connected do
  event,publishstatus
endon

// loop

// events triggered by http

On B58 do               // B58 - gpio 14 - D5 
  pulse,14,1,500
  pulse,2,1,500
  let,1,1
  Publish,%sysname%/B58/status,0
endon

On B24 do               // B24 - gpio 12 - D6
  pulse,12,1,500
  pulse,2,1,500
  let,1,1
  Publish,%sysname%/B24/status,0
endon 

On BOFF do              // BOFF - gpio 13 - D7
  pulse,13,1,500
  pulse,2,1,500
  Publish,%sysname%/BOFF/status,0
  let,1,2
endon

// events triggered by MQTT

on MQTTIN#BOFF do       // cancelled
  if %eventvalue%=1
     logentry,"mqt boff"
     pulse,13,1,500
     pulse,2,1,500
     Publish,%sysname%/BOFF/status,0
     let,1,2
  endif
endon

on MQTTIN#B58 do       // brew 5-8
  if %eventvalue%=1
     logentry,"mqt b58"
     pulse,14,1,500
     pulse,2,1,500
     Publish,%sysname%/B58/status,0
     let,1,1
  endif
endon

on MQTTIN#B24 do        // brew 2-4
  if %eventvalue%=1
     logentry,"mqt b24"
     pulse,12,1,500
     pulse,2,1,500
     Publish,%sysname%/B24/status,0
     let,1,1
  endif
endon

on VACC#status do
  if %eventvalue%=1  // status = 1
    if %v1%=1        // status = 1 var1 = 1
       logentry,"Working"
       gpio,2,1      // led on
       Publish,%sysname%/Notify/status,1  // working
    endif
  else               // status = 0
    if %v1%=1        // status = 0 var1 =1
       let,1,0
       logentry,"Finished"
       gpio,2,0      // led off
       Publish,%sysname%/Notify/status,0   // finished
    endif 
    if %v1%=2        // status = 0 var1 =2
       let,1,0
       logentry,"Cancelled"
       gpio,2,0      // led off
       Publish,%sysname%/Notify/status,2   // cancelled
    endif       
  endif
endon
The result was that gpio 04 never had a constat behavior, and with MM on GND and GPIO 4, i never had the voltage.

Please note the GPIO 04 is the VACC device.

When i commented out the Monitor, it worked like a charm. That's why i asked, it monitoring a gpio defined on a device can cause weird behavior.

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

Re: Monitor GPIO - question

#4 Post by TD-er » 02 Jan 2021, 10:35

So you have the switch task + monitoring for GPIO 4?
There is no need for monitoring on that pin if you also have a switch task configured as the switch task will generate events on its own on changes.

I am not sure why it was not working, maybe the extra event handling interfered with the speed needed for the switch task?

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Monitor GPIO - question

#5 Post by pw444 » 02 Jan 2021, 17:48

seams not being a good idea.. learned the hard way :lol:

Post Reply

Who is online

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