Page 1 of 2

GPIO port

Posted: Sunday 23 April 2017 15:33
by djdacore
Is it possible to use a GPIO port on a Raspberry Pi as in INPUT?
For example I like to create a doorbell.
If I manually create a switch with function 'doorbell' I can only select the pins as Outputs.

Re: GPIO port

Posted: Sunday 23 April 2017 16:03
by henrivb
yes, install "Generic sysfs gpio" hardware. Before enabeling it do the sysfs settings using a startup shell script. When google you will find how to do it. If you need pullups use raspi-gpio to enable these.

Re: GPIO port

Posted: Sunday 23 April 2017 16:06
by henrivb
Note: Generic sysfs gpio is only availble in the latest beta releases. There is no need for wiringpi.

Re: GPIO port

Posted: Sunday 23 April 2017 16:15
by henrivb
You can also do it using Raspberry's GPIO tough. See domoticz wiki on how to set it up. It works, I have used inputs using both Raspberrys GPIO and Sysfs-gpio. On the longer term Sysfs-gpio will likely replace Rasberrys GPIO.

Re: GPIO port

Posted: Sunday 23 April 2017 17:21
by djdacore
I looked at the installation of 'sysfs' but that's pretty difficult and also I installed the latest Beta version of Domoticz.
Tonight I can take a look at the Wiki how to setup the GPIO port.

Re: GPIO port

Posted: Sunday 23 April 2017 18:18
by henrivb
Below the content of my /etc/init.d/domoticz_sysfs.sh script.I call it from my /etc/init/domticz.sh script. I run domoticz as a daemon. After reboot all sysfs ports should be setup, ready to go. Note that in the example below I have setup 23 inputs (with pullups) and 1 output (gpio12). To setup the pullups I use the raspi-gpio tool. You can install it as follows: "sudo apt-get install raspi-gpio". Once this is done enable the "Generic sysfs gpio" hardware (Setup/Hardware/"Generic sysfs gpio"). Once done, goto the devices tab, you should see all devices that you have exported available for use. By clicking the green arrows you can add and rename the devices you want to use. Now you will see the devices you configured in the "Switches" tab. Please let us know your results.

#! /bin/sh
#-----------------------------------------------------------------------------
# Init sysfs GPIO ports
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# unexport
#
echo 4 > /sys/class/gpio/unexport
echo 5 > /sys/class/gpio/unexport
echo 6 > /sys/class/gpio/unexport
echo 7 > /sys/class/gpio/unexport

echo 8 > /sys/class/gpio/unexport
echo 9 > /sys/class/gpio/unexport
echo 10 > /sys/class/gpio/unexport
echo 11 > /sys/class/gpio/unexport

echo 12 > /sys/class/gpio/unexport
echo 13 > /sys/class/gpio/unexport
echo 14 > /sys/class/gpio/unexport
echo 15 > /sys/class/gpio/unexport

echo 16 > /sys/class/gpio/unexport
echo 17 > /sys/class/gpio/unexport
echo 18 > /sys/class/gpio/unexport
echo 19 > /sys/class/gpio/unexport

echo 20 > /sys/class/gpio/unexport
echo 21 > /sys/class/gpio/unexport
echo 22 > /sys/class/gpio/unexport
echo 23 > /sys/class/gpio/unexport

echo 24 > /sys/class/gpio/unexport
echo 25 > /sys/class/gpio/unexport
echo 26 > /sys/class/gpio/unexport
echo 27 > /sys/class/gpio/unexport

#-----------------------------------------------------------------------------
# export
#
echo 4 > /sys/class/gpio/export
echo 5 > /sys/class/gpio/export
echo 6 > /sys/class/gpio/export
echo 7 > /sys/class/gpio/export

echo 8 > /sys/class/gpio/export
echo 9 > /sys/class/gpio/export
echo 10 > /sys/class/gpio/export
echo 11 > /sys/class/gpio/export

