Page 1 of 1
How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Wednesday 07 March 2018 19:42
by OldPensionado
Hi guys,
I'm struggling with my RPi, Domoticz (V3.8153), and the plugin GPIO-SYSFS-Switches. And up to this moment my RPi is winning...
What's the case/problem?
I would like to read an input which changes between 0 V and 3V and see the changes reflected in a Domoticz switch/light.
I did an update of Domoticz (from V3.5877 to V3.8153). I was using an older Python version (2.7.9) and updated that as well to Python3 V3.4.2.
After this update I found some errors in the Domoticz logfile (about "Failed dynamic library load, install the latest libpython3.x lib that is available for your platform"). This was finally solved by completely removing Python and a fresh reinstall. At the end I had to install python3-dev in order to get no errors in the logfile. Took me a lot of hours.
Then I decide to install plugin GPIO-SYSFS-Switches from Github. Prior to this I had some problems to stop and disable GPIOinput.service.
After installing the GPIO-SYSFS plugin I don't know how to start or initialize this plugin. Also I was unable to find out where and how to declare the IO-pins (BCM-numbers).
Reading all kinds of posts for two days now doesn't help me till now.
Since I am not very familiar with Linux and so, I would heavily appreciate when you explicitly mention the folder/directory where a specific file resides. Also specifying the precise Raspbian command would be very helpful.
By the way: I know how to declare a (virtual) switch in Domoticz and I did use GPIOinput where the Domoticz description field has to contain for instance "%pin=23".
I sincerely hope someone is out there, has the answers and will share them with me.
Thanks in advance!
[Edit: Forgot to mention that I successfully installed raspi-gpio too. I have tried "$ sudo raspi-gpio set 4 ip pd" but I'm afraid that I need some more information or tips how to go further.]
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Sunday 11 March 2018 19:06
by ubee
Hm, I'm a bit confused here. I doubt you need to enable this python plugin to make this work. In order to just have a switch reflecting the status of an input pin, you should first of all add a new HW device - Generic sysfs GPIO. You also need to configure which pins you should use for this system. See this post for details:
http://www.domoticz.com/forum/viewtopic.php?t=17688
Once you have done this, you just create a new switch device on the Switch tab. Use the manual option in the upper left corner. There you can select which pin to use (if you have many input pins) etc.
You don't need the GPIOinput.service either. That was a fix made by me for polled input. The built in GPIO sysfs support si the only thing you need. It works well. Also forget the virtual switches and %pin etc. That belongs to the GPIOinput.service as well.
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Sunday 11 March 2018 21:53
by OldPensionado
@ubee: thanks for the reply!
What I did:
To check: $ sudo raspi-gpio get 4, which results in: GPIO 4: level=0 fsel=0 func=INPUT. Looks good to me.
In Domoticz I added a new piece of hardware in Setup > Hardware, type Generic sysfs GPIO. And the result was looking good.
However, as mentioned by @elgringo in the topic
http://www.domoticz.com/forum/viewtopic.php?t=17688
Note:
When you add the "Generic sysfs GPIO" hardware "Auto configure devices" is selected by default. In case you want to manually configure your exported sysfs-gpio devices you must uncheck "Auto configure devices" in the "Setup - hardware - Generic sysfs GPIO" menu.
I didn't see any "Auto configure devices" to check or to uncheck.
What did I do wrong? Did I forgot something in the definition using raspi-gpio?
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Monday 12 March 2018 7:00
by ubee
Well, I see this check box in my configuration. This is enabled, but to be honest I don't know what this is used for. In my case this is enabled and I add my switches manually on the switches tab. I think this thread should be moved to Bugs and problems. Maybe you can make a new post in that forum and refer to this. Then the guy behind sysfs GPIO might see it and can guide you further.
- Capture.PNG (133.31 KiB) Viewed 10404 times
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Monday 12 March 2018 17:49
by OldPensionado
What I did:
Code: Select all
sudo raspi-gpio set 4 ip pu
sudo echo "4" > /sys/class/gpio/export
echo "1" | sudo tee -a /sys/class/gpio/gpio4/active_low
echo "both" | sudo tee -a /sys/class/gpio/gpio4/edge
This is I think exactly (well, ok, I used gpio4 in stead of gpio26) the same as elgringo did in this post
viewtopic.php?f=4&t=17688&p=140828&hili ... te#p140828
And still no checkbox for Autoconfigure devices.
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Tuesday 13 March 2018 15:36
by ubee
Maybe you should try another web-browser. This sounds weird, but sometimes the browser creates problems with Domoticz. I think it is cache or cookie related. For instance, try with Edge to see if this helps.
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Tuesday 13 March 2018 16:00
by OldPensionado
Yes, yes!
I tested with Chrome and voilĂ : the Auto configure devices checkbox and Debounce field both appear! Since I prefer to keep using Firefox I cleared the cache and both fields are visible now in Firefox too. Somewhere on this forum I read a post about clearing the browser's cache.
Thank you again. Now I can continue with my little project of defining an input and so on.
I'll report later.
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Wednesday 14 March 2018 16:34
by OldPensionado
Since my problem about the invisible checkboxes "Auto configure devices" was solved by @ubee I did a lot of experiments with defining gpio-pins and trying to connect to them within Domoticz. But so far no success, unfortunately.
I am afraid that I'm doing something seriously wrong in my pin definition. I've tried (again) to define inputs as in my previous post
http://www.domoticz.com/forum/viewtopic ... 01#p174403.
Somewhere on the forum I saw that the double quote sign (") was not used; I've tried this without any success.
What I need to know is:
- is it necessary to use a script which runs at boottime of the RPi?
- or can I enter these commands in my putty-window?
- what kind of script should I use (Python?)
- in which startup file should this script be invoked?
- when is it necessary to reboot the RPi?
- how could I check whether the commands have been executed correctly?
- where can I find what these commands actually do (or what results should be visible)?
- which part of the Domoticz manual should I read more in detail?
Well, you see, being old still doesn't mean you know a lot...
Thanks in advance!
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Wednesday 14 March 2018 22:01
by ubee
You need to configure the pins at boot. I have made an update to /etc/rc.local. In my case I have defined a shell script with the following commands and just execute this script by the end of rc.local.
Code: Select all
#! /bin/sh
#-----------------------------------------------------------------------------
# Init sysfs GPIO ports
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# unexport
#
#echo 4 > /sys/class/gpio/unexport
#echo 12 > /sys/class/gpio/unexport
#echo 13 > /sys/class/gpio/unexport
#-----------------------------------------------------------------------------
# export
#
echo 17 > /sys/class/gpio/export
echo 18 > /sys/class/gpio/export
echo 22 > /sys/class/gpio/export
echo 10 > /sys/class/gpio/export
echo 9 > /sys/class/gpio/export
echo 11 > /sys/class/gpio/export
echo 8 > /sys/class/gpio/export
echo 7 > /sys/class/gpio/export
#-----------------------------------------------------------------------------
# Set direction = in
#
# echo in > /sys/class/gpio/gpio4/direction
echo out > /sys/class/gpio/gpio17/direction
echo out > /sys/class/gpio/gpio18/direction
echo out > /sys/class/gpio/gpio22/direction
echo out > /sys/class/gpio/gpio10/direction
echo out > /sys/class/gpio/gpio9/direction
echo out > /sys/class/gpio/gpio11/direction
echo out > /sys/class/gpio/gpio8/direction
echo out > /sys/class/gpio/gpio7/direction
#-----------------------------------------------------------------------------
# Set active_low = 0 (false)
#
# echo 0 > /sys/class/gpio/gpio4/active_low
echo 1 > /sys/class/gpio/gpio17/active_low
echo 1 > /sys/class/gpio/gpio18/active_low
echo 1 > /sys/class/gpio/gpio22/active_low
echo 1 > /sys/class/gpio/gpio10/active_low
echo 1 > /sys/class/gpio/gpio9/active_low
echo 1 > /sys/class/gpio/gpio11/active_low
echo 1 > /sys/class/gpio/gpio8/active_low
echo 1 > /sys/class/gpio/gpio7/active_low
#-----------------------------------------------------------------------------
# Set edges = none
#
# echo none > /sys/class/gpio/gpio4/edge
#-----------------------------------------------------------------------------
# Set pullups
#
# raspi-gpio set 4 pu
#raspi-gpio set 11 dl
#raspi-gpio set 12 dl
#-----------------------------------------------------------------------------
I have put this in a file
/home/pi/sysfs_init.sh
and execute this by adding the following line by the end of /etc/rc.local
/home/pi/sysfs_init.sh
Please make sure you make this file executable by the following command
chmod 750 sysfs_init.sh
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Saturday 05 January 2019 0:02
by peterjoosen
Hi everyone,
I'm struggling with the configuration of the GPIO input pins with my raspberry pi3. I configured GPIO 0,1,2,4,5,6,7,8,9 and 10 as inputs in the file: /etc/init.d/domoticz.sh and they all work when I activate the hardware tab (Generic SYSFS GPIO). After a reboot, GPIO 9 and 10 don't react anymore. Disable and re-enable the hardware is necessary to let them work until you reboot again. I tried to test this with a brand new Raspbian Stretch_lite installation with a clean database, but it doesn't help. I also checked the logfile and performed python update (No errors after Python update to version '3.5.3'). Is there a limitation on how many inputs you can use or isn't it possible to use certain GPIO numbers? I will put a text doc with the additional lines used in the domoticz.sh file for declaring the GPIO pins...
Anyone suggestions ?
Please , let me know if you have a solution
Regards,
Peter
Re: How to init GPIO-SYSFS and define inputs using raspi-gpio
Posted: Thursday 23 January 2020 1:26
by HvdW
I have been struggling with GPIO all day.
The post of @ubee is straightforward and works as expected.
The Domoticz
sysfs wiki is a bit confusing in my opinion.
@ubee sets the pin active_low , the Wiki sets the value.