[GPIO] New GPIO Binding for OH3

Great, thanks!

It should be possible to control all pins. For more information see: pigpio library

The old gpio binding was not removed for evil motives. It simply does not any longer works with the new techniques used in OH3. To still have the possibility to control GPIO pins with OH3 I created this binding. You can see this new binding as an update to the old one. If the current install instructions are to hard to follow, just wait for the next point release of openHAB

I have a couple of door contacts connected to my RP3B+. I have wired GPIO 5 and 6 through the contacts to ground. The old configuration I had in OH2 was

Contact Window_FF_Kitchen       "Kitchen Door Contact [%s]"	<door>	(FF_Kitchen, Windows, gMagicMirror)	{ gpio="pin:5 activelow:no" }
Contact Window_FF_Frontdoor     "Front Door Contact [%s]"	<frontdoor>	(FF_Corridor, Windows, gMagicMirror)	{ gpio="pin:6 activelow:no" }

I have setup a GPIO thing with 2 input channels and GPIO pins 5 and 6 linked in OH3. Both like this:

But I cannot see any change in the item. They both stay at NULL. Any suggestions on how to trouble shoot this would be appreciated.

1 Like

Try:
ssh to openHAB and use the following command for GPIO 6:

pigs m 6 r

http://abyz.me.uk/rpi/pigpio/pigs.html#M/MODES

This command set GPIO 6 to INPUT MODE, propably
GPIO Binding not set the corect MODE of GPIO.

When you use the following command first:

pigs mg 6

you can see:
1 or 0
It means MODE of GPIO 6.
or command:

pigs r 6

show status GPIO.

http://abyz.me.uk/rpi/pigpio/pigs.html#R/READ

After setting GPIO to right mode you can see any change in the Item.

The second problem may be that GPIO Binding works with Items Switch not Contact.

Thing and Items file example:

The third is you have the pigpio daemon installed and is the daemon functional even after a restart.

Use command:

sudo systemctl status pigpiod

if answer is something like:

