Page 1 of 1

Smooth Fade RPI + Dali Warrior09-2 + Dali Warrior11

Posted: Wed Jan 27, 2016 3:37 pm
by jnsjohansson
Hi,

I am trying to detect motion with the Raspberry PI and fade a light up and down accordingly.

In the test below I have 3 functions:

basic
advanced
dali


in both basic and advanced there is a flicker as I set the new light level.

in dali, it actually fades as i use the fadeUp/fadeDown commands, but I have little understanding of how it actually works ie. what level of brightness does it step up to. i feel a bit in the dark on how this actually functions.

and regarding DACP, when is it appropriate to actually call this? 200ms before any other type of command?

Any thoughts and/or advice?

Code: Select all

import time
import smbus

bus             = smbus.SMBus(1)
i2c_addr        = 0x20
fade_interval   = 0.05 #0.05s = 50ms
time_start      = time.time()

Verbose         = 0

gamma = [1,4,7,10,13,16,18,21,24,27,30,32,35,38,40,43,46,48,51,53,56,58,61,63,66,68,71,73,76,78,80,82,85,87,89,92,94,96,98,100,102,104,107,109,111,113,115,117,119,121,123,124,126,128,130,132,134,136,137,139,141,143,144,146,148,149,151,153,154,156,157,159,160,162,164,165,166,168,169,171,172,174,175,176,178,179,180,182,183,184,185,187,188,189,190,191,193,194,195,196,197,198,199,200,201,203,204,205,206,207,207,208,209,210,211,212,213,214,215,216,216,217,218,219,220,220,221,222,223,223,224,225,226,226,227,228,228,229,230,230,231,231,232,233,233,234,234,235,235,236,236,237,237,238,238,239,239,240,240,240,241,241,242,242,243,243,243,244,244,244,245,245,245,246,246,246,246,247,247,247,248,248,248,248,249,249,249,249,249,250,250,250,250,250,251,251,251,251,251,251,251,252,252,252,252,252,252,252,252,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254];
gamma_length = len(gamma)

def fadeBasic(times):
    number,light_level,fade_rate = 0,0,1
    while(number < times):
        try:
            writeLightLevel(light_level)
            light_level = light_level + fade_rate
            if(light_level < 0):
                light_level = 0
                fade_rate   = 1
                time.sleep(3)
            elif(light_level > 254):
                light_level = 254
                fade_rate   = -1
                time.sleep(3)
                number += 1
            time.sleep(fade_interval)
        except:
            continue
    return

def fadeDali(times):
    number, i  = 0, 0
    fade_up = True
    while(number < times):
        try:
            if (fade_up):
                fadeUp()
                i += 1
            else:
                fadeDown()
                i -= 1

            time.sleep(fade_interval)

            if(i < 0):
                i = 0
                fade_up = True
                time.sleep(3)
            elif(i > 64):
                i = 64
                writeLightLevel
                fade_up = False
                time.sleep(3)

        except:
            continue

def fadeAdvanced(times):
    global time_start
    number,light_level,fade_rate = 0,0,1
    while(number < times):
        try:
            writeLightLevel(gamma[light_level])
            light_level = light_level + fade_rate
            if(light_level < 0):
                light_level = 0
                fade_rate   = 1
                time.sleep(3)
            elif(light_level > gamma_length - 1):
                light_level = gamma_length - 1
                fade_rate   = -1
                time.sleep(3)
                number += 1
            time.sleep(fade_interval)
        except:
            continue
    return

def sendCommand(value):
    try:
        if (Verbose):
            print "sendCommand: Success, value:",value
        command = [0xFF, value]
        bus.write_i2c_block_data(i2c_addr, 0x01, command)
        return True
    except:
        if (Verbose):
            print "sendCommand: Fail, value:",value
        return False

def fadeUp():
    return sendCommand(1)

def fadeDown():
    return sendCommand(2)

def writeLightLevel(value):
    global i2c_addr
    try:
        if (Verbose):
            print "writeLightLevel: Success, value:",value
        command = [0xFE, value]
        bus.write_i2c_block_data(i2c_addr, 0x01, command)
        return True
    except:
        if (Verbose):
            print "writeLightLevel: Fail, value:",value
        return False

if __name__ == "__main__":
    print "_dali.py"
    writeLightLevel(1)
    sendCommand(9)
    #fadeDali(10)
    fadeBasic(10)
    #fadeAdvanced(10)
else:
    print "imported _dali.py"

Re: Smooth Fade RPI + Dali Warrior09-2 + Dali Warrior11

Posted: Mon Feb 01, 2016 12:48 pm
by Guido K├Ârber
Resolved by phone. Likely the luminaire did cause the problem.