Page 1 of 1

Unstable led A1 and A2

Posted: 19 Jun 2021, 13:43
by LorenzB
Hi everyone,
I recently started working with a RevPi core 3+ 16G with a python project but i'm encountering a strange problem.
I'm trying to use the LED A1 and A2 on the RevPi ad debug LED for the script but both led seems to act funny, they blink, basicali when they should stay on or off.
It's hard to explain so i include a video and the actual script being run.

Video: https://youtu.be/jHbEJjsMeEs

Code:

Code: Select all

import revpimodio2
import time

rpi = revpimodio2.RevPiModIO(autorefresh=True)

def setVPNLink( str ):
    rpi = revpimodio2.RevPiModIO(autorefresh=True)
    if str == "off":
        rpi.core.a1green.value = False
        rpi.core.a1red.value = False
        print(1)
    elif str == "verde":
        rpi.core.a1green.value = True
        rpi.core.a1red.value = False
        print(2)
    elif str == "arancio":
        rpi.core.a1green.value = True
        rpi.core.a1red.value = True
        print(3)
    elif str == "rosso":
        rpi.core.a1green.value = False
        rpi.core.a1red.value = True
        print(4)
    elif str == "clear":
        rpi.core.a1green.value = False
        rpi.core.a1red.value = False
        print(5)
    return

def setRunningLED( str ):
    rpi = revpimodio2.RevPiModIO(autorefresh=True)
    if str == "off":
        rpi.core.a2green.value = False
        rpi.core.a2red.value = False
        print(6)
    elif str == "verde":
        rpi.core.a2green.value = True
        rpi.core.a2red.value = False
        print(7)
    elif str == "arancio":
        rpi.core.a2green.value = True
        rpi.core.a2red.value = True
        print(8)
    elif str == "rosso":
        rpi.core.a2green.value = False
        rpi.core.a2red.value = True
        print(9)
    elif str == "clear":
        rpi.core.a2green.value = False
        rpi.core.a2red.value = False
        print(10)
    return

setRunningLED("clear")
setVPNLink("clear")
time.sleep(5)
setVPNLink("clear")
time.sleep(5)
setVPNLink("verde")
time.sleep(5)
setVPNLink("arancio")
time.sleep(5)
setVPNLink("rosso")
time.sleep(5)
setVPNLink("verde")
time.sleep(5)
setRunningLED("clear")
setVPNLink("clear")

Re: Unstable led A1 and A2

Posted: 22 Jun 2021, 09:06
by RevPiModIO
Hi LorenzB!

That is because of a multi use of RevPiModIO. In your program you have three instances of RevPiModIO. Each instance want so set the buffer to the process image. So if the LED is off in instance A and on in instance B they will force the value on each refresh.

The solution is to only use one instance of RevPiModIO like this:

Code: Select all

import revpimodio2
import time

# This is your global an only instance of RevPiModIO
rpi = revpimodio2.RevPiModIO(autorefresh=True)

def setVPNLink( str ):
    # Do not create a new instance. rpi is in the global namespace an you can use it in this function
    # remove: rpi = revpimodio2.RevPiModIO(autorefresh=True)
    if str == "off":
        rpi.core.a1green.value = False
        rpi.core.a1red.value = False
        print(1)
    elif str == "verde":
        rpi.core.a1green.value = True
        rpi.core.a1red.value = False
        print(2)
    elif str == "arancio":
        rpi.core.a1green.value = True
        rpi.core.a1red.value = True
        print(3)
    elif str == "rosso":
        rpi.core.a1green.value = False
        rpi.core.a1red.value = True
        print(4)
    elif str == "clear":
        rpi.core.a1green.value = False
        rpi.core.a1red.value = False
        print(5)
    return

def setRunningLED( str ):
    # Same as above, use your global instance.
    # remove: rpi = revpimodio2.RevPiModIO(autorefresh=True)
    if str == "off":
        rpi.core.a2green.value = False
        rpi.core.a2red.value = False
        print(6)
    elif str == "verde":
        rpi.core.a2green.value = True
        rpi.core.a2red.value = False
        print(7)
    elif str == "arancio":
        rpi.core.a2green.value = True
        rpi.core.a2red.value = True
        print(8)
    elif str == "rosso":
        rpi.core.a2green.value = False
        rpi.core.a2red.value = True
        print(9)
    elif str == "clear":
        rpi.core.a2green.value = False
        rpi.core.a2red.value = False
        print(10)
    return

setRunningLED("clear")
setVPNLink("clear")
time.sleep(5)
setVPNLink("clear")
time.sleep(5)
setVPNLink("verde")
time.sleep(5)
setVPNLink("arancio")
time.sleep(5)
setVPNLink("rosso")
time.sleep(5)
setVPNLink("verde")
time.sleep(5)
setRunningLED("clear")
setVPNLink("clear")

Sven