echo 12 > /sys/class/gpio/export
echo 13 > /sys/class/gpio/export
echo 14 > /sys/class/gpio/export
echo 15 > /sys/class/gpio/export

echo 16 > /sys/class/gpio/export
echo 17 > /sys/class/gpio/export
echo 18 > /sys/class/gpio/export
echo 19 > /sys/class/gpio/export

echo 20 > /sys/class/gpio/export
echo 21 > /sys/class/gpio/export
echo 22 > /sys/class/gpio/export
echo 23 > /sys/class/gpio/export

echo 24 > /sys/class/gpio/export
echo 25 > /sys/class/gpio/export
echo 26 > /sys/class/gpio/export
echo 27 > /sys/class/gpio/export
#-----------------------------------------------------------------------------
# Set direction = in
#
echo in > /sys/class/gpio/gpio4/direction
echo in > /sys/class/gpio/gpio5/direction
echo in > /sys/class/gpio/gpio6/direction
echo in > /sys/class/gpio/gpio7/direction

echo in > /sys/class/gpio/gpio8/direction
echo in > /sys/class/gpio/gpio9/direction
echo in > /sys/class/gpio/gpio10/direction
echo in > /sys/class/gpio/gpio11/direction

echo out > /sys/class/gpio/gpio12/direction
echo in > /sys/class/gpio/gpio13/direction
echo in > /sys/class/gpio/gpio14/direction
echo in > /sys/class/gpio/gpio15/direction

echo in > /sys/class/gpio/gpio16/direction
echo in > /sys/class/gpio/gpio17/direction
echo in > /sys/class/gpio/gpio18/direction
echo in > /sys/class/gpio/gpio19/direction

echo in > /sys/class/gpio/gpio20/direction
echo in > /sys/class/gpio/gpio21/direction
echo in > /sys/class/gpio/gpio22/direction
echo in > /sys/class/gpio/gpio23/direction

echo in > /sys/class/gpio/gpio24/direction
echo in > /sys/class/gpio/gpio25/direction
echo in > /sys/class/gpio/gpio26/direction
echo in > /sys/class/gpio/gpio27/direction

#-----------------------------------------------------------------------------
# Set active_low = 0 (false)
#
echo 0 > /sys/class/gpio/gpio4/active_low
echo 0 > /sys/class/gpio/gpio5/active_low
echo 0 > /sys/class/gpio/gpio6/active_low
echo 0 > /sys/class/gpio/gpio7/active_low

echo 0 > /sys/class/gpio/gpio8/active_low
echo 0 > /sys/class/gpio/gpio9/active_low
echo 0 > /sys/class/gpio/gpio10/active_low
echo 0 > /sys/class/gpio/gpio11/active_low

echo 0 > /sys/class/gpio/gpio12/active_low
echo 0 > /sys/class/gpio/gpio13/active_low
echo 0 > /sys/class/gpio/gpio14/active_low
echo 0 > /sys/class/gpio/gpio15/active_low

echo 0 > /sys/class/gpio/gpio16/active_low
echo 0 > /sys/class/gpio/gpio17/active_low
echo 0 > /sys/class/gpio/gpio18/active_low
echo 0 > /sys/class/gpio/gpio19/active_low

echo 0 > /sys/class/gpio/gpio20/active_low
echo 0 > /sys/class/gpio/gpio21/active_low
echo 0 > /sys/class/gpio/gpio22/active_low
echo 0 > /sys/class/gpio/gpio23/active_low

echo 0 > /sys/class/gpio/gpio24/active_low
echo 0 > /sys/class/gpio/gpio25/active_low
echo 0 > /sys/class/gpio/gpio26/active_low
echo 0 > /sys/class/gpio/gpio27/active_low

#-----------------------------------------------------------------------------
# Set edges = none
#
echo none > /sys/class/gpio/gpio4/edge
echo none > /sys/class/gpio/gpio5/edge
echo none > /sys/class/gpio/gpio6/edge
echo none > /sys/class/gpio/gpio7/edge

