Polling inputs

Brecht

New member
Hello everyone,

I use Sequent Microsystem HATs for my home automation. All my switches are connected to 'Sixteen LV Digital Inputs' which I poll from node-red every 10ms to detect button events. As polling is not efficient and 99% of the time nothing can be detected, I was wondering how I could optimise this. I've read that other HAT's have interrupt handlers, but this is not mentioned in the manual of the 16LV input HAT.

Any thoughts on how I can optimise this?

Thanks!

Manual of the Industrial Automation V3 8-Layer Stackable HAT for Raspberry Pi:
Two of the Raspberry Pi’s GPIO pins are used for I2C communication. Another pin is allocated for the
interrupt handler, leaving 23 GPIO pins available for the user
 

alexburcea

Moderator
Staff member
Hi,
Assuming you have V2.x, there is an interrupt pin connected to Raspberry PI GPIO11. But I am not sure that is your problem because the inputs are filtered out for using AC signals. It is hard to tell you the cutoff frequency of the filter because this depends of the voltage you use for the switch but is not greater than 10Hz. Your 10ms should catch any transition if any (actually the 10ms will overload the Raspberry I2C port, if NodeRED manage to do a request each 10ms). If you see the corresponding LED flashing when you push the button, you should be able to catch that event but if you did not see it, the voltage was too low and/or contact was too fast.
Please let me know what version of the card you use and input voltage.
 

Brecht

New member
Hi Alex,
I'm not sure if we understand eachother correctly, but I'm not really having a problem, I rather like to optimize the communication between the rpi and the HAT's. That is why I informed about the polling solution.
Is there a way to check the version of the card via software? Because the HATs are stacked and it's hard for me to unplug my installation. My order was in oktober '23 (Order SH-4609). All my digital inputs are working on 24V DC.

Thank you
 

alexburcea

Moderator
Staff member
Hi,

Considering your order date you have 16-inputs V2.0 so you can use internal pullup and interrupt on GPIO11 to optimize the code (access the card only if you get interrupt on GPIO11).

Alex.
 

indygreg

New member
i have the V4 8-Layer Stackable HAT and had a similar question to brecht. does this mean i could use the node red raspberry pi gpio node as an input to your IOPLUS OPTIn node to effectively trigger a reading when the state of the pin changes? i am new to node-red if i read this right would you mind walking through how to set this up?
 

alexburcea

Moderator
Staff member
Theoretically yes, this means the raspberry GPIO26 is connected to the local processor but we need to change the firmware for that.
Give me few days to make a new firmware release for Home Automation HAT and I will let you know.
 

indygreg

New member
Theoretically yes, this means the raspberry GPIO26 is connected to the local processor but we need to change the firmware for that.
Give me few days to make a new firmware release for Home Automation HAT and I will let you know.
(i just fell in love with this product) :)
 

alexburcea

Moderator
Staff member
Hi,

Please update card firmware , instructions here.
Now, if opto inputs are changing the GPIO26 will go low for 10ms. We did this way because we need to release the pin for the button which is connected also here.
You can use "rpi gpio-in" node. Please set the debounce interval less than 10ms (5 is a good number).
The node will generate 2 events per opto change but you can discard one.
Let me know if you have any questions.
 

indygreg

New member
perhaps i am doing something wrong?



greg@PI1:~/ioplus-rpi/update $ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
(use "git add <file>..." to include in what will be committed)
../ioplus
../node-red/node_modules/
../node-red/package-lock.json
../node-red/package.json

nothing added to commit but untracked files present (use "git add" to track)
greg@PI1:~/ioplus-rpi/update $ ./update 0
bash: ./update: cannot execute: required file not found
 

indygreg

