Unstable led A1 and A2

Moderator: RevPiModIO

Post Reply
LorenzB
Posts: 1
Joined: 19 Jun 2021, 13:29
Answers: 0

Unstable led A1 and A2

Post 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")
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: Unstable led A1 and A2

Post 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
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
Post Reply