echo none > /sys/class/gpio/gpio8/edge
echo none > /sys/class/gpio/gpio9/edge
echo none > /sys/class/gpio/gpio10/edge
echo none > /sys/class/gpio/gpio11/edge

echo none > /sys/class/gpio/gpio12/edge
echo none > /sys/class/gpio/gpio13/edge
echo none > /sys/class/gpio/gpio14/edge
echo none > /sys/class/gpio/gpio15/edge

echo none > /sys/class/gpio/gpio16/edge
echo none > /sys/class/gpio/gpio17/edge
echo none > /sys/class/gpio/gpio18/edge
echo none > /sys/class/gpio/gpio19/edge

echo none > /sys/class/gpio/gpio20/edge
echo none > /sys/class/gpio/gpio21/edge
echo none > /sys/class/gpio/gpio22/edge
echo none > /sys/class/gpio/gpio23/edge

echo none > /sys/class/gpio/gpio24/edge
echo none > /sys/class/gpio/gpio25/edge
echo none > /sys/class/gpio/gpio26/edge
echo none > /sys/class/gpio/gpio27/edge

#-----------------------------------------------------------------------------
# Set pullups
#
raspi-gpio set 4 pu
raspi-gpio set 5 pu
raspi-gpio set 6 pu
raspi-gpio set 7 pu

raspi-gpio set 8 pu
raspi-gpio set 9 pu
raspi-gpio set 10 pu
raspi-gpio set 11 pu

raspi-gpio set 12 dl
raspi-gpio set 13 pu
raspi-gpio set 14 pu
raspi-gpio set 15 pu

raspi-gpio set 16 pu
raspi-gpio set 17 pu
raspi-gpio set 18 pu
raspi-gpio set 19 pu

raspi-gpio set 20 pu
raspi-gpio set 21 pu
raspi-gpio set 22 pu
raspi-gpio set 23 pu

raspi-gpio set 24 pu
raspi-gpio set 25 pu
raspi-gpio set 26 pu
raspi-gpio set 27 pu

#-----------------------------------------------------------------------------

exit 0

Re: GPIO port

Posted: Sunday 23 April 2017 18:25
by Lebo2d9
you can maybe check this https://github.com/bengtner/GPIOinput

Re: GPIO port

Posted: Monday 24 April 2017 8:02
by henrivb
Lebo2d9 should also be able to use the new "Generic sysfs gpio" hardware type to control the relays connected to output ports the raspberry. The advantage is that wiringpi is no longer needed making the susbsystem more simple. I am looking forward to see reports back of people who use "Generic sysfs gpio" to find out if it is a good replacement for the existing "Raspberry's gpio" hardware type.

Re: GPIO port

Posted: Monday 24 April 2017 8:41
by djdacore
'Henrivb' I used your script, thanks for that. I installed raspi-gpio too, but I have one problem. I can not install the latest Beta version. When I update to the latest Beta version I can not login anymore on the webpage. It gives me the error: Browser Cache refresh failed. Manifest fetch failed (6).
So when I go back to the Stable, it works again.
And to install the 'Generic Sysfs GPIO' I need the latest version.
Do you know what is causing this problem?

Re: GPIO port

Posted: Monday 24 April 2017 9:11
by henrivb
I am also running the latest beta (V3.7373) but did not see that problem. Did you delete you browser cache and reload? If the problem persists we need someone else to step in and help you out. You should be really close in getting it to work now.

Re: GPIO port

Posted: Monday 24 April 2017 9:19
by henrivb
If deleting the browser cache does not help you may rename your existing database (domoticz.db to _domotocz.db ) and restart domoticz so that you start with a new db. Then add the "Generic sysfs gpio" hardware. This should work if all is well. It works for me using chrome IE and edge browsers on windows.

Re: GPIO port

Posted: Monday 24 April 2017 11:07
by djdacore
I deleted the folder 'domoticz' just installed Domoticz again, and restored my database. But I get the same error.
I just posted a new topic about my problem, and see if someone knows what to do.
After I installed the Beta version again, the same problem. So if nobody knows a solution after today, I create a backup of the database, and install a new image of Debian. And after that I restore the DB again.
The strange thing is, that the Beta was working last week, so there is something strange happening.
But I hoped it was something simple

Re: GPIO port

Posted: Monday 24 April 2017 11:51
by henrivb
Did you try: 1. install latest beta (don't restore your database but keep new empty one for a start) 2. add "Generic sysfs gpio" ? 3. test your GPIO inputs ?

Re: GPIO port

Posted: Monday 24 April 2017 13:19
by djdacore
I will first try to start a new Raspbian Image, and install Domoticz on a fresh SD-card. If something goes wrong I can go back fast.
After that I can try to restore the database and see if it's OK.
If not, I know that it is the Database that is causing the problem.
And if it works, I know it's the Domoticz installation itself.
I will test before evening starts and will let you know!

Re: GPIO port

Posted: Monday 24 April 2017 21:08
by djdacore
I started with a new installation of Debian and after that I installed Domotics and all the things you advised above!
All is working now!

The problem is my database, the old one was corrupt I think...
So I configured Pin 4 as Doorbell, and 18 as an Output that is connected with Pushover.

Thanks for all your help!

Re: GPIO port

Posted: Monday 24 April 2017 21:49
by henrivb
Great !

Re: GPIO port

Posted: Saturday 20 May 2017 18:45
by Bikey
henrivb wrote:Below the content of my /etc/init.d/domoticz_sysfs.sh script.I call it from my /etc/init/domticz.sh script. I run domoticz as a daemon. After reboot all sysfs ports should be setup, ready to go. Note that in the example below I have setup 23 inputs (with pullups) and 1 output (gpio12). To setup the pullups I use the raspi-gpio tool. You can install it as follows: "sudo apt-get install raspi-gpio". Once this is done enable the "Generic sysfs gpio" hardware (Setup/Hardware/"Generic sysfs gpio"). Once done, goto the devices tab, you should see all devices that you have exported available for use. By clicking the green arrows you can add and rename the devices you want to use. Now you will see the devices you configured in the "Switches" tab. Please let us know your results.
...
Hi, I started to use the generic sysfs.gpi hardware instead of the "old" "Raspberry's GPIO port" hardware in Domoticz. I got this working without using the sysfs.sh script, even after reboot. Now thought to use your example initiation script, but don't understand the sequence.

From Google I understand, that you should:
Export
Change the ports
Unexport.

However in your script you do just do
Unexport
Export
Change the ports?

Is that Ok?

Re: GPIO port

Posted: Saturday 20 May 2017 22:14
by Bikey
I'm having a strange thing, the "edge" command seems not to be persistant after an "unexport":
e.g.

Code: Select all

pi@RPI ~ $ echo 25 > /sys/class/gpio/export
pi@RPI ~ $ echo both > /sys/class/gpio/gpio25/edge
pi@RPI ~ $ cat /sys/class/gpio/gpio25/edge
both
pi@RPI ~ $ echo 25 > /sys/class/gpio/unexport
Ok, so all things seems Ok, but then if I check:

Code: Select all

pi@RPI ~ $ echo 25 > /sys/class/gpio/export
pi@RPI ~ $ cat /sys/class/gpio/gpio25/edge
none
What am I doing wrong here?

Re: GPIO port

Posted: Tuesday 23 May 2017 22:12
by henrivb
Why are you doing the "unexport" ? by doing that you will loose the previous settings of the gpio port.

Re: GPIO port

Posted: Tuesday 23 May 2017 22:26
by Bikey
henrivb wrote:Why are you doing the "unexport" ? by doing that you will loose the previous settings of the gpio port.
So it seems ;-) I thought that was necessary to give control back to the system?
Why does your script start with an "unexport"?