New member
so i updated the hat and tried this flow. when connecting opto1 to gnd i get a response sometimes but other times not. here is my nodered flow
[
{
"id": "4b34ee84d0c70aa3",
"type": "IOPLUS OPT in",
"z": "5030df393faa6a5a",
"name": "",
"stack": "1",
"channel": "1",
"payload": "payload",
"payloadType": "msg",
"x": 640,
"y": 380,
"wires": [
[
"337a055dfafea2fd"
]
]
},
{
"id": "337a055dfafea2fd",
"type": "debug",
"z": "5030df393faa6a5a",
"name": "debug 3",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 860,
"y": 380,
"wires": []
},
{
"id": "bd692008508c49c0",
"type": "rpi-gpio in",
"z": "5030df393faa6a5a",
"name": "",
"pin": "26",
"intype": "tri",
"debounce": "5",
"read": true,
"bcm": true,
"x": 210,
"y": 380,
"wires": [
[
"1db09222d32df279",
"bababaebece77869"
]
]
},
{
"id": "1db09222d32df279",
"type": "debug",
"z": "5030df393faa6a5a",
"name": "debug 10",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 390,
"y": 320,
"wires": []
},
{
"id": "bababaebece77869",
"type": "switch",
"z": "5030df393faa6a5a",
"name": "filter for 0",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 420,
"y": 380,
"wires": [
[
"4b34ee84d0c70aa3"
]
]
}
]
 

alexburcea

Moderator
Staff member
The GPIO26 is a Raspberry pin that can be read or set interrupt on it without any additional card. Please search "Using Raspberry Pi GPIO pins" on the internet and you will get tons of documentation. The Home Automation Hat is using that pin to inform Raspberry Pi that the state of the optoisolated inputs has changed since the last time they were read.
 

Brecht

New member
Hi,

Please update card firmware , instructions here.
Now, if opto inputs are changing the GPIO26 will go low for 10ms. We did this way because we need to release the pin for the button which is connected also here.
You can use "rpi gpio-in" node. Please set the debounce interval less than 10ms (5 is a good number).
The node will generate 2 events per opto change but you can discard one.
Let me know if you have any questions.

Hi Alex, everyone,

Can someone help me with the update? I've followed the instructions, but my Linux knowledge is limited.

Code:
admin@rpi-automationhat-1:~/8inputs-rpi $ cd /home
admin@rpi-automationhat-1:/home $ git clone https://github.com/SequentMicrosystems/ioplus-rpi.git
fatal: could not create work tree dir 'ioplus-rpi': Permission denied
admin@rpi-automationhat-1:/home $ sudo git clone https://github.com/SequentMicrosystems/ioplus-rpi.git
Cloning into 'ioplus-rpi'...
remote: Enumerating objects: 697, done.
remote: Counting objects: 100% (449/449), done.
remote: Compressing objects: 100% (277/277), done.
remote: Total 697 (delta 243), reused 328 (delta 162), pack-reused 248 (from 1)
Receiving objects: 100% (697/697), 1.68 MiB | 4.08 MiB/s, done.
Resolving deltas: 100% (356/356), done.
admin@rpi-automationhat-1:/home $ cd ioplus-rpi/update/
admin@rpi-automationhat-1:/home/ioplus-rpi/update $ dir
README.md  fwrevhist.md  rockupd  update  update64
admin@rpi-automationhat-1:/home/ioplus-rpi/update $ ~/ioplus-rpi/update$ ./update 6
-bash: /home/admin/ioplus-rpi/update$: No such file or directory
admin@rpi-automationhat-1:/home/ioplus-rpi/update $ ~/ioplus-rpi/update $ ./update 6
-bash: /home/admin/ioplus-rpi/update: Is a directory
admin@rpi-automationhat-1:/home/ioplus-rpi/update $ ~/ioplus-rpi/update$ ./update64 6
-bash: /home/admin/ioplus-rpi/update$: No such file or directory

As far as I understand, I managed to download the update from git and checked the contents of the created folder, but for some reason I don't manage to start the update.
FYI my Automation HAT is at address 6

Also, @alexburcea, will you create this feature for the other input HAT's aswell? It would be nice if I could apply the same solution to my 16input HAT's.

