Simple GPIO example

do you mean you cannot switch it off?

I had wired it up incorrectly - thank you though.

1 Like

great. Sorry my earlier reply might have been late but I was on holiday

What if I want to control the LED with a script? Is this possible while using this binding? I want to write a script that turns off the normally on LED when the state of a thing changes.

Hi

Would you happen to know if this process is purely for Raspberry Pi, or can I try it on any Linux based SBC?

(In my case, an ODroid C2 or XU4)

Cheers :smile:

@MDAR I don’t know about support from the GPIO binding, but you could maybe use my MQTTany. Currently the GPIO module only supports RPi but can easily be modified to support other boards if there are Python 3 libraries available to control their GPIOs.

Let me know if you are interested and if you already know of any Python libraries.

1 Like

Thanks Michael.

I have limited knowledge of anything outside of GUI things.
So python is outside of my skill set.

Thanks for the offer.

No I mean I would make the changes. Looks like there is a library. I’ll get to this next, I’m just working on a module for DS18x20 sensors right now. Keep an eye on the github for the odroid support getting added.

@MDAR keep an eye on this issue over on github for updates.

1 Like

I don’t know Python that well either, but when you can see an example of how simply it is, it makes life easier :slight_smile:

So if you want to control the LED via a script, create a simple python script to turn off the LED. Then use the exec binding to call the script in a rule when the state of something changes.

Say you had the LED controlled via GPIO pin 25. First I’d assume (hope) you would be controlling that LED light via a transistor (like a Darlington TIP120 and 220ohm resistor to protect the pin) After installing python (plenty of articles on how to) then you’d create a script that would look something like this:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.OUT)

GPIO.output(25,False)

GPIO.cleanup()

Save to for example: /usr/local/share/gpio25.py

To test execution, simply type this from the command prompt:

python gpio25.py

Your LED should turn off.

If you want to turn on, you can simply send ‘True’ to the GPIO.output command rather than ‘False’ in the script above.

1 Like

Thank you! It was really easy yes :slight_smile:

1 Like

Hi, thanks for this great and simple example.

I am just wondering, if the GPIO Binding is not yet available for OpenHAB3?! Is there any alternative?

Patrick
you may find this recent post interesting

1 Like

yes, I do! I will test the binding within the next days and will let you know how it works! thank you :slight_smile:

1 Like