Control GPIO Voltage

(Adrian Knorr) #1

Hey there,
i want to controll my LED Strip (I have that simple controller, where you can controll the hole strip, not only parts).
But i don’t want only red, green and blue. To mix colors i have to set the output e.g. on GPIO Pin 11 to only 1,6V (50%).
I only see instructions for on and off. How can i get different voltages ?
Like in pigs “pigs p 11 125” (You can controll the pin from 0-255)

Sorry if my english isn’t the best, i am just a student from Germany.

0 Likes

(George Erhan) #2

Hi and welcome to the openHAB community!
There is a binding for the GPIO interface, but AFAIK it will not help you very much.
You can also try the exec binding with some python scripts to do what you require!
Check here, and here!

0 Likes

(Adrian Knorr) #3

Ah, nice idea! Thanks :slight_smile:

0 Likes

(Adrian Knorr) #4

Sorry for the double post.

Can i configure

  • If the switch is getting turned on run command x
  • It the switch is getting turned off run command y
    ?
0 Likes

(George Erhan) #5

If you read the documentation, that is pretty much the idea! I have linked the exec1 binding documentation! Please read the documentation on the openHAB documentation’s page according to your setup!

0 Likes

(Adrian Knorr) #6

Sorry, but i don’t get it how to configure that.

My Item:
Switch Kette “Kette” { channel="exec:command:apc:run }
My Thing:
Thing exec:command:apc [command=“pyhton ~/Desktop/fade.py”]

When i trigger the Switch Kette, nothing is happening. Why?

0 Likes

(Rich Koshak) #7

Your problem is almost certainly because OH runs as the openhab user, not your login user.

Edit:

Also see

http://www.toptechboy.com/raspberry-pi/raspberry-pi-lesson-27-analog-voltages-using-gpio-pwm-in-python/

1 Like

(Markus Storm) #8

If I recall correctly, at least on a Pi (you didn’t mention but that’s what I assume you’re using), you can only set GPIOs to either 1 or 0 (i.e. 3.3V or 0V). I suggest you get a WiFi or zwave RGB controller instead.

0 Likes

(Rich Koshak) #9

True but there are ways to simulate voltages between 0V and 3.3V using PWM. Of course the LEDs he is using will have to support dimming for it to work.

1 Like

(Markus Storm) #10

You don’t want to simulate PWM in software. I doubt a Pi is fast enough. Just for example, a Fibaro RGBW needs to operate at a rate of 244Hz to get it flicker-free.

0 Likes

(George Erhan) #11

Dear Markus,
244 Hz for a transistor is like I am walking 1 km/h, slow pace I mean! The transistors generally speaking are not bound to a brand/technology! I have reached with Raspberry Pi far bigger frequencies!

0 Likes

(Markus Storm) #12

For a transistor, yes. But for the massive software stack involved we’re talking about here ?
But feel free and try and let me know the outcome.

0 Likes

(George Erhan) #13

Oh, come on! Of course you can not do PWM control for LED from a rule in openHAB! Let’s set things straight assuming we are reasonable men (people, whatever gender)!
Of course a triac dimmer from the conception is fast, of course we can not emphasize on OH being an all-do machine, because the OS (Java) is not real time!
But, from my above points said to a guidance towards a technology/protocol, I think it’s way too far stretched!
So, instead of saying Fibaro, just say Z-wave! :wink:

0 Likes

(Rich Koshak) #14

See the link I supplied above. I’ve no experience, just some google foo that tells me it is possible at least with Python controlling a single LED.

No one is suggesting implementing PWM in OH.

YMMV.

1 Like

(George Erhan) #15

You will always be a peach!

:wink:
0 Likes

(Adrian Knorr) #16

Many many thanks to everyone! :slight_smile:

1 Like

(Ezbix) #17

Sitemaps:

sitemap home label="Main Menu"
{
        Slider item=Dimmer1
        Switch item=LED

}

Items:

Switch LED “LED” { gpio=“pin:21” }
Dimmer Dimmer1 "Dimmer [%.1f]"
Rules:
rule "DimmerON"
when
Item LED changed
then
if(LED.state==ON)
executeCommandLine(“screen -dmS dimmer python /home/openhabian/asd.py”)
end

rule "DimmerOFF"
when
        Item LED changed
then
        if(LED.state==OFF)
                 executeCommandLine("killall python")
end

rule "Dimmer2"
when
    Item Dimmer1 received command
then
    if (receivedCommand instanceof PercentType)
        executeCommandLine("screen -S dimmer -X stuff  " + (receivedCommand as PercentType)+ "\\n")
end

Python Script:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(40,GPIO.OUT)
pwm=GPIO.PWM(40,100)
pwm.start(100)

while True:
        asd=input()
        pwm.ChangeDutyCycle(asd)

It’s just a thought about using screen, there might be hundreds better solutions. Though its not meant for changing colors on ur LED strip, but u can control voltage by using PWM with the slider going from 0-100% power on openhab.

1 Like