Thanks!
 

alexburcea

Moderator
Staff member
Hi,

Did you need to update the Home Automation HAT firmware?
If this is the case and you already have the "ioplus-rpi" folder on your Raspberry you just need to go to that folder "cd ioplus-rpi/" and then run a "git pull" command to get the last version. The last step is to go to the update folder "cd update/" and then run the "./update 6" command to update the card with stack level 6.
The current version of the 16 inputs does this by default because it is done with an io-expander which does that by default.
 
Last edited:

Brecht

New member
Hi,

Did you need to update the Home Automation HAT firmware?
If this is the case and you already have the "ioplus-rpi" folder on your Raspberry you just need to go to that folder "cd ioplus-rpi/" and then run a "git pull" command to get the last version. The last step is to go to the update folder "cd update/" and then run the "./update 6" command to update the card with stack level 6.
The current version of the 16 inputs does this by default because it is done with an io-expander which does that by default.
Hi Alex,

How do I know I need to update the Home Automation HAT firmware?

I tried to update it anyway, but ran into an 'Bootloader no answer!!!' error. What could be the cause?
Internet connection is no problem, otherwise I wouldn't be able to do the git pull

Code:
admin@rpi-automationhat-1:~/ioplus-rpi $ ioplus -v
ioplus v1.2.8 Copyright (c) 2016 - 2023 Sequent Microsystems

This is free software with ABSOLUTELY NO WARRANTY.
For details type: ioplus -warranty
admin@rpi-automationhat-1:~/ioplus-rpi $ git pull
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
remote: Enumerating objects: 162, done.
remote: Counting objects: 100% (162/162), done.
remote: Compressing objects: 100% (91/91), done.
remote: Total 142 (delta 99), reused 77 (delta 48), pack-reused 0 (from 0)
Receiving objects: 100% (142/142), 43.46 KiB | 2.29 MiB/s, done.
Resolving deltas: 100% (99/99), completed with 16 local objects.
From https://github.com/SequentMicrosystems/ioplus-rpi
   b9f7d9a..c5b3494  master     -> origin/master
Updating b9f7d9a..c5b3494
Fast-forward
 .gitignore                                |    7 +
 Makefile                                  |    2 +-
 domoticz/libioplus/__init__.py            |   28 +-
 python/{ioplus => }/LICENSE               |    0
 python/Makefile                           |   14 +
 python/README.md                          |  221 +++++++++++--
 python/ioplus/README.md                   |  179 -----------
 python/ioplus/setup.py                    |   20 --
 python/{ioplus => }/libioplus/__init__.py |  113 +++++--
 python/setup.cfg                          |    2 +
 python/setup.py                           |   29 ++
 src/comm.c                                |   14 +
 src/comm.h                                |    1 +
 src/gpio.c                                |  176 +++++++++++
 src/ioplus.c                              | 1248 +++++++++++++++++++++++++++++++++++++-----------------------------------
 src/ioplus.h                              |   42 ++-
 update/update                             |  Bin 18124 -> 18108 bytes
 update/update64                           |  Bin 23784 -> 23440 bytes
 18 files changed, 1231 insertions(+), 865 deletions(-)
 rename python/{ioplus => }/LICENSE (100%)
 create mode 100644 python/Makefile
 delete mode 100644 python/ioplus/README.md
 delete mode 100644 python/ioplus/setup.py
 rename python/{ioplus => }/libioplus/__init__.py (80%)
 create mode 100644 python/setup.cfg
 create mode 100644 python/setup.py
admin@rpi-automationhat-1:~/ioplus-rpi $ cd update/
admin@rpi-automationhat-1:~/ioplus-rpi/update $ sudo ./update 6
You are ready to update the firmware on your board.
Your Raspberry Pi must be connected to the internet.
We strongly recommend to disconnect all outputs from the board since they can change state unpredictably.
Type "yes" (without quotes) to continue or anything else to quit:
yes
Bootloader no answer!!!
 
Top