● pigpiod.service - Daemon required to control GPIO pins via pigpio
Loaded: loaded (/lib/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/pigpiod.service.d
└─public.conf
Active: active (running) since Wed 2021-02-17 13:06:50 CET; 46min ago
Process: 375 ExecStart=/usr/bin/pigpiod (code=exited, status=0/SUCCESS)
Main PID: 396 (pigpiod)
Tasks: 6 (limit: 2181)
CGroup: /system.slice/pigpiod.service
└─396 /usr/bin/pigpiod

The normal way to start the pigpio library during boot.

Yes! Thank you! I needed to set the GPIO’s to inputs. I also changed the door contact items to switches. I found that if I altered the debounce in OH and saved the thing, I would have to go into the command line again and set the GPIO to input again.
Thank you again for your help.

Thank’s for your job.
I have some problems with the inputs:

  1. Configuring the inputs through the Channels the command “pigs mg 6” returns 1 (Output) and it seems that the pull down resistor is set, while giving the command “pigs m 6 r” it seems that the pull up resistor is set. That’s right? Is it possible to set the pull up resistance for the inputs?
  2. I set the delay time to 500 ms, but from the log I see that the input changes state in 5 ms. How can I increase the debounce time to avoid noise on the inputs?
  3. Like Ben_Douglas, every time I save the thing I also have to give the command “pigs m 6 r”. Is it possible to solve this problem?

Thanks for your help!

I thought the delay time was the debounce time. I have been increasing the delay time in an attempt to mitigate the false readings I have been getting. I can experiment more this weekend. The ability to change GPIO settings from within the binding as suggested by @gab75 would be greatly appreciated.

Hi . You need
Rule with command line script.

ssh to OpenHAB:

sudo nano /etc/openhab/scripts/set_Input.sh

Type:
pigs m 6 r

Ctrl x
Y (Save file)

sudo chmod 755 /etc/openhab/scripts/set_Input.sh

Main UI:
settings
Bindings
Add
Exec Binding
Install

Main UI
Rules
Add
Type name “XXX”
Add Trigger
System Event
choose 80 - Things initialized
done
Add Action
Run Script
Rule DSL

copy text:

executeCommandLine("/etc/openhab/scripts/set_Input.sh")
logInfo(“XXX.rules”, “Input set”)

Save
Back

When Run the script manualy
in openHAB Log Viewier (http://192.168.XX.XX:9001/) You can see:

Input set

After restart OpenHAB in openHAB Log Viewier You can see:
Input set

If you need set the GPIO to input Mode using “pigs” in Main UI, simple Run script manualy in Main UI


GPIO Output Mode pull up/down:

http://abyz.me.uk/rpi/pigpio/pigs.html#PUD

In any case, if you connect the GPIO pin to the VCC (3.3V) without changing the Mode, then a current (35 mA) flows through the GPIO.
And that’s actually why Remote GPIO Input seems to show someone something even without changing the Mode.

1 Like

Thanks for your quick reply!
I tried your solution and it seems to work fine. The debounce time now also works correctly.
I hope that in the final version of GPIO Binding this procedure will be automatic within the I/O configuration.

Thank you for developing this binding. But i have one question: As far as i understand the code (i am no coding expert :slight_smile: ), actually there is only the possibility for “on / off” commands. What i am looking for is the possibility of sending PWM requests to pigpio. Is there an easy way to do this or is this feature planned?

1 Like

That works thank you. I had some trouble getting the EXEC command in the script to work. I just created EXEC thing in the GUI and added the command to that. Then make a Running item for that thing and send it an ON in the rule instead of executing a script.
Thanks again for the help.

@jojo100 you may want to have a look at the RaspberryPi PWM Binding I wrote some time ago. It supports hardware and software PWM.

Thank you for the hint at your PWM Binding. looks interesting for me, despite of the need for running openhab with root privileges. Maybe I’ll give the exec-binding a try.

Thank you very much for this great Add On.

I had also Problems with the Input Signals and that I could not set a pull up or down resistor.

Because of this I added a pull up or down option to the code. They I saw the Input and Output were switched configured into JPigpio. I also fixed this by using the Constants of JPigpio. I put the changed files here: https://wordpressvonmorgen.dd-dns.de/pigpio/

Hopefully you will take over this changes in the Add on.

Best regards from Germany,
Sjoerd Takken

Thanks @nbauer,

I have got this working today and its running normal on the new OH3. I wanted to ask you if you have found a solution to fix the bug when restarting the Raspberry Pi ? as it reboots it doesn’t reset the pins. Everything stays ON When rebooting my RPi unlike the old GPIO binding for previous versions of OH were it reset the pins after complete reboot.

If anyone solved this issue please share and post to help.

Thanks you all in advanced.

I’m so glad you’ve made this binding, thanks!

I had some trouble getting the binding to work after installing. Posting incase this is useful for anyone else with same problem.

I’m using OpenHabian on a RPI3B+ on build 3.1.0.M2.

I was receiving a communication error using PIGPIO on the local RPI. I tried using localhost, 127.0.0.1, the IP address of the RPI itself, but none worked. I noticed that PIGPIO was only listening on IPv6 ::1. I stuck that into the binding config and it came straight up.

Thanks again to the creator for the work! :slight_smile:

1 Like

Hello, would this be fixed in next Version.

upgraded to the latest openhab 3.0.1 and i dont see gpio binding anywhere
How can i install it?Is it included or do i have to download it from somewhere?

Look here: GPIO - Bindings | openHAB
You have to install the Binding manually.

Hello everyone.

If for some reason the local installation (OpenHAB on a RPI3B+, build 3.0.1. or 3.1.0.M2) of GPIO Binding

does not work properly here is the installation procedure:

I will try to explain the procedure.
The installation consists of two steps.

  1. You need to install the PIGPIO daemon first (takes care of communication with GPIO):
  • ssh to OpenHAB and type
    sudo apt-get install pigpiod

  • then type
    sudo mkdir -p /etc/systemd/system/pigpiod.service.d/

  • then type
    sudo nano /etc/systemd/system/pigpiod.service.d/public.conf

  • paste or write to a file
    [Service]
    ExecStart=
    ExecStart=/usr/bin/pigpiod

  • Ctrl x
    Y (Save file)

  • then type
    sudo systemctl daemon-reload

  • then you can test if the local PIGPIO daemon is running (optional test)
    sudo systemctl restart pigpiod
    sudo systemctl status pigpiod


answer is something like:

● pigpiod.service - Daemon required to control GPIO pins via pigpio
Loaded: loaded (/lib/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/pigpiod.service.d
└─public.conf
Active: active (running) since Wed 2021-02-17 13:06:50 CET; 46min ago
Process: 375 ExecStart=/usr/bin/pigpiod (code=exited, status=0/SUCCESS)
Main PID: 396 (pigpiod)
Tasks: 6 (limit: 2181)
CGroup: /system.slice/pigpiod.service
└─396 /usr/bin/pigpiod


 the normal way to start the pigpio library.

  • Then type command
    (to automate running the daemon at boot time)
    sudo systemctl enable pigpiod


answer is something like:
Created symlink /etc/systemd/system/multi-user.target.wants/pigpiod.service → /lib/systemd/system/pigpiod.service

  • If you want to be sure that the PIGPIO daemon will be active even after a reboot type (optional test)
    sudo reboot

After restarting OpenHAB

  • ssh to OpenHAB and type
    sudo systemctl status pigpiod


answer is something like:

● pigpiod.service - Daemon required to control GPIO pins via pigpio
Loaded: loaded (/lib/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/pigpiod.service.d
└─public.conf
Active: active (running) since Wed 2021-02-17 13:06:50 CET; 46min ago
Process: 375 ExecStart=/usr/bin/pigpiod (code=exited, status=0/SUCCESS)
Main PID: 396 (pigpiod)
Tasks: 6 (limit: 2181)
CGroup: /system.slice/pigpiod.service
└─396 /usr/bin/pigpiod

The normal way to start the pigpio library during boot.

Note:
The procedure is the same for both versions of OpenHAB (build 3.0.1. or 3.1.0.M2).

  1. The second step is installation GPIO Binding
    (takes care of communication with the PIGPIO daemon which you installed in the first step),
    you have three options:

a) manual installation:

  • ssh to OpenHAB and type
    openhab-cli console

Password: (default is “habopen” or “your password”)

the answer


   |_|       3.0.1 - Release Build


 answer
Bundle ID: XXX

  • then type
    bundle:start org.openhab.binding.gpio

  • then type
    logout

b) download file from
https://openhab.jfrog.io/artifactory/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.gpio/3.1.0-SNAPSHOT/org.openhab.binding.gpio-3.1.0-SNAPSHOT.jar

  • and copy it to
    \192.168.XXX.YYY\openHAB-addons
  • wait a moment
    and then you can configure GPIO via the OpenHAB Main UI:

Things
Add (+)
GPIO Binding
Add Manually (Pigpio Remote)


Create Thing

c) normally install GPIO binding via OpenHAB Main UI
this option only applies to 3.1.x bundle users (not for 3.0.1)

Main UI:
Settings
Bindings
Add (+)
GPIO Binding
Install

I hope this helps

:slight_smile:

4 Likes

Check out the following link for setting GPIO in config.txt

GPIO control in config.txt - Raspberry Pi Documentation

Add this to the [all] section in the /boot/config.txt
I added gpio=17,23,24=ip and all of those pins were set to input after boot.

There are a lot of options you can do at boot.

  • ip - Input
  • op - Output
  • a0-a5 - Alt0-Alt5
  • dh - Driving high (for outputs)
  • dl - Driving low (for outputs)
  • pu - Pull up
  • pd - Pull down
  • pn/np - No pull

Hope this helps.

It does not seem to work on a reboot, just a boot