HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Raspberry Pi GPIO/SPI/I2C => Topic started by: Gene on April 07, 2014, 10:27:44 AM
-
This is a small program you can import in HomeGenie from Configure->Automation section and will add 8 modules that will control Raspberry GPIOs and so any led or relay connected to them.
Instructions:
1) enter the RaspberrySharp group in Automation section then from Actions menu choose Import Program and select the attached hgx file;
2) after importing the program, click it in the list and go to Edit Source Code, then from Actions menu select the Update option (this is required only the first time a new program is imported):
(http://www.homegenie.it/docs/images/rpi/hg_rpigpio_01.jpg)
3) go back to the program list and click again the GPIO program, that will now display configuration options:
(http://www.homegenie.it/docs/images/rpi/hg_rpigpio_02.jpg)
Each GPIO can be configured as input (IN), output (OUT) or can be disabled (OFF).
GPIOs configured as IN are mapped to a Sensor module with a Status.Level field displaying current pin level (0, 1).
GPIOs configured as OUT are mapped to a Switch module that can be controlled with on/off commands.
After changing the configuration it is required to disable and re-enable the program in order to make it load the new settings.
Program enabling/disabling can be done by simply clicking on the rounded button you see to the right side of the list.
4) go back to the Configure->Group and Modules section and now you can add the GPIOs modules to a Control group:
(http://www.homegenie.it/docs/images/rpi/hg_rpigpio_03.jpg)
5) go back to the Home->Control section and you will now able to control the GPIO connected device =)
(http://www.homegenie.it/docs/images/rpi/hg_rpigpio_04.jpg)
Note that if in the system there are other applications that are using the GPIOs allocated by the program, it will stop with an error. In this case, you have to set already allocated GPIOs to OFF.
If you have enabled the Raspberry Pi GPIO interface from Configure->System and Interfaces, disable it since it is deprecated and probably not even working in latest HG release.
EDIT1: Updated GPIO program hgx that now let user customize pins as input or output (2014-04-08 00.22)
-
(run video full screen to see annotations)
https://www.youtube.com/watch?v=bpZ5Y2UqBUc (http://www.youtube.com/watch?v=bpZ5Y2UqBUc#)
-
The DHT-11 temperature sensor doesn' t work anymore. I have Set GPIO 4 to IN. But it only reads High.
Any ideas.
Thanks
-
Set it to OFF indeed.
Cheers,
g.
-
I have it set to off. I reset both programs and nothing changed. When I put the web service call in the web browser, to retrieve the temp it says " { 'ResponseValue' : '' } "
-
Well.. on my configuration (hg r371), leaving GPIO program as is, the DHT is still working.
What version of HG are you running?
Did you try restarting the DHT-11 program?
If still not working dunno how to help any further.
g.
-
Is there a way to enable the Raspberry Pi's pullup or pulldown resistor on a GPIO pin that is configured for input? I have a switch connected to one of my input pins. When the switch is closed it consistently shows a Status.Level of 0. But when the switch is open the Status.Level fluctuates between 0 and 1.
-
The GPIO program does not offer any parameter for that at the moment.
You can either change the source code by adding some hard-coded instruction or extend the GPIO program in order to offer a new user definable configuration parameter "PinResistor" for each pin.
If you look at line 31 of the source code you see:
configuration[p] = new InputPinConfiguration(PinMapping.ToProcessor(pc.Pin));
you can add an hard-coded line like this:
configuration[p] = new InputPinConfiguration(PinMapping.ToProcessor(pc.Pin));
configuration[p].Resistor = PinResistor.PullUp;
this will configure every input pin as pullup.
Cheers,
g.
-
Thanks Gene. I used this code
((InputPinConfiguration)configuration[p]).Resistor = PinResistor.PullUp;
since the Resistor property is on the InputPinConfiguration class but not its base class. Now my switch state is being read reliably.
-
Anyone succeed in getting the DHT-11 module to work?
I can´t make it work(r400). The Adafruit example in Python works when I stop Homegenie
I don´t have the GPIO module activated.
Any Clues?
-
Is there any easy way to configure the GPIO outputs to be active low, but still show the outputs correctly in Homegenie (i.e off when off, on when on) ?
Im using a 4 relay module connected to the raspberry pi's GPIO ports, but it's inputs are actve low so in homegenie when it shows the output as on it is off etc. I want to use these relays to connect sirens and strobes from my old/existing alarm system so that i can use home genie as the house alarm instead (already have all sensors and PIRs connected via z-wave / x10 and working great!)
Would be nice if it was possible to use "Out+" and "Out-" to configure active high or active low outputs... the same way that the inputs work with pull up/down resistors..
Richie
-
Hi RichieC,
I'll add this functionality to the gpio program.
In the meantime you can edit the gpio program and invert 0/1 values at line 56 (see picture).
Cheers,
g.
-
edit the dht-11 program and try changing the start delay value at line 24 (try values between 80 and 130).
g.
Anyone succeed in getting the DHT-11 module to work?
I can´t make it work(r400). The Adafruit example in Python works when I stop Homegenie
I don´t have the GPIO module activated.
Any Clues?
-
Thanks Gene, would be great if you could add that..
I tried making the change you suggested and this does make the on/off leds on the homegenie switch modules display correctly, but the on/off buttons are still reversed..
Hi RichieC,
I'll add this functionality to the gpio program.
In the meantime you can edit the gpio program and invert 0/1 values at line 56 (see picture).
Cheers,
g.
-
If i also, invert the true/false at lines 85 and 89.. it then works correctly, but when homegenie starts the switches default to on.
Thanks Gene, would be great if you could add that..
I tried making the change you suggested and this does make the on/off leds on the homegenie switch modules display correctly, but the on/off buttons are still reversed..
Hi RichieC,
I'll add this functionality to the gpio program.
In the meantime you can edit the gpio program and invert 0/1 values at line 56 (see picture).
Cheers,
g.
-
Gene,
How can i modify the GPIO program to change the inital state of the switches when it starts? - so that they are on instead of off - so they are off in my case - if that makes sense!?
If i also, invert the true/false at lines 85 and 89.. it then works correctly, but when homegenie starts the switches default to on.
Thanks Gene, would be great if you could add that..
I tried making the change you suggested and this does make the on/off leds on the homegenie switch modules display correctly, but the on/off buttons are still reversed..
Hi RichieC,
I'll add this functionality to the gpio program.
In the meantime you can edit the gpio program and invert 0/1 values at line 56 (see picture).
Cheers,
g.
-
Hi,
Few weeks ago I installed HG on my RPi as a Z-wave gateway. I realized that GPIO can be of great use for adding more switches with relays, and I bought 8 port relay module, and it works great with 100 GPIO Modules.
Now, I consider it so great, that I miss GPIO ports. I found that P5 Header on RPi have 4 more GPIO ports, but it requires some work on soldering. So, I did it, and by default, I can't use it with 100 GPIO Moudules, and I made following changes in the code:
var pinMapping = new List<dynamic>();
// read GPIO configuration
var gpio4 = Program.InputField("GPIO4").Value.ToLower();
var gpio17 = Program.InputField("GPIO17").Value.ToLower();
var gpio18 = Program.InputField("GPIO18").Value.ToLower();
var gpio21 = Program.InputField("GPIO21").Value.ToLower();
var gpio22 = Program.InputField("GPIO22").Value.ToLower();
var gpio23 = Program.InputField("GPIO23").Value.ToLower();
var gpio24 = Program.InputField("GPIO24").Value.ToLower();
var gpio25 = Program.InputField("GPIO25").Value.ToLower();
var gpio28 = Program.InputField("GPIO28").Value.ToLower();
var gpio29 = Program.InputField("GPIO29").Value.ToLower();
var gpio30 = Program.InputField("GPIO30").Value.ToLower();
var gpio31 = Program.InputField("GPIO31").Value.ToLower();
// add configured GPIOs to a list that will be used to configure the connection
if (gpio4 != "off") pinMapping.Add(new { Config = gpio4, Address = "GPIO4", Pin = ConnectorPin.P1Pin7, Direction = ( gpio4.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio4.StartsWith("!") });
if (gpio17 != "off") pinMapping.Add(new { Config = gpio17, Address = "GPIO17", Pin = ConnectorPin.P1Pin11, Direction = (gpio17.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio17.StartsWith("!") });
if (gpio18 != "off") pinMapping.Add(new { Config = gpio18, Address = "GPIO18", Pin = ConnectorPin.P1Pin12, Direction = (gpio18.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio18.StartsWith("!") });
if (gpio21 != "off") pinMapping.Add(new { Config = gpio21, Address = "GPIO21", Pin = ConnectorPin.P1Pin13, Direction = (gpio21.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio21.StartsWith("!") });
if (gpio22 != "off") pinMapping.Add(new { Config = gpio22, Address = "GPIO22", Pin = ConnectorPin.P1Pin15, Direction = (gpio22.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio22.StartsWith("!") });
if (gpio23 != "off") pinMapping.Add(new { Config = gpio23, Address = "GPIO23", Pin = ConnectorPin.P1Pin16, Direction = (gpio23.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio23.StartsWith("!") });
if (gpio24 != "off") pinMapping.Add(new { Config = gpio24, Address = "GPIO24", Pin = ConnectorPin.P1Pin18, Direction = (gpio24.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio24.StartsWith("!") });
if (gpio25 != "off") pinMapping.Add(new { Config = gpio25, Address = "GPIO25", Pin = ConnectorPin.P1Pin22, Direction = (gpio25.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio25.StartsWith("!") });
if (gpio28 != "off") pinMapping.Add(new { Config = gpio28, Address = "GPIO28", Pin = ConnectorPin.P5Pin3, Direction = (gpio28.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio28.StartsWith("!") });
//if (gpio29 != "off") pinMapping.Add(new { Config = gpio23, Address = "GPIO29", Pin = ConnectorPin.P5Pin4, Direction = (gpio29.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio29.StartsWith("!") });
//if (gpio30 != "off") pinMapping.Add(new { Config = gpio24, Address = "GPIO30", Pin = ConnectorPin.P5Pin5, Direction = (gpio30.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio30.StartsWith("!") });
//if (gpio31 != "off") pinMapping.Add(new { Config = gpio25, Address = "GPIO31", Pin = ConnectorPin.P5Pin6, Direction = (gpio31.EndsWith("out") ? PinDirection.Output : PinDirection.Input), Reversed = gpio31.StartsWith("!") });
When I try to complie it, I get following error:
Connector pin P5-3 is not mapped to processor with pin layout revision 1
And, my expertise stops here. Any help ideas?
-
i tried to gpio module in my homegenie of rpi but it shows the following error
1. MemoryGpioConnectionDriver is only supported on Raspberry Pi
2. at Raspberry.IO.GeneralPurpose.MemoryGpioConnectionDriver..ctor () [0x00000] in :0
3. at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in :0
4. at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in :0
5. at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in :0
6. at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in :0
7. at HomeGenie.Automation.Scripting.ScriptingInstance.RunCode (System.String PROGRAM_OPTIONS_STRING) [0x00000] in :0
8. at HomeGenie.Automation.Scripting.ScriptingInstance.Run (System.String PROGRAM_OPTIONS_STRING) [0x00000] in :0
suggest some channges to do in code
-
what model Pi are you trying to use?
-
Hi Folks,
Could anyone any help me out configure GPIO PIN as IN.
My Setup:
- Installed HG on RPi through .deb package. ( v1.1 beta r525 )
- Installed RaspberryPi GPIO Package in HG.
Able to configure GPIO pin as OUT and toggle switch.
How to do it as INPUT ?
H/w setup pin GPIO17 with button.
In GPIO Modules:
Set GPIO PIN 17 as IN.
Imported that PIN on to a group and Display -Sensor.
Also observed in backend GPIO 17 is configured as "in" direction.
I didn't observe the Level changing on Displayto ON/OFF. It always shows OFF. But through commandline Python script able to catch
button press event.
One more thing.
Can i use python program directly in HomeGenie ProgramCode by setting Progarm Type as Python Script.
Thanks for help
Regards,
Satya
-
I'm running r519 but I doubt this would be any different. I use GPIO25 as an input for my motion sensor.
-
Cool.. Thanks @bkenobi.
I was setting just IN. Changed IN+. Its working.
I will find which setting works for my setup.
I am going to try PIR sensor as IN. I am not sure i can try that or not. any help before experiment will be great to me.
-
I'd just give it a try. It will probably need the pull-up or pull-down set depending on your hardware. Once you get it in there, add a virtual module of type sensor and it should show motion out of the box. I believe I initially had an issue with the sensor being reversed but believe switching pull-up/pull-down fixed it. It's been a while, so I don't remember actually.
-
PIR's work fine on GPIO :) - so long as the output for the PIR is compatible, IE dry contacts :)
I got some external 12v Pir's from china via ebay which work great, I just wind the timer right down and turn the light level whichever way works in day light..
I had to alter the connections from the relay to do what I needed, but domestic alarm pir's would be fine..
I have these wired to gpio's for the outside lights :)
-
My motion sensor is not actually compatible with GPIO's so I had to do a little hacking about. I was initially going to modify the module, but chose an alternate route that works well. The motion sensor is intended for use with a lamp so the output is 110VAC. Since I can't send that to the RPi, I installed a 110VAC relay with a dry contact output. Since the motion sensor must have a load, I installed a 40W bulb inside the garage which toggles on any time motion is sensed (turns into a really nice motion notifier if your in the garage). The dry contacts on the relay go to the GPIO directly. I turned the motion sensor into "test" mode since that triggers for all events rather than using the 1-30 minute timer and only at night. As a result, I can use HG to determine what sensed motion means day or night. If your interested, check out the Advanced Smart Lights code in the APP section. It uses this setup to trigger a chime(s) and/or a light module(s) and can even be over-ridden by a switch if desired.
-
Does anyone else use inverted inputs and have issues with the widget needing to be inverted?
-
today i upgrade to HomeGenie 1.1 beta r525, my gpio on but after restart its off so i must mannualy on it, its normal or not? if normal i want to downgrade the homegenie version, dont like this feature.
and now my homegenie if go home page its show nothing, i must click